silphius/app/ecs-components/ticking.js
2024-06-27 13:57:02 -05:00

38 lines
935 B
JavaScript

import Component from '@/ecs/component.js';
export default class Ticking extends Component {
instanceFromSchema() {
const Instance = super.instanceFromSchema();
return class TickingInstance extends Instance {
$$finished = [];
$$tickingPromises = [];
addTickingPromise(tickingPromise) {
this.$$tickingPromises.push(tickingPromise);
tickingPromise.then(() => {
this.$$finished.push(tickingPromise);
});
}
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'},
};
}