diff --git a/app/ecs-components/plant.js b/app/ecs-components/plant.js index 7a6df4f..61d45bf 100644 --- a/app/ecs-components/plant.js +++ b/app/ecs-components/plant.js @@ -20,27 +20,20 @@ export default class Plant extends Component { if ('undefined' !== typeof window) { return; } - const {readAsset} = this.ecs; - await readAsset(instance.growScript) - .then(async (code) => { - if (code.byteLength > 0) { - const context = { - ecs: this.ecs, - plant: instance, - }; - instance.growScriptInstance = await Script.fromCode((new TextDecoder()).decode(code), context); - } - }); - await readAsset(instance.mayGrowScript) - .then(async (code) => { - if (code.byteLength > 0) { - const context = { - ecs: this.ecs, - plant: instance, - }; - instance.mayGrowScriptInstance = await Script.fromCode((new TextDecoder()).decode(code), context); - } - }); + instance.growScriptInstance = await this.ecs.readScript( + instance.growScript, + { + ecs: this.ecs, + plant: instance, + }, + ); + instance.mayGrowScriptInstance = await this.ecs.readScript( + instance.mayGrowScript, + { + ecs: this.ecs, + plant: instance, + }, + ); } // heavy handed... markChange() {} diff --git a/app/engine.js b/app/engine.js index 2e2a961..95af89c 100644 --- a/app/engine.js +++ b/app/engine.js @@ -41,10 +41,10 @@ export default class Engine { const chars = await this.readAsset(uri); return chars.byteLength > 0 ? JSON.parse((new TextDecoder()).decode(chars)) : {}; } - async readScript(uri) { + async readScript(uri, context) { const code = await this.readAsset(uri); if (code.byteLength > 0) { - return Script.fromCode((new TextDecoder()).decode(code)); + return Script.fromCode((new TextDecoder()).decode(code), context); } } } diff --git a/app/routes/_main-menu.play.$.$/route.jsx b/app/routes/_main-menu.play.$.$/route.jsx index d6f50f4..423fc21 100644 --- a/app/routes/_main-menu.play.$.$/route.jsx +++ b/app/routes/_main-menu.play.$.$/route.jsx @@ -41,10 +41,10 @@ class ClientEcs extends Ecs { const chars = await this.readAsset(uri); return chars.byteLength > 0 ? JSON.parse((new TextDecoder()).decode(chars)) : {}; } - async readScript(uri) { + async readScript(uri, context = {}) { const code = await this.readAsset(uri); if (code.byteLength > 0) { - return Script.fromCode((new TextDecoder()).decode(code)); + return Script.fromCode((new TextDecoder()).decode(code), context); } } }