import { mainloop, frame, clearScreen, } from "./window.ts"; import { codeSheet } from "./sheet.ts"; import { refreshKeyboard, keyPressed, K } from "./keyboard.ts"; import { repl, resetRepl } from "./repl.ts"; import { addToContext } from "./runcode.ts"; import { editmode } from "./editmode.ts"; const game = codeSheet(0); game.init(); let mode: "play" | "edit" | "repl" = "repl"; addToContext("play", () => {mode = "play"}); clearScreen(); await mainloop((_t) => { // TODO: use t if (keyPressed(K.ESCAPE)) { const modeTo = ({ play: "repl", edit: "repl", repl: "edit", } as const)[mode]; console.log(`pressed escape (${mode} -> ${modeTo})`); if (mode === "play") { resetRepl(); } if (mode === "edit") { clearScreen(); } mode = modeTo; } else { if (mode === "play") { game.update(); game.draw(); frame(); } else if (mode === "repl") { repl.update(); repl.draw(); frame(); } else if (mode === "edit") { editmode.update(); editmode.draw(); frame(); } } refreshKeyboard(); });