Refactor NPC interaction logic in runtime-interaction-system.ts

This commit is contained in:
2026-04-15 10:57:59 +02:00
parent 8460ac6329
commit 5a132cb351

View File

@@ -336,6 +336,10 @@ function getNpcDialoguePrompt(
const hasNpcDialogue = const hasNpcDialogue =
npc.defaultDialogueId !== null || npc.dialogues.length > 0; npc.defaultDialogueId !== null || npc.dialogues.length > 0;
if (!hasClickLinks) {
return trimmedName.length > 0 ? `Talk to ${trimmedName}` : "Talk";
}
if (hasNpcDialogue) { if (hasNpcDialogue) {
return trimmedName.length > 0 ? `Talk to ${trimmedName}` : "Talk"; return trimmedName.length > 0 ? `Talk to ${trimmedName}` : "Talk";
} }
@@ -586,11 +590,7 @@ export class RuntimeInteractionSystem {
const hasClickLinks = hasTriggerLinks(runtimeScene, npc.entityId, "click"); const hasClickLinks = hasTriggerLinks(runtimeScene, npc.entityId, "click");
if ( if (!hasClickLinks) {
!hasClickLinks &&
npc.defaultDialogueId === null &&
npc.dialogues.length === 0
) {
continue; continue;
} }
@@ -638,20 +638,8 @@ export class RuntimeInteractionSystem {
) ?? null; ) ?? null;
if (npc !== null) { if (npc !== null) {
if (hasTriggerLinks(runtimeScene, npc.entityId, "click")) { this.dispatchLinks(sourceEntityId, "click", runtimeScene, dispatcher);
this.dispatchLinks(sourceEntityId, "click", runtimeScene, dispatcher); return;
return;
}
if (npc.defaultDialogueId !== null || npc.dialogues.length > 0) {
dispatcher.startNpcDialogue?.(npc.entityId, npc.defaultDialogueId, {
kind: "npc",
sourceEntityId: npc.entityId,
linkId: null,
trigger: "click"
});
return;
}
} }
this.dispatchLinks(sourceEntityId, "click", runtimeScene, dispatcher); this.dispatchLinks(sourceEntityId, "click", runtimeScene, dispatcher);