refactor: readScript
This commit is contained in:
parent
7009f398f5
commit
02d2c4b604
|
@ -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() {}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user