silphius/app/ecs/components/plant.js

52 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-06-27 15:08:30 -05:00
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() {
2024-07-11 15:43:08 -05:00
return this.mayGrowScriptInstance.evaluate();
2024-06-27 15:08:30 -05:00
}
grow() {
const {Ticking} = ecs.get(this.entity);
2024-07-22 01:31:52 -05:00
Ticking.add(this.growScriptInstance.ticker());
2024-06-27 15:08:30 -05:00
}
};
}
async load(instance) {
// heavy handed...
if ('undefined' !== typeof window) {
return;
}
2024-07-01 17:23:04 -05:00
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,
},
);
2024-06-27 15:08:30 -05:00
}
// heavy handed...
markChange() {}
static properties = {
growScript: {type: 'string'},
growth: {type: 'uint16'},
2024-06-28 07:03:56 -05:00
growthFactor: {defaultValue: 127, type: 'uint8'},
2024-06-27 15:08:30 -05:00
mayGrowScript: {type: 'string'},
stage: {type: 'uint8'},
stages: {
type: 'array',
subtype: {type: 'uint16'},
},
};
}