silphius/app/ecs/components/plant.js
2024-07-25 16:39:05 -05:00

53 lines
1.2 KiB
JavaScript

import Component from '@/ecs/component.js';
export default class Plant extends Component {
instanceFromSchema() {
const {ecs} = this;
const Instance = super.instanceFromSchema();
return class PlantInstance extends Instance {
$$grow;
$$mayGrow;
grow() {
const {Ticking} = ecs.get(this.entity);
Ticking.add(this.$$grow.ticker());
}
mayGrow() {
return this.$$mayGrow.evaluate();
}
};
}
async load(instance) {
// heavy handed...
if ('undefined' !== typeof window) {
return;
}
instance.$$grow = await this.ecs.readScript(
instance.growScript,
{
ecs: this.ecs,
plant: instance,
},
);
instance.$$mayGrow = 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'},
},
};
}