feat: perishable

This commit is contained in:
cha0s 2019-11-06 15:59:52 -06:00
parent 2326185fb7
commit c9ecfbadae

View File

@ -0,0 +1,32 @@
import {compose} from '@avocado/core';
import {StateProperty, Trait} from '../trait';
const decorate = compose(
);
export class Perishable extends decorate(Trait) {
static defaultParams() {
return {
ttl: 300,
};
}
static type() {
return 'perishable';
}
constructor(entity, params, state) {
super(entity, params, state);
this.ttl = this.params.ttl;
}
tick(elapsed) {
this.ttl -= elapsed;
if (this.ttl <= 0) {
this.entity.destroy();
}
}
}