BlueGit

timfa questward

Files

questward / shared / quests / initialQuests.js

initialQuests.js

initialQuests.js 1.0 KiB Download Raw
1/** Normalize world-settings list of quests granted to new (and existing) characters. */
2
3export function normalizeInitialQuests (raw)
4{
5 if (!Array.isArray(raw))
6 { return []; }
7 const out = [];
8 const seen = new Set();
9 for (const entry of raw)
10 {
11 const id = String(entry?.questId ?? entry ?? "").trim().slice(0, 80);
12 if (!id || seen.has(id))
13 { continue; }
14 seen.add(id);
15 out.push(id);
16 }
17 return out;
18}
19
20export function initialQuestsEqual (a, b)
21{
22 const left = normalizeInitialQuests(a);
23 const right = normalizeInitialQuests(b);
24 if (left.length !== right.length)
25 { return false; }
26 return left.every((id, index) => id === right[index]);
27}
28
29export function diffInitialQuests (prev, next)
30{
31 const before = new Set(normalizeInitialQuests(prev));
32 const after = normalizeInitialQuests(next);
33 const bullets = [];
34 for (const id of after)
35 {
36 if (!before.has(id))
37 { bullets.push(`Initial quest +${id}`); }
38 }
39 for (const id of before)
40 {
41 if (!after.includes(id))
42 { bullets.push(`Initial quest −${id}`); }
43 }
44 return bullets;
45}