diff --git a/src/lib/engine/1-base/index.ts b/src/lib/engine/1-base/index.ts index 4c4538858e..9dcb2df483 100644 --- a/src/lib/engine/1-base/index.ts +++ b/src/lib/engine/1-base/index.ts @@ -1,7 +1,7 @@ import { palette } from './palette' import type { Text } from './text' -// Tagged tempalate literal factory go brrr +// Tagged template literal factory go brrr const _makeTag = (cb: (string: string) => T) => { return (strings: string[], ...interps: string[]) => { if (typeof strings === 'string') { @@ -65,7 +65,7 @@ export function baseEngine() { set type(newType) { const legendDict = Object.fromEntries(gameState.legend) - if (!(newType in legendDict)) throw new Error(`"${newType}" not in legend.`) + if (!(newType in legendDict)) throw new Error(`"${newType}" isn\'t in the legend.`) this.remove() addSprite(this._x, this._y, newType) } @@ -181,11 +181,14 @@ export function baseEngine() { const setMap = (string: string): void => { if (!string) throw new Error('Tried to set empty map.') + + if (string.constructor == Object) throw new Error('setMap() takes a string, not a dict.') // https://stackoverflow.com/a/51285298 + if (Array.isArray(string)) throw new Error('It looks like you passed an array into setMap(). Did you mean to use something like setMap(levels[level]) instead of setMap(levels)?') const rows = string.trim().split("\n").map(x => x.trim()) const rowLengths = rows.map(x => x.length) const isRect = _allEqual(rowLengths) - if (!isRect) throw new Error('Level must be rect.') + if (!isRect) throw new Error('Level must be rectangular.') const w = rows[0]?.length ?? 0 const h = rows.length gameState.dimensions.width = w @@ -259,8 +262,19 @@ export function baseEngine() { return tiles } - const setSolids = (arr: string[]): void => { gameState.solids = arr } - const setPushables = (map: Record): void => { gameState.pushable = map } + const setSolids = (arr: string[]): void => { + if (!Array.isArray(arr)) throw new Error('The sprites passed into setSolids() need to be an array.') + gameState.solids = arr + } + const setPushables = (map: Record): void => { + for (const key in map) { + if(key.length != 1) { + throw new Error('Your sprite name must be wrapped in [] brackets here.'); + } + _checkLegend(key) + } + gameState.pushable = map + } const api = { setMap, diff --git a/src/lib/engine/2-web/index.ts b/src/lib/engine/2-web/index.ts index e52912f3b5..c85e476e14 100644 --- a/src/lib/engine/2-web/index.ts +++ b/src/lib/engine/2-web/index.ts @@ -76,6 +76,10 @@ export function webEngine(canvas: HTMLCanvasElement) { let animationId = window.requestAnimationFrame(_gameloop) const setLegend = (...bitmaps: [string, string][]): void => { + if (bitmaps.length == 0) throw new Error('There needs to be at least one sprite in the legend.') + + if (!Array.isArray(bitmaps[0])) throw new Error('The sprites passed into setLegend each need to be in square brackets, like setLegend([player, bitmap`...`]).') + bitmaps.forEach(([ key ]) => { if (key === '.') throw new Error(`Can't reassign "." bitmap`) if (key.length !== 1) throw new Error(`Bitmaps must have one character names`) diff --git a/src/lib/upload.ts b/src/lib/upload.ts index 28216d84e5..14b17070a3 100644 --- a/src/lib/upload.ts +++ b/src/lib/upload.ts @@ -6,7 +6,7 @@ export const uploadState = signal('IDLE') const getPort = async (): Promise => { if (!navigator.serial) { - const msg = 'Your browser does not support the Web Serial API. Please try again in a recent version of Chrome.' + const msg = 'Your browser does not support the Web Serial API. Please try again in a recent version of a Chromium-based browser, such as Chrome, Edge, or Arc.' alert(msg) throw new Error(msg) }