52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
import Component from '@/ecs/component.js';
|
|
import Script from '@/util/script.js';
|
|
|
|
export default class Plant extends Component {
|
|
instanceFromSchema() {
|
|
const {ecs} = this;
|
|
const Instance = super.instanceFromSchema();
|
|
return class PlantInstance extends Instance {
|
|
mayGrow() {
|
|
return this.mayGrowScriptInstance.evaluateSync();
|
|
}
|
|
grow() {
|
|
const {Ticking} = ecs.get(this.entity);
|
|
Ticking.addTickingPromise(this.growScriptInstance.tickingPromise());
|
|
}
|
|
};
|
|
}
|
|
async load(instance) {
|
|
// heavy handed...
|
|
if ('undefined' !== typeof window) {
|
|
return;
|
|
}
|
|
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() {}
|
|
static properties = {
|
|
growScript: {type: 'string'},
|
|
growth: {type: 'uint16'},
|
|
growthFactor: {defaultValue: 127, type: 'uint8'},
|
|
mayGrowScript: {type: 'string'},
|
|
stage: {type: 'uint8'},
|
|
stages: {
|
|
type: 'array',
|
|
subtype: {type: 'uint16'},
|
|
},
|
|
};
|
|
}
|