2023-05-02 17:06:54 -07:00
|
|
|
import { getCart } from "./cart.ts";
|
2023-05-03 15:17:27 -07:00
|
|
|
import { runCode, addToContext } from "./runcode.ts";
|
2023-05-02 17:06:54 -07:00
|
|
|
|
2023-05-05 14:59:52 -07:00
|
|
|
// "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"];
|
2023-05-02 17:06:54 -07:00
|
|
|
|
2023-05-05 11:52:08 -07:00
|
|
|
export const getSheet = (n: number) => {
|
2023-05-05 14:59:52 -07:00
|
|
|
return getCart()[n];
|
2023-05-02 17:06:54 -07:00
|
|
|
}
|
|
|
|
|
2023-05-05 11:52:08 -07:00
|
|
|
// deno-lint-ignore no-explicit-any
|
|
|
|
export const setSheet = (n: number, type: SheetType, value: any) => {
|
|
|
|
return getCart()[n] = {sheet_type: type, value};
|
|
|
|
}
|
|
|
|
|
2023-05-02 17:06:54 -07:00
|
|
|
export const codeSheet = (sheet: number) => {
|
2023-05-05 14:59:52 -07:00
|
|
|
const {sheet_type, value} = getSheet(sheet);
|
|
|
|
if (sheet_type !== "code") {
|
|
|
|
throw "Trying to run a non-code sheet as code."
|
|
|
|
}
|
|
|
|
return runCode(value);
|
2023-05-02 17:06:54 -07:00
|
|
|
}
|
|
|
|
|
2023-05-03 15:17:27 -07:00
|
|
|
addToContext("code_sheet", codeSheet);
|