Fix sample cart, and get ready for edit mode
This commit is contained in:
parent
2a7003b443
commit
6b90d883e9
@ -1,7 +1,7 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"sheet_type": "code",
|
"sheet_type": "code",
|
||||||
"value": "x = code_sheet(1);\nreturn ({init: () => {y = 0}, update: () => {y += speed; if (y > 127) {y = -6}}, draw: () => {clear_screen(); draw_text(x, y, 'hello world')}})"
|
"value": "x = code_sheet(1);\nreturn ({init: () => {y = 0}, update: () => {y += speed; if (y > 127) {y = -6}}, draw: () => {cls(); txt(x, y, 'hello world')}})"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"sheet_type": "code",
|
"sheet_type": "code",
|
||||||
|
14
editmode.ts
Normal file
14
editmode.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { clearScreen } from "./window.ts"
|
||||||
|
|
||||||
|
const update = () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const draw = () => {
|
||||||
|
clearScreen()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const editmode = {
|
||||||
|
update,
|
||||||
|
draw,
|
||||||
|
}
|
17
index.ts
17
index.ts
@ -7,6 +7,7 @@ import { codeSheet } from "./sheet.ts";
|
|||||||
import { refreshKeyboard, keyPressed, K } from "./keyboard.ts";
|
import { refreshKeyboard, keyPressed, K } from "./keyboard.ts";
|
||||||
import { repl, resetRepl } from "./repl.ts";
|
import { repl, resetRepl } from "./repl.ts";
|
||||||
import { addToContext } from "./runcode.ts";
|
import { addToContext } from "./runcode.ts";
|
||||||
|
import { editmode } from "./editmode.ts";
|
||||||
|
|
||||||
const game = codeSheet(0);
|
const game = codeSheet(0);
|
||||||
|
|
||||||
@ -21,18 +22,19 @@ clearScreen();
|
|||||||
await mainloop((_t) => {
|
await mainloop((_t) => {
|
||||||
// TODO: use t
|
// TODO: use t
|
||||||
if (keyPressed(K.ESCAPE)) {
|
if (keyPressed(K.ESCAPE)) {
|
||||||
console.log('pressed escape');
|
const modeTo = ({
|
||||||
|
play: "repl",
|
||||||
|
edit: "repl",
|
||||||
|
repl: "edit",
|
||||||
|
} as const)[mode];
|
||||||
|
console.log(`pressed escape (${mode} -> ${modeTo})`);
|
||||||
if (mode === "play") {
|
if (mode === "play") {
|
||||||
resetRepl();
|
resetRepl();
|
||||||
}
|
}
|
||||||
if (mode === "edit") {
|
if (mode === "edit") {
|
||||||
clearScreen();
|
clearScreen();
|
||||||
}
|
}
|
||||||
mode = ({
|
mode = modeTo;
|
||||||
play: "repl",
|
|
||||||
edit: "repl",
|
|
||||||
repl: "edit",
|
|
||||||
} as const)[mode];
|
|
||||||
} else {
|
} else {
|
||||||
if (mode === "play") {
|
if (mode === "play") {
|
||||||
game.update();
|
game.update();
|
||||||
@ -43,7 +45,8 @@ await mainloop((_t) => {
|
|||||||
repl.draw();
|
repl.draw();
|
||||||
frame();
|
frame();
|
||||||
} else if (mode === "edit") {
|
} else if (mode === "edit") {
|
||||||
clearScreen();
|
editmode.update();
|
||||||
|
editmode.draw();
|
||||||
frame();
|
frame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user