Add undo-redo

This commit is contained in:
dylan
2023-05-06 11:35:02 -07:00
parent 9685568f90
commit 3ad23f3a91
4 changed files with 86 additions and 17 deletions

View File

@ -1,5 +1,5 @@
import { getCart } from "./cart.ts";
import { runCode, addToContext } from "./runcode.ts";
// import { runCode, addToContext } from "./runcode.ts";
// "code" | "spritesheet" | "map" | "sfx" | "patterns" | "fonts"
export type Sheet = {
@ -20,12 +20,20 @@ export const setSheet = (n: number, type: SheetType, value: any) => {
return getCart()[n] = {sheet_type: type, value};
}
export const codeSheet = (sheet: number) => {
export const getCodeSheet = (sheet: number) => {
const {sheet_type, value} = getSheet(sheet);
if (sheet_type !== "code") {
throw "Trying to run a non-code sheet as code."
throw "Trying to use a non-code sheet as code."
}
return runCode(value);
return value;
}
addToContext("code_sheet", codeSheet);
export const getSpriteSheet = (sheet: number) => {
const {sheet_type, value} = getSheet(sheet);
if (sheet_type !== "spritesheet") {
throw "Trying to use a non-sprite sheet as a spritesheet."
}
return value;
}
// addToContext("code", codeSheet);