import { normalizeQuestDef, normalizeDialogueTree, questLookupFromRawDefs } from "../../../shared/quests/normalize.js"; /** Active-revision quest + dialogue defs for the live sim. */ export class QuestContentCache { constructor (worldDb) { this.worldDb = worldDb; this.quests = new Map(); this.dialogues = new Map(); this.reload(); } reload () { const revisionId = this.worldDb.getActiveRevisionId(); this.quests = new Map(); this.dialogues = new Map(); if (revisionId == null) { return; } const questRaws = this.worldDb.listQuestDefs(revisionId); const questLookup = questLookupFromRawDefs(questRaws); for (const raw of questRaws) { const def = normalizeQuestDef(raw, questLookup); this.quests.set(def.questId, def); } for (const raw of this.worldDb.listDialogueTrees(revisionId)) { const tree = normalizeDialogueTree(raw, questLookup); this.dialogues.set(tree.dialogueId, tree); } } quest (questId) { return this.quests.get(String(questId)) ?? null; } dialogue (dialogueId) { return this.dialogues.get(String(dialogueId)) ?? null; } allQuests () { return [...this.quests.values()]; } }