silphius/app/ecs-components/ticking.js
2024-07-04 09:05:38 -05:00

41 lines
995 B
JavaScript

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