Starting on sprite editor
This commit is contained in:
19
sheet.ts
19
sheet.ts
@ -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);
|
Reference in New Issue
Block a user