Starting on sprite editor

This commit is contained in:
dylan
2023-05-05 14:59:52 -07:00
parent b87529bf56
commit f2b5978cae
7 changed files with 352 additions and 210 deletions

View File

@ -1,10 +1,18 @@
import { getCart } from "./cart.ts";
import { runCode, addToContext } from "./runcode.ts";
export type SheetType = "code" | "spritesheet" | "map" | "sfx" | "patterns" | "fonts";
// "code" | "spritesheet" | "map" | "sfx" | "patterns" | "fonts"
export type Sheet = {
sheet_type: "code",
value: string,
} | {
sheet_type: "spritesheet",
value: Array<Array<number>>,
}
export type SheetType = Sheet["sheet_type"];
export const getSheet = (n: number) => {
return getCart()[n].value;
return getCart()[n];
}
// deno-lint-ignore no-explicit-any
@ -13,8 +21,11 @@ export const setSheet = (n: number, type: SheetType, value: any) => {
}
export const codeSheet = (sheet: number) => {
const code = getSheet(sheet);
return runCode(code);
const {sheet_type, value} = getSheet(sheet);
if (sheet_type !== "code") {
throw "Trying to run a non-code sheet as code."
}
return runCode(value);
}
addToContext("code_sheet", codeSheet);