import { mainloop, frame, clearScreen, } from "./io/window.ts"; import { runCode } from "./runtime/runcode.ts"; import { getCodeSheet } from "./io/sheet.ts"; import { refreshKeyboard, keyPressed, K } from "./io/keyboard.ts"; import { repl, resetRepl } from "./repl/repl.ts"; import { addToContext } from "./runtime/runcode.ts"; import { editmode } from "./editor/editmode.ts"; import { refreshMouse } from "./io/mouse.ts"; import { camera } from "./runtime/builtins.ts"; // deno-lint-ignore no-explicit-any let game: any = null; let mode: "play" | "edit" | "repl" = "repl"; addToContext("play", async () => { game = await runCode(getCodeSheet(0)); mode = "play"; game.init(); }); clearScreen(); await mainloop(async (_t) => { // TODO: use t if (keyPressed(K.ESCAPE)) { const modeTo = ({ play: "repl", edit: "repl", repl: "edit", } as const)[mode]; if (mode === "play") { resetRepl(); } if (mode === "edit") { clearScreen(); } mode = modeTo; } else { if (mode === "play") { if (game) { await game.update(); await game.draw(); } frame(); } else if (mode === "repl") { repl.update(); camera(0, 0); repl.draw(); frame(); } else if (mode === "edit") { await editmode.update(); camera(0, 0); editmode.draw(); frame(); } } refreshKeyboard(); refreshMouse(); }, false);