diff --git a/app/ecs/ecs.js b/app/ecs/ecs.js index dcda2b9..a17f7ae 100644 --- a/app/ecs/ecs.js +++ b/app/ecs/ecs.js @@ -204,8 +204,23 @@ export default class Ecs { return entityIds; } const creating = {}; + const extendedSpecificsList = []; for (let i = 0; i < specificsList.length; i++) { - const [entityId, components] = specificsList[i]; + const [entityId, rawComponents] = specificsList[i]; + let { + $$extends, + ...components + } = rawComponents; + if ($$extends) { + components = { + ...this.readJson($$extends), + ...components, + }; + } + extendedSpecificsList.push([entityId, components]); + } + for (let i = 0; i < extendedSpecificsList.length; i++) { + const [entityId, components] = extendedSpecificsList[i]; if (!this.$$detached.has(entityId)) { this.deferredChanges[entityId] = []; } @@ -227,8 +242,8 @@ export default class Ecs { for (const i in creating) { this.Components[i].createMany(creating[i]) } - for (let i = 0; i < specificsList.length; i++) { - const [entityId, components] = specificsList[i]; + for (let i = 0; i < extendedSpecificsList.length; i++) { + const [entityId, components] = extendedSpecificsList[i]; this.rebuild(entityId, () => Object.keys(components)); if (this.$$detached.has(entityId)) { continue;