silphius/app/ecs/components/ticking.js
2024-07-22 01:31:52 -05:00

41 lines
869 B
JavaScript

import Component from '@/ecs/component.js';
export default class Ticking extends Component {
instanceFromSchema() {
return class TickingInstance extends super.instanceFromSchema() {
$$finished = [];
$$tickers = [];
add(ticker) {
this.$$tickers.push(ticker);
ticker.then(() => {
this.$$finished.push(ticker);
});
}
reset() {
this.$$finished = [];
this.$$tickers = [];
}
tick(elapsed) {
for (const ticker of this.$$finished) {
this.$$tickers.splice(
this.$$tickers.indexOf(ticker),
1,
);
}
this.$$finished = [];
for (const ticker of this.$$tickers) {
ticker.tick(elapsed);
}
}
}
}
static properties = {
isTicking: {defaultValue: 1, type: 'uint8'},
};
}