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) {
|
if ('undefined' !== typeof window) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const {readAsset} = this.ecs;
|
instance.growScriptInstance = await this.ecs.readScript(
|
||||||
await readAsset(instance.growScript)
|
instance.growScript,
|
||||||
.then(async (code) => {
|
{
|
||||||
if (code.byteLength > 0) {
|
|
||||||
const context = {
|
|
||||||
ecs: this.ecs,
|
ecs: this.ecs,
|
||||||
plant: instance,
|
plant: instance,
|
||||||
};
|
},
|
||||||
instance.growScriptInstance = await Script.fromCode((new TextDecoder()).decode(code), context);
|
);
|
||||||
}
|
instance.mayGrowScriptInstance = await this.ecs.readScript(
|
||||||
});
|
instance.mayGrowScript,
|
||||||
await readAsset(instance.mayGrowScript)
|
{
|
||||||
.then(async (code) => {
|
|
||||||
if (code.byteLength > 0) {
|
|
||||||
const context = {
|
|
||||||
ecs: this.ecs,
|
ecs: this.ecs,
|
||||||
plant: instance,
|
plant: instance,
|
||||||
};
|
},
|
||||||
instance.mayGrowScriptInstance = await Script.fromCode((new TextDecoder()).decode(code), context);
|
);
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// heavy handed...
|
// heavy handed...
|
||||||
markChange() {}
|
markChange() {}
|
||||||
|
|
|
@ -41,10 +41,10 @@ export default class Engine {
|
||||||
const chars = await this.readAsset(uri);
|
const chars = await this.readAsset(uri);
|
||||||
return chars.byteLength > 0 ? JSON.parse((new TextDecoder()).decode(chars)) : {};
|
return chars.byteLength > 0 ? JSON.parse((new TextDecoder()).decode(chars)) : {};
|
||||||
}
|
}
|
||||||
async readScript(uri) {
|
async readScript(uri, context) {
|
||||||
const code = await this.readAsset(uri);
|
const code = await this.readAsset(uri);
|
||||||
if (code.byteLength > 0) {
|
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);
|
const chars = await this.readAsset(uri);
|
||||||
return chars.byteLength > 0 ? JSON.parse((new TextDecoder()).decode(chars)) : {};
|
return chars.byteLength > 0 ? JSON.parse((new TextDecoder()).decode(chars)) : {};
|
||||||
}
|
}
|
||||||
async readScript(uri) {
|
async readScript(uri, context = {}) {
|
||||||
const code = await this.readAsset(uri);
|
const code = await this.readAsset(uri);
|
||||||
if (code.byteLength > 0) {
|
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