silphius/app/ecs/components/ttl.js

29 lines
634 B
JavaScript
Raw Normal View History

2024-07-30 09:56:53 -05:00
import Component from '@/ecs/component.js';
export default class Ttl extends Component {
instanceFromSchema() {
const {ecs} = this;
return class TtlInstance extends super.instanceFromSchema() {
$$elapsed = 0;
2024-08-01 21:10:16 -05:00
destroy() {
this.$$elapsed = 0;
}
2024-08-01 15:44:54 -05:00
get elapsed() {
return this.$$elapsed;
}
set elapsed(elapsed) {
this.$$elapsed = elapsed;
}
2024-07-30 09:56:53 -05:00
tick(elapsed) {
this.$$elapsed += elapsed;
if (this.$$elapsed >= this.ttl) {
ecs.destroy(this.entity);
}
}
}
}
static properties = {
ttl: {type: 'float32'},
};
}