silphius/app/ecs/components/ticking.js

41 lines
869 B
JavaScript
Raw Normal View History

2024-06-26 21:08:09 -05:00
import Component from '@/ecs/component.js';
2024-06-26 21:08:09 -05:00
export default class Ticking extends Component {
instanceFromSchema() {
2024-07-03 21:58:03 -05:00
return class TickingInstance extends super.instanceFromSchema() {
2024-06-27 13:56:43 -05:00
$$finished = [];
2024-07-22 01:31:52 -05:00
$$tickers = [];
2024-06-27 13:56:43 -05:00
2024-07-22 01:31:52 -05:00
add(ticker) {
this.$$tickers.push(ticker);
ticker.then(() => {
this.$$finished.push(ticker);
2024-06-27 13:56:43 -05:00
});
}
2024-06-27 13:56:43 -05:00
2024-07-04 09:05:38 -05:00
reset() {
this.$$finished = [];
2024-07-22 01:31:52 -05:00
this.$$tickers = [];
2024-07-04 09:05:38 -05:00
}
2024-06-27 13:56:43 -05:00
tick(elapsed) {
2024-07-22 01:31:52 -05:00
for (const ticker of this.$$finished) {
this.$$tickers.splice(
this.$$tickers.indexOf(ticker),
2024-06-27 13:56:43 -05:00
1,
);
}
this.$$finished = [];
2024-07-22 01:31:52 -05:00
for (const ticker of this.$$tickers) {
ticker.tick(elapsed);
2024-06-27 13:56:43 -05:00
}
}
2024-06-27 13:56:43 -05:00
}
2024-06-26 21:08:09 -05:00
}
static properties = {
isTicking: {defaultValue: 1, type: 'uint8'},
};
}