More repl improvements
This commit is contained in:
43
index.ts
43
index.ts
@ -4,27 +4,48 @@ import {
|
||||
clearScreen,
|
||||
} from "./window.ts";
|
||||
import { codeSheet } from "./sheet.ts";
|
||||
import { refreshKeyboard } from "./keyboard.ts";
|
||||
import { repl } from "./repl.ts";
|
||||
import { refreshKeyboard, keyPressed, K } from "./keyboard.ts";
|
||||
import { repl, resetRepl } from "./repl.ts";
|
||||
import { addToContext } from "./runcode.ts";
|
||||
|
||||
const game = codeSheet(0);
|
||||
|
||||
game.init();
|
||||
|
||||
let mode: "play" | "edit" = "edit";
|
||||
let mode: "play" | "edit" | "repl" = "repl";
|
||||
|
||||
addToContext("play", () => {mode = "play"});
|
||||
|
||||
clearScreen();
|
||||
|
||||
await mainloop((_t) => {
|
||||
// TODO: use t
|
||||
if (mode === "play") {
|
||||
game.update();
|
||||
game.draw();
|
||||
frame();
|
||||
} else if (mode === "edit") {
|
||||
repl.update();
|
||||
repl.draw();
|
||||
frame();
|
||||
if (keyPressed(K.ESCAPE)) {
|
||||
console.log('pressed escape');
|
||||
if (mode === "play") {
|
||||
resetRepl();
|
||||
}
|
||||
if (mode === "edit") {
|
||||
clearScreen();
|
||||
}
|
||||
mode = ({
|
||||
play: "repl",
|
||||
edit: "repl",
|
||||
repl: "edit",
|
||||
} as const)[mode];
|
||||
} else {
|
||||
if (mode === "play") {
|
||||
game.update();
|
||||
game.draw();
|
||||
frame();
|
||||
} else if (mode === "repl") {
|
||||
repl.update();
|
||||
repl.draw();
|
||||
frame();
|
||||
} else if (mode === "edit") {
|
||||
clearScreen();
|
||||
frame();
|
||||
}
|
||||
}
|
||||
refreshKeyboard();
|
||||
});
|
||||
|
Reference in New Issue
Block a user