From 59cdac0fffb969cbe52a4ae24397830f97b9ff5b Mon Sep 17 00:00:00 2001 From: snwy Date: Sat, 30 Mar 2024 17:07:06 -0400 Subject: [PATCH] Fix for #1557 (#1563) fix for #1557 --- src/lib/engine/index.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/lib/engine/index.ts b/src/lib/engine/index.ts index a591b11a14..937e82c285 100644 --- a/src/lib/engine/index.ts +++ b/src/lib/engine/index.ts @@ -45,8 +45,16 @@ export function runGame(code: string, canvas: HTMLCanvasElement, onPageError: (e return timer }, setLegend: (..._bitmaps: [string, string][]) => { - bitmaps.value = _bitmaps - return game.api.setLegend(..._bitmaps) + // this is bad; but for some reason i could not do _bitmaps === [undefined] + // @ts-ignore + if(JSON.stringify(_bitmaps) === "[null]") { + // @ts-ignore + bitmaps.value = [[]]; + throw new Error('The sprites passed into setLegend each need to be in square brackets, like setLegend([player, bitmap`...`]).') + } else { + bitmaps.value = _bitmaps; + } + return game.api.setLegend(...bitmaps.value) }, playTune: (text: string, n: number) => { const tune = textToTune(text) @@ -94,7 +102,13 @@ export function runGameHeadless(code: string): void { setTimeout: () => {}, setInterval: () => {}, setLegend: (..._bitmaps: [string, string][]) => { - bitmaps.value = _bitmaps + // this is bad; but for some reason i could not do _bitmaps === [undefined] + if(JSON.stringify(_bitmaps) === "[null]") { + // @ts-ignore + bitmaps.value = [[]]; + throw new Error('The sprites passed into setLegend each need to be in square brackets, like setLegend([player, bitmap`...`]).'); + } else + bitmaps.value = _bitmaps return game.api.setLegend(..._bitmaps) }, playTune: () => {}