From c6afca48c4e184f4e856075be19d3e1ce3111e15 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Mon, 13 Apr 2026 17:27:37 +0200 Subject: [PATCH] Add NPC actor registry functionality --- src/entities/npc-actor-registry.ts | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/entities/npc-actor-registry.ts diff --git a/src/entities/npc-actor-registry.ts b/src/entities/npc-actor-registry.ts new file mode 100644 index 00000000..6d0d98f5 --- /dev/null +++ b/src/entities/npc-actor-registry.ts @@ -0,0 +1,51 @@ +import type { ProjectDocument } from "../document/scene-document"; + +import { getEntityInstances } from "./entity-instances"; + +export interface NpcActorUsage { + actorId: string; + sceneId: string; + sceneName: string; + entityId: string; + entityName?: string; +} + +export function listNpcActorUsages( + projectDocument: ProjectDocument, + actorId: string +): NpcActorUsage[] { + const normalizedActorId = actorId.trim(); + + if (normalizedActorId.length === 0) { + return []; + } + + const usages: NpcActorUsage[] = []; + + for (const scene of Object.values(projectDocument.scenes)) { + for (const entity of getEntityInstances(scene.entities)) { + if (entity.kind !== "npc" || entity.actorId !== normalizedActorId) { + continue; + } + + usages.push({ + actorId: normalizedActorId, + sceneId: scene.id, + sceneName: scene.name, + entityId: entity.id, + entityName: entity.name + }); + } + } + + usages.sort((left, right) => { + return ( + left.sceneName.localeCompare(right.sceneName) || + left.sceneId.localeCompare(right.sceneId) || + (left.entityName ?? "").localeCompare(right.entityName ?? "") || + left.entityId.localeCompare(right.entityId) + ); + }); + + return usages; +} \ No newline at end of file