silphius/app/ecs/components/plant.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-06-27 15:08:30 -05:00
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 {
2024-07-25 16:39:05 -05:00
$$grow;
$$mayGrow;
2024-06-27 15:08:30 -05:00
grow() {
const {Ticking} = ecs.get(this.entity);
2024-07-25 16:39:05 -05:00
Ticking.add(this.$$grow.ticker());
}
mayGrow() {
return this.$$mayGrow.evaluate();
2024-06-27 15:08:30 -05:00
}
};
}
async load(instance) {
// heavy handed...
if ('undefined' !== typeof window) {
return;
}
2024-07-25 16:39:05 -05:00
instance.$$grow = await this.ecs.readScript(
2024-07-01 17:23:04 -05:00
instance.growScript,
{
ecs: this.ecs,
plant: instance,
},
);
2024-07-25 16:39:05 -05:00
instance.$$mayGrow = await this.ecs.readScript(
2024-07-01 17:23:04 -05:00
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'},
},
};
}