From d6900a65a20e639b698fc1cefcbddc6fd009c46b Mon Sep 17 00:00:00 2001 From: Tchips46 Date: Mon, 6 Jul 2026 19:35:42 +0200 Subject: [PATCH 1/2] fix(core-editor): reload event searching for entities --- packages/core-editor/src/editor/core-editor.ts | 6 ++---- packages/ecs-lib/wasm/SparseArray.hpp | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/core-editor/src/editor/core-editor.ts b/packages/core-editor/src/editor/core-editor.ts index 0e1fe941..b15f3a59 100644 --- a/packages/core-editor/src/editor/core-editor.ts +++ b/packages/core-editor/src/editor/core-editor.ts @@ -96,10 +96,8 @@ export class CoreEditor { const reg = this.ecsLibrary.registry; return reg.entityFromIndex( reg - .getComponents({ name: "__RESERVED_entityId" }) - // @todo There is an issue here, getIndex return index from 1 but entityFromIndex get index from 0 - // This is a temp fix - .getIndex({ name: "__RESERVED_entityId", entityId: entityId }) - 1, + .getIndexedZipper([{ name: `__RESERVED_entityId` }]) + .find(({ __RESERVED_entityId }) => __RESERVED_entityId.entityId === entityId).id, ); } } diff --git a/packages/ecs-lib/wasm/SparseArray.hpp b/packages/ecs-lib/wasm/SparseArray.hpp index d6d87cc6..983507cc 100644 --- a/packages/ecs-lib/wasm/SparseArray.hpp +++ b/packages/ecs-lib/wasm/SparseArray.hpp @@ -293,6 +293,7 @@ namespace nfo { */ [[nodiscard]] size_type get_index(const_reference_type value) const { + // @todo This is not how we compare js values so this function is broken for now auto it = std::find(_data.begin(), _data.end(), value); if (it != _data.end()) { return static_cast(std::distance(_data.begin(), it)); From 01fc08d6c3eae0cdb84f02102258492054bdc320 Mon Sep 17 00:00:00 2001 From: Tchips46 Date: Mon, 6 Jul 2026 20:04:02 +0200 Subject: [PATCH 2/2] fix(core-editor): reload event searching for entities --- .../core-editor/test/editor-feature.spec.ts | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/packages/core-editor/test/editor-feature.spec.ts b/packages/core-editor/test/editor-feature.spec.ts index 191cf94d..c63fc5d1 100644 --- a/packages/core-editor/test/editor-feature.spec.ts +++ b/packages/core-editor/test/editor-feature.spec.ts @@ -2,7 +2,7 @@ import { type IRunOptions } from "@nanoforge-dev/common"; import { afterEach, describe, expect, it, vi } from "vitest"; import { type ApplicationConfig } from "../../core/src/application/application-config"; -import { CoreEvents } from "../src/common/context/events/core-events"; +import { CoreEvents } from "../src"; import { type Save, type SaveComponent, type SaveEntity } from "../src/common/context/save.type"; import { type Core } from "../src/core/core"; import { CoreEditor } from "../src/editor/core-editor"; @@ -35,14 +35,25 @@ describe("EditorFeatures", () => { describe("askEntitiesHotReload", () => { it("should reload entities with new save variables", async () => { - const getIndex = vi.fn((component) => { - return Number(component.entityId.slice(-1)); - }); - const FakeRegistry = vi.fn( class { addComponent = vi.fn(); - getComponents = vi.fn(() => ({ getIndex })); + getIndexedZipper = vi.fn(() => [ + { + id: 2, + __RESERVED_entityId: { + entityId: "ent2", + name: "__RESERVED_entityId", + }, + }, + { + id: 3, + __RESERVED_entityId: { + entityId: "ent3", + name: "__RESERVED_entityId", + }, + }, + ]); getEntityComponent = vi.fn((entity: number, component) => { return ( { @@ -75,9 +86,7 @@ describe("EditorFeatures", () => { )[entity]?.[component.name]; }); entityFromIndex = vi.fn((index) => { - // @todo There is an issue here, see src/editor/core-editor.ts:97 - // This is a temp fix - return index + 1; + return index; }); }, ); @@ -136,19 +145,7 @@ describe("EditorFeatures", () => { getComponentSystemLibrary: () => ({ library: { registry: fakeReg } }), } as unknown as ApplicationConfig, ).hotReloadEvent({ components, entities } as any as Save); - expect(fakeReg.getComponents).toHaveBeenCalledWith({ name: "__RESERVED_entityId" }); - expect(getIndex).toHaveBeenNthCalledWith(1, { - entityId: "ent2", - name: "__RESERVED_entityId", - }); - expect(getIndex).toHaveBeenNthCalledWith(2, { - entityId: "ent2", - name: "__RESERVED_entityId", - }); - expect(getIndex).toHaveBeenNthCalledWith(3, { - entityId: "ent3", - name: "__RESERVED_entityId", - }); + expect(fakeReg.getIndexedZipper).toHaveBeenCalledWith([{ name: "__RESERVED_entityId" }]); expect(fakeReg.getEntityComponent).toHaveBeenNthCalledWith(1, 2, { name: "Position" }); expect(fakeReg.getEntityComponent).toHaveBeenNthCalledWith(2, 2, { name: "Bullets" }); expect(fakeReg.getEntityComponent).toHaveBeenNthCalledWith(3, 3, { name: "Position" });