some more cart infrastructure
This commit is contained in:
38
sheet.ts
Normal file
38
sheet.ts
Normal 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;
|
||||
},
|
||||
});
|
Reference in New Issue
Block a user