refactor: easy rebuild
This commit is contained in:
parent
4256d8770f
commit
5521d28131
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user