29 lines
634 B
JavaScript
29 lines
634 B
JavaScript
import Component from '@/ecs/component.js';
|
|
|
|
export default class Ttl extends Component {
|
|
instanceFromSchema() {
|
|
const {ecs} = this;
|
|
return class TtlInstance extends super.instanceFromSchema() {
|
|
$$elapsed = 0;
|
|
destroy() {
|
|
this.$$elapsed = 0;
|
|
}
|
|
get elapsed() {
|
|
return this.$$elapsed;
|
|
}
|
|
set elapsed(elapsed) {
|
|
this.$$elapsed = elapsed;
|
|
}
|
|
tick(elapsed) {
|
|
this.$$elapsed += elapsed;
|
|
if (this.$$elapsed >= this.ttl) {
|
|
ecs.destroy(this.entity);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
static properties = {
|
|
ttl: {type: 'float32'},
|
|
};
|
|
}
|