BlueGit

timfa questward

Files

questward / server / src / quests / contentCache.js

contentCache.js

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