BlueGit

timfa questward

Files

questward / server / src / quests / contentCache.js

contentCache.js

feat: branch quest steps and remember which steps were finished
timfa project_85689633_bot_760517ee9267c86ff1d6c3a0237abf7d · pushed by timfa · 4 weeks ago
25915c58 History
contentCache.js 1.1 KiB Download Raw
1import {
2 normalizeQuestDef,
3 normalizeDialogueTree,
4 questLookupFromRawDefs
5} from "../../../shared/quests/normalize.js";
6
7/** Active-revision quest + dialogue defs for the live sim. */
8export 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}