some more cart infrastructure

This commit is contained in:
dylan
2023-05-02 17:06:54 -07:00
parent a7b675d541
commit fdc8f97aee
7 changed files with 61 additions and 57 deletions

38
sheet.ts Normal file
View File

@ -0,0 +1,38 @@
import faux from "./builtins.ts";
import { getCart } from "./cart.ts";
export type SheetType = "code" | "spritesheet" | "map" | "sfx" | "patterns" | "fonts";
const getSheet = (n: number) => {
return getCart()[n].value;
}
export const codeSheet = (sheet: number) => {
const code = getSheet(sheet);
try {
new Function(code);
} catch (err) {
throw err;
}
const fn = new Function("context", `
with (context) {
${code}
}
`);
return fn(context);
}
// deno-lint-ignore no-explicit-any
const G: any = {...faux, faux, log: console.log, code_sheet: codeSheet};
const context = new Proxy(G, {
get: (target, prop) => {
return target[prop];
},
set: (target, prop, value) => {
target[prop] = value;
return true;
},
has: () => {
return true;
},
});