From 5521d28131ba488e3f891c1705ed109c1d2ad1cf Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 13 Jul 2024 00:34:07 -0500 Subject: [PATCH] refactor: easy rebuild --- app/ecs/ecs.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/ecs/ecs.js b/app/ecs/ecs.js index e4af2aa..b584f27 100644 --- a/app/ecs/ecs.js +++ b/app/ecs/ecs.js @@ -309,15 +309,21 @@ export default class Ecs { } rebuild(entityId, componentNames) { - let existing = []; - if (this.$$entities[entityId]) { - existing.push(...this.$$entities[entityId].constructor.componentNames); + let Class; + if (componentNames) { + let existing = []; + if (this.$$entities[entityId]) { + existing.push(...this.$$entities[entityId].constructor.componentNames); + } + Class = this.$$entityFactory.makeClass(componentNames(existing), this.Components); + } + else { + Class = this.$$entities[entityId].constructor; } - const Class = this.$$entityFactory.makeClass(componentNames(existing), this.Components); 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) {