From 4b29b382b36794da9d08941abdcfdfff5b1dc49f Mon Sep 17 00:00:00 2001 From: Chris Maltby Date: Thu, 7 Nov 2024 15:06:46 +0000 Subject: [PATCH] Exclude text wait code from autolabel --- src/lib/compiler/scriptBuilder.ts | 6 ++++++ src/shared/lib/compiler/lexText.ts | 23 +++++++++++++++++++++++ src/shared/lib/scripts/autoLabel.ts | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/lib/compiler/scriptBuilder.ts b/src/lib/compiler/scriptBuilder.ts index 2817aa9e7..afe428b65 100644 --- a/src/lib/compiler/scriptBuilder.ts +++ b/src/lib/compiler/scriptBuilder.ts @@ -588,6 +588,10 @@ const textCodeGotoRel = (x: number, y: number): string => { return `\\004\\${decOct(x)}\\${decOct(y)}`; }; +const textCodeInput = (mask: number): string => { + return `\\006\\${decOct(mask)}`; +}; + const assertUnreachable = (_x: never): never => { throw new Error("Didn't expect to get here"); }; @@ -1956,6 +1960,8 @@ class ScriptBuilder { text += textCodeGotoRel(token.x, token.y); } else if (token.type === "gotoxy" && !token.relative) { text += textCodeGoto(token.x, token.y); + } else if (token.type === "input") { + text += textCodeInput(token.mask); } }); diff --git a/src/shared/lib/compiler/lexText.ts b/src/shared/lib/compiler/lexText.ts index bf3726291..b929731f3 100644 --- a/src/shared/lib/compiler/lexText.ts +++ b/src/shared/lib/compiler/lexText.ts @@ -36,6 +36,10 @@ export type Token = x: number; y: number; relative?: boolean; + } + | { + type: "input"; + mask: number; }; export const lexText = (inputText: string): Token[] => { @@ -281,6 +285,25 @@ export const lexText = (inputText: string): Token[] => { continue; } + // Check for gbvm wait for input + if ( + inputText[i] === "\\" && + inputText[i + 1] === "0" && + inputText[i + 2] === "0" && + inputText[i + 3] === "6" && + inputText[i + 4] === "\\" && + inputText[i + 5]?.match(/[0-7]/) && + inputText[i + 6]?.match(/[0-7]/) && + inputText[i + 7]?.match(/[0-7]/) + ) { + tokens.push({ + type: "input", + mask: fromSigned8Bit(parseInt(inputText.substring(i + 5, i + 8), 8)), + }); + i += 7; + continue; + } + // Ignore unmatched GBVM octal in previews if (inputText[i] === "\\" && inputText[i + 1]?.match(/[0-7]/)) { let len = 1; diff --git a/src/shared/lib/scripts/autoLabel.ts b/src/shared/lib/scripts/autoLabel.ts index 85feb07e7..d86f087d7 100644 --- a/src/shared/lib/scripts/autoLabel.ts +++ b/src/shared/lib/scripts/autoLabel.ts @@ -199,7 +199,7 @@ export const getAutoLabel = ( return `||variable:${t.variableId}||`; } else if (t.type === "char") { return `%c||variable:${t.variableId}||`; - } else if (t.type === "gotoxy") { + } else if (t.type === "gotoxy" || t.type === "input") { return " "; } return "";