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