| 1 | import { |
| 2 | normalizeQuestDef, |
| 3 | normalizeDialogueTree, |
| 4 | questLookupFromRawDefs |
| 5 | } from "../../../shared/quests/normalize.js"; |
| 6 | |
| 7 | /** Active-revision quest + dialogue defs for the live sim. */ |
| 8 | export class QuestContentCache |
| 9 | { |
| 10 | constructor (worldDb) |
| 11 | { |
| 12 | this.worldDb = worldDb; |
| 13 | this.quests = new Map(); |
| 14 | this.dialogues = new Map(); |
| 15 | this.reload(); |
| 16 | } |
| 17 | |
| 18 | reload () |
| 19 | { |
| 20 | const revisionId = this.worldDb.getActiveRevisionId(); |
| 21 | this.quests = new Map(); |
| 22 | this.dialogues = new Map(); |
| 23 | if (revisionId == null) |
| 24 | { return; } |
| 25 | const questRaws = this.worldDb.listQuestDefs(revisionId); |
| 26 | const questLookup = questLookupFromRawDefs(questRaws); |
| 27 | for (const raw of questRaws) |
| 28 | { |
| 29 | const def = normalizeQuestDef(raw, questLookup); |
| 30 | this.quests.set(def.questId, def); |
| 31 | } |
| 32 | for (const raw of this.worldDb.listDialogueTrees(revisionId)) |
| 33 | { |
| 34 | const tree = normalizeDialogueTree(raw, questLookup); |
| 35 | this.dialogues.set(tree.dialogueId, tree); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | quest (questId) |
| 40 | { |
| 41 | return this.quests.get(String(questId)) ?? null; |
| 42 | } |
| 43 | |
| 44 | dialogue (dialogueId) |
| 45 | { |
| 46 | return this.dialogues.get(String(dialogueId)) ?? null; |
| 47 | } |
| 48 | |
| 49 | allQuests () |
| 50 | { |
| 51 | return [...this.quests.values()]; |
| 52 | } |
| 53 | } |