From 634c8a73e20b749abcf1f2c142e84b8c0cc7534e Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Tue, 14 Apr 2026 02:09:08 +0200 Subject: [PATCH] Update NPC presence filtering logic to use project scheduler routines --- tests/domain/build-runtime-scene.test.ts | 48 +++++++++++++++++------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/tests/domain/build-runtime-scene.test.ts b/tests/domain/build-runtime-scene.test.ts index 676c0383..0dfbb7f3 100644 --- a/tests/domain/build-runtime-scene.test.ts +++ b/tests/domain/build-runtime-scene.test.ts @@ -832,27 +832,18 @@ describe("buildRuntimeSceneFromDocument", () => { }); }); - it("filters active NPC presence from the current project-global runtime clock", () => { + it("filters active NPCs from the project scheduler against the current runtime clock", () => { const alwaysNpc = createNpcEntity({ id: "entity-npc-always", - actorId: "actor-town-always", - presence: createNpcAlwaysPresence() + actorId: "actor-town-always" }); const daytimeNpc = createNpcEntity({ id: "entity-npc-daytime", - actorId: "actor-town-daytime", - presence: createNpcTimeWindowPresence({ - startHour: 9, - endHour: 17 - }) + actorId: "actor-town-daytime" }); const overnightNpc = createNpcEntity({ id: "entity-npc-overnight", - actorId: "actor-town-overnight", - presence: createNpcTimeWindowPresence({ - startHour: 22, - endHour: 2 - }) + actorId: "actor-town-overnight" }); const document = { ...createEmptySceneDocument({ name: "NPC Presence Scene" }), @@ -862,6 +853,28 @@ describe("buildRuntimeSceneFromDocument", () => { [overnightNpc.id]: overnightNpc } }; + document.scheduler.routines["routine-daytime"] = createProjectScheduleRoutine({ + id: "routine-daytime", + title: "Day Shift", + target: createActorControlTargetRef(daytimeNpc.actorId), + startHour: 9, + endHour: 17, + effect: createSetActorPresenceControlEffect({ + target: createActorControlTargetRef(daytimeNpc.actorId), + active: true + }) + }); + document.scheduler.routines["routine-overnight"] = createProjectScheduleRoutine({ + id: "routine-overnight", + title: "Night Shift", + target: createActorControlTargetRef(overnightNpc.actorId), + startHour: 22, + endHour: 2, + effect: createSetActorPresenceControlEffect({ + target: createActorControlTargetRef(overnightNpc.actorId), + active: true + }) + }); const daytimeRuntimeScene = buildRuntimeSceneFromDocument(document, { runtimeClock: { @@ -914,6 +927,15 @@ describe("buildRuntimeSceneFromDocument", () => { .filter((collider) => collider.source === "npc") .map((collider) => collider.entityId) ).toEqual(["entity-npc-always", "entity-npc-overnight"]); + expect( + overnightRuntimeScene.entities.npcs.find( + (npc) => npc.entityId === overnightNpc.id + ) + ).toEqual( + expect.objectContaining({ + activeRoutineTitle: "Night Shift" + }) + ); }); it("builds a deterministic fallback spawn when no PlayerStart is authored", () => {