Skip to content

Commit

Permalink
Exclude text wait code from autolabel
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaltby committed Nov 7, 2024
1 parent 40f6457 commit 4b29b38
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/lib/compiler/scriptBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};
Expand Down Expand Up @@ -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);
}
});

Expand Down
23 changes: 23 additions & 0 deletions src/shared/lib/compiler/lexText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export type Token =
x: number;
y: number;
relative?: boolean;
}
| {
type: "input";
mask: number;
};

export const lexText = (inputText: string): Token[] => {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/lib/scripts/autoLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down

0 comments on commit 4b29b38

Please sign in to comment.