refactor: entity $$extends

This commit is contained in:
cha0s 2024-10-21 02:36:41 -05:00
parent 34247e00db
commit 739a3e4f95

View File

@ -204,8 +204,23 @@ export default class Ecs {
return entityIds; return entityIds;
} }
const creating = {}; const creating = {};
const extendedSpecificsList = [];
for (let i = 0; i < specificsList.length; i++) { 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)) { if (!this.$$detached.has(entityId)) {
this.deferredChanges[entityId] = []; this.deferredChanges[entityId] = [];
} }
@ -227,8 +242,8 @@ export default class Ecs {
for (const i in creating) { for (const i in creating) {
this.Components[i].createMany(creating[i]) this.Components[i].createMany(creating[i])
} }
for (let i = 0; i < specificsList.length; i++) { for (let i = 0; i < extendedSpecificsList.length; i++) {
const [entityId, components] = specificsList[i]; const [entityId, components] = extendedSpecificsList[i];
this.rebuild(entityId, () => Object.keys(components)); this.rebuild(entityId, () => Object.keys(components));
if (this.$$detached.has(entityId)) { if (this.$$detached.has(entityId)) {
continue; continue;