62 lines
1.2 KiB
TypeScript
62 lines
1.2 KiB
TypeScript
import {
|
|
mainloop,
|
|
frame,
|
|
clearScreen,
|
|
} from "./window.ts";
|
|
import { runCode } from "./runcode.ts";
|
|
import { getCodeSheet } 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";
|
|
import { refreshMouse } from "./mouse.ts";
|
|
|
|
// deno-lint-ignore no-explicit-any
|
|
let game: any = null;
|
|
|
|
let mode: "play" | "edit" | "repl" = "repl";
|
|
|
|
addToContext("play", () => {
|
|
mode = "play";
|
|
game = runCode(getCodeSheet(0));
|
|
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) {
|
|
game.update();
|
|
game.draw();
|
|
}
|
|
frame();
|
|
} else if (mode === "repl") {
|
|
repl.update();
|
|
repl.draw();
|
|
frame();
|
|
} else if (mode === "edit") {
|
|
await editmode.update();
|
|
editmode.draw();
|
|
frame();
|
|
}
|
|
}
|
|
refreshKeyboard();
|
|
refreshMouse();
|
|
}, false);
|