refactor: easy rebuild

This commit is contained in:
cha0s 2024-07-13 00:34:07 -05:00
parent 4256d8770f
commit 5521d28131

View File

@ -309,15 +309,21 @@ export default class Ecs {
}
rebuild(entityId, componentNames) {
let Class;
if (componentNames) {
let existing = [];
if (this.$$entities[entityId]) {
existing.push(...this.$$entities[entityId].constructor.componentNames);
}
const Class = this.$$entityFactory.makeClass(componentNames(existing), this.Components);
Class = this.$$entityFactory.makeClass(componentNames(existing), this.Components);
}
else {
Class = this.$$entities[entityId].constructor;
}
if (this.$$entities[entityId] && Class === this.$$entities[entityId].constructor) {
// Eventually - memoizable.
}
this.$$entities[entityId] = new Class(entityId);
return this.$$entities[entityId] = new Class(entityId);
}
reindex(entityIds) {