Add a single favorite quest with a top-screen objective tracker.
Active quests can be starred in the quest list; the first unfinished objective shows above toasts with the same chip style and progress counts.
@@ -62,7 +62,10 @@
62
62
</div>
63
63
</section>
64
64
</aside>
65
<div id="toast-stack" aria-live="polite"></div>
65
<div id="top-center-stack">
66
<div id="quest-tracker" hidden aria-live="polite"></div>
67
<div id="toast-stack" aria-live="polite"></div>
68
</div>
66
69
<div id="world-tooltip" hidden></div>
67
70
68
71
<div id="quests-list-backdrop" class="modal-backdrop" hidden></div>
@@ -62,7 +62,10 @@62
</div>62
</div>63
</section>63
</section>64
</aside>64
</aside>65
<div id="toast-stack" aria-live="polite"></div>65
<div id="top-center-stack">66
<div id="quest-tracker" hidden aria-live="polite"></div>67
<div id="toast-stack" aria-live="polite"></div>68
</div>66
<div id="world-tooltip" hidden></div>69
<div id="world-tooltip" hidden></div>67
70
68
<div id="quests-list-backdrop" class="modal-backdrop" hidden></div>71
<div id="quests-list-backdrop" class="modal-backdrop" hidden></div>@@ -2129,6 +2129,7 @@ async function main ()
2129
2129
closeCreateModal();
2130
2130
startPlay(message);
2131
2131
inventory?.setLocalCharacterId(message.characterId);
2132
questsUi?.setLocalCharacterId?.(message.characterId);
2132
2133
toasts?.applyRestartStatus?.(message.restartStatus);
2133
2134
socket.send({ type: MessageType.requestQuests });
2134
2135
break;
@@ -2129,6 +2129,7 @@ async function main ()2129
closeCreateModal();2129
closeCreateModal();2130
startPlay(message);2130
startPlay(message);2131
inventory?.setLocalCharacterId(message.characterId);2131
inventory?.setLocalCharacterId(message.characterId);2132
questsUi?.setLocalCharacterId?.(message.characterId);2132
toasts?.applyRestartStatus?.(message.restartStatus);2133
toasts?.applyRestartStatus?.(message.restartStatus);2133
socket.send({ type: MessageType.requestQuests });2134
socket.send({ type: MessageType.requestQuests });2134
break;2135
break;@@ -1,7 +1,12 @@
1
1
/**
2
* Play HUD Quests list + detail modals + completion popup.
2
* Play HUD Quests list + detail modals + completion popup + favorite tracker.
3
3
*/
4
4
import { formatObjectiveDisplayText } from "/shared/quests/objectiveProgress.js";
5
import {
6
clearFavoriteQuestId,
7
loadFavoriteQuestId,
8
saveFavoriteQuestId
9
} from "/shared/quests/favoriteQuest.js";
5
10
6
11
export function initQuests ({ socket, MessageType, toasts })
7
12
{
@@ -17,12 +22,16 @@ export function initQuests ({ socket, MessageType, toasts })
17
22
const completePanel = document.getElementById("quest-complete-panel");
18
23
const completeTitle = document.getElementById("quest-complete-title");
19
24
const completeBody = document.getElementById("quest-complete-body");
25
const trackerEl = document.getElementById("quest-tracker");
20
26
/** @type {any[]} */
21
27
let quests = [];
22
28
let listOpen = false;
23
29
let detailOpen = false;
24
30
let completeOpen = false;
25
31
let detailQuestId = null;
32
let localCharacterId = 0;
33
/** @type {string|null} */
34
let favoriteQuestId = null;
26
35
27
36
function showList (visible)
28
37
{
@@ -88,6 +97,85 @@ export function initQuests ({ socket, MessageType, toasts })
88
97
{ completeBody?.append(ul); }
89
98
}
90
99
100
function canFavorite (quest)
101
{
102
return !!quest
103
&& quest.state !== "completed"
104
&& !quest.orphaned
105
&& !!quest.step;
106
}
107
108
function setFavorite (questId)
109
{
110
const id = String(questId ?? "").trim() || null;
111
const quest = id ? quests.find((q) => q.questId === id) : null;
112
if (id && !canFavorite(quest))
113
{ return; }
114
favoriteQuestId = id;
115
if (localCharacterId)
116
{
117
if (id)
118
{ saveFavoriteQuestId(localCharacterId, id); }
119
else
120
{ clearFavoriteQuestId(localCharacterId); }
121
}
122
if (listOpen)
123
{ renderList(); }
124
renderTracker();
125
}
126
127
function toggleFavorite (questId)
128
{
129
if (favoriteQuestId === questId)
130
{ setFavorite(null); }
131
else
132
{ setFavorite(questId); }
133
}
134
135
function firstActiveObjective (quest)
136
{
137
if (!canFavorite(quest))
138
{ return null; }
139
for (const obj of quest.step.objectives ?? [])
140
{
141
if (!obj?.done)
142
{ return obj; }
143
}
144
return null;
145
}
146
147
function renderTracker ()
148
{
149
if (!trackerEl)
150
{ return; }
151
const quest = favoriteQuestId
152
? quests.find((q) => q.questId === favoriteQuestId)
153
: null;
154
if (!canFavorite(quest))
155
{
156
if (favoriteQuestId && localCharacterId)
157
{
158
favoriteQuestId = null;
159
clearFavoriteQuestId(localCharacterId);
160
}
161
trackerEl.hidden = true;
162
trackerEl.textContent = "";
163
return;
164
}
165
const obj = firstActiveObjective(quest);
166
if (!obj)
167
{
168
trackerEl.hidden = true;
169
trackerEl.textContent = "";
170
return;
171
}
172
const progress = (obj.current != null && obj.required != null)
173
? { current: obj.current, required: obj.required }
174
: null;
175
trackerEl.textContent = formatObjectiveDisplayText(obj.text, progress);
176
trackerEl.hidden = false;
177
}
178
91
179
function renderList ()
92
180
{
93
181
if (!listBody)
@@ -103,6 +191,8 @@ export function initQuests ({ socket, MessageType, toasts })
103
191
}
104
192
for (const quest of quests)
105
193
{
194
const row = document.createElement("div");
195
row.className = "quests-list-row";
106
196
const btn = document.createElement("button");
107
197
btn.type = "button";
108
198
btn.className = "quests-list-item";
@@ -115,7 +205,29 @@ export function initQuests ({ socket, MessageType, toasts })
115
205
showList(false);
116
206
showDetail(true, quest.questId);
117
207
});
118
listBody.append(btn);
208
const star = document.createElement("button");
209
star.type = "button";
210
star.className = "quests-favorite-btn";
211
const isFav = favoriteQuestId === quest.questId;
212
const allowed = canFavorite(quest);
213
star.textContent = isFav ? "★" : "☆";
214
star.title = !allowed
215
? "Only active quests can be favorited"
216
: (isFav ? "Clear favorite" : "Favorite quest");
217
star.disabled = !allowed && !isFav;
218
star.setAttribute("aria-pressed", isFav ? "true" : "false");
219
if (isFav)
220
{ star.classList.add("active"); }
221
star.addEventListener("click", (event) =>
222
{
223
event.preventDefault();
224
event.stopPropagation();
225
if (!allowed && !isFav)
226
{ return; }
227
toggleFavorite(quest.questId);
228
});
229
row.append(btn, star);
230
listBody.append(row);
119
231
}
120
232
}
121
233
@@ -218,13 +330,32 @@ export function initQuests ({ socket, MessageType, toasts })
218
330
{
219
331
return listOpen || detailOpen || completeOpen;
220
332
},
333
setLocalCharacterId (characterId)
334
{
335
localCharacterId = characterId | 0;
336
favoriteQuestId = loadFavoriteQuestId(localCharacterId);
337
renderTracker();
338
if (listOpen)
339
{ renderList(); }
340
},
221
341
applySnapshot (message)
222
342
{
223
343
quests = Array.isArray(message?.quests) ? message.quests : [];
344
if (favoriteQuestId)
345
{
346
const fav = quests.find((q) => q.questId === favoriteQuestId);
347
if (!canFavorite(fav))
348
{
349
favoriteQuestId = null;
350
if (localCharacterId)
351
{ clearFavoriteQuestId(localCharacterId); }
352
}
353
}
224
354
if (listOpen)
225
355
{ renderList(); }
226
356
if (detailOpen)
227
357
{ renderDetail(); }
358
renderTracker();
228
359
},
229
360
handleStepComplete (message)
230
361
{
@@ -253,6 +384,8 @@ export function initQuests ({ socket, MessageType, toasts })
253
384
},
254
385
handleComplete (message)
255
386
{
387
if (message?.questId && favoriteQuestId === message.questId)
388
{ setFavorite(null); }
256
389
showComplete(true, message);
257
390
},
258
391
openQuest (questId)
@@ -269,7 +402,10 @@ export function initQuests ({ socket, MessageType, toasts })
269
402
reset ()
270
403
{
271
404
quests = [];
405
localCharacterId = 0;
406
favoriteQuestId = null;
272
407
this.hide();
408
renderTracker();
273
409
}
274
410
};
275
411
}
@@ -1,7 +1,12 @@1
/**1
/**2
* Play HUD Quests list + detail modals + completion popup.2
* Play HUD Quests list + detail modals + completion popup + favorite tracker.3
*/3
*/4
import { formatObjectiveDisplayText } from "/shared/quests/objectiveProgress.js";4
import { formatObjectiveDisplayText } from "/shared/quests/objectiveProgress.js";5
import {6
clearFavoriteQuestId,7
loadFavoriteQuestId,8
saveFavoriteQuestId9
} from "/shared/quests/favoriteQuest.js";5
10
6
export function initQuests ({ socket, MessageType, toasts })11
export function initQuests ({ socket, MessageType, toasts })7
{12
{@@ -17,12 +22,16 @@ export function initQuests ({ socket, MessageType, toasts })17
const completePanel = document.getElementById("quest-complete-panel");22
const completePanel = document.getElementById("quest-complete-panel");18
const completeTitle = document.getElementById("quest-complete-title");23
const completeTitle = document.getElementById("quest-complete-title");19
const completeBody = document.getElementById("quest-complete-body");24
const completeBody = document.getElementById("quest-complete-body");25
const trackerEl = document.getElementById("quest-tracker");20
/** @type {any[]} */26
/** @type {any[]} */21
let quests = [];27
let quests = [];22
let listOpen = false;28
let listOpen = false;23
let detailOpen = false;29
let detailOpen = false;24
let completeOpen = false;30
let completeOpen = false;25
let detailQuestId = null;31
let detailQuestId = null;32
let localCharacterId = 0;33
/** @type {string|null} */34
let favoriteQuestId = null;26
35
27
function showList (visible)36
function showList (visible)28
{37
{@@ -88,6 +97,85 @@ export function initQuests ({ socket, MessageType, toasts })88
{ completeBody?.append(ul); }97
{ completeBody?.append(ul); }89
}98
}90
99
100
function canFavorite (quest)101
{102
return !!quest103
&& quest.state !== "completed"104
&& !quest.orphaned105
&& !!quest.step;106
}107
108
function setFavorite (questId)109
{110
const id = String(questId ?? "").trim() || null;111
const quest = id ? quests.find((q) => q.questId === id) : null;112
if (id && !canFavorite(quest))113
{ return; }114
favoriteQuestId = id;115
if (localCharacterId)116
{117
if (id)118
{ saveFavoriteQuestId(localCharacterId, id); }119
else120
{ clearFavoriteQuestId(localCharacterId); }121
}122
if (listOpen)123
{ renderList(); }124
renderTracker();125
}126
127
function toggleFavorite (questId)128
{129
if (favoriteQuestId === questId)130
{ setFavorite(null); }131
else132
{ setFavorite(questId); }133
}134
135
function firstActiveObjective (quest)136
{137
if (!canFavorite(quest))138
{ return null; }139
for (const obj of quest.step.objectives ?? [])140
{141
if (!obj?.done)142
{ return obj; }143
}144
return null;145
}146
147
function renderTracker ()148
{149
if (!trackerEl)150
{ return; }151
const quest = favoriteQuestId152
? quests.find((q) => q.questId === favoriteQuestId)153
: null;154
if (!canFavorite(quest))155
{156
if (favoriteQuestId && localCharacterId)157
{158
favoriteQuestId = null;159
clearFavoriteQuestId(localCharacterId);160
}161
trackerEl.hidden = true;162
trackerEl.textContent = "";163
return;164
}165
const obj = firstActiveObjective(quest);166
if (!obj)167
{168
trackerEl.hidden = true;169
trackerEl.textContent = "";170
return;171
}172
const progress = (obj.current != null && obj.required != null)173
? { current: obj.current, required: obj.required }174
: null;175
trackerEl.textContent = formatObjectiveDisplayText(obj.text, progress);176
trackerEl.hidden = false;177
}178
91
function renderList ()179
function renderList ()92
{180
{93
if (!listBody)181
if (!listBody)@@ -103,6 +191,8 @@ export function initQuests ({ socket, MessageType, toasts })103
}191
}104
for (const quest of quests)192
for (const quest of quests)105
{193
{194
const row = document.createElement("div");195
row.className = "quests-list-row";106
const btn = document.createElement("button");196
const btn = document.createElement("button");107
btn.type = "button";197
btn.type = "button";108
btn.className = "quests-list-item";198
btn.className = "quests-list-item";@@ -115,7 +205,29 @@ export function initQuests ({ socket, MessageType, toasts })115
showList(false);205
showList(false);116
showDetail(true, quest.questId);206
showDetail(true, quest.questId);117
});207
});118
listBody.append(btn);208
const star = document.createElement("button");209
star.type = "button";210
star.className = "quests-favorite-btn";211
const isFav = favoriteQuestId === quest.questId;212
const allowed = canFavorite(quest);213
star.textContent = isFav ? "★" : "☆";214
star.title = !allowed215
? "Only active quests can be favorited"216
: (isFav ? "Clear favorite" : "Favorite quest");217
star.disabled = !allowed && !isFav;218
star.setAttribute("aria-pressed", isFav ? "true" : "false");219
if (isFav)220
{ star.classList.add("active"); }221
star.addEventListener("click", (event) =>222
{223
event.preventDefault();224
event.stopPropagation();225
if (!allowed && !isFav)226
{ return; }227
toggleFavorite(quest.questId);228
});229
row.append(btn, star);230
listBody.append(row);119
}231
}120
}232
}121
233
@@ -218,13 +330,32 @@ export function initQuests ({ socket, MessageType, toasts })218
{330
{219
return listOpen || detailOpen || completeOpen;331
return listOpen || detailOpen || completeOpen;220
},332
},333
setLocalCharacterId (characterId)334
{335
localCharacterId = characterId | 0;336
favoriteQuestId = loadFavoriteQuestId(localCharacterId);337
renderTracker();338
if (listOpen)339
{ renderList(); }340
},221
applySnapshot (message)341
applySnapshot (message)222
{342
{223
quests = Array.isArray(message?.quests) ? message.quests : [];343
quests = Array.isArray(message?.quests) ? message.quests : [];344
if (favoriteQuestId)345
{346
const fav = quests.find((q) => q.questId === favoriteQuestId);347
if (!canFavorite(fav))348
{349
favoriteQuestId = null;350
if (localCharacterId)351
{ clearFavoriteQuestId(localCharacterId); }352
}353
}224
if (listOpen)354
if (listOpen)225
{ renderList(); }355
{ renderList(); }226
if (detailOpen)356
if (detailOpen)227
{ renderDetail(); }357
{ renderDetail(); }358
renderTracker();228
},359
},229
handleStepComplete (message)360
handleStepComplete (message)230
{361
{@@ -253,6 +384,8 @@ export function initQuests ({ socket, MessageType, toasts })253
},384
},254
handleComplete (message)385
handleComplete (message)255
{386
{387
if (message?.questId && favoriteQuestId === message.questId)388
{ setFavorite(null); }256
showComplete(true, message);389
showComplete(true, message);257
},390
},258
openQuest (questId)391
openQuest (questId)@@ -269,7 +402,10 @@ export function initQuests ({ socket, MessageType, toasts })269
reset ()402
reset ()270
{403
{271
quests = [];404
quests = [];405
localCharacterId = 0;406
favoriteQuestId = null;272
this.hide();407
this.hide();408
renderTracker();273
}409
}274
};410
};275
}411
}@@ -192,7 +192,7 @@ body {
192
192
color: #f0f2f6;
193
193
}
194
194
195
#toast-stack {
195
#top-center-stack {
196
196
position: fixed;
197
197
top: 3.4rem;
198
198
left: 50%;
@@ -207,6 +207,36 @@ body {
207
207
width: max-content;
208
208
}
209
209
210
#toast-stack {
211
display: flex;
212
flex-direction: column;
213
align-items: center;
214
gap: 0.4rem;
215
pointer-events: none;
216
width: 100%;
217
}
218
219
#quest-tracker {
220
box-sizing: border-box;
221
width: 100%;
222
background: rgba(12, 14, 18, 0.94);
223
border: 1px solid #4a5568;
224
padding: 0.28rem 0.85rem;
225
font-size: 0.95rem;
226
line-height: 1.25;
227
text-align: center;
228
color: #f0ebe0;
229
white-space: nowrap;
230
overflow: hidden;
231
text-overflow: ellipsis;
232
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
233
pointer-events: none;
234
}
235
236
#quest-tracker[hidden] {
237
display: none !important;
238
}
239
210
240
#world-tooltip {
211
241
position: fixed;
212
242
z-index: 11;
@@ -2793,6 +2823,46 @@ button.friend-account-name:hover {
2793
2823
width: 100%;
2794
2824
}
2795
2825
2826
.quests-list-row {
2827
display: flex;
2828
align-items: stretch;
2829
gap: 0.35rem;
2830
width: 100%;
2831
}
2832
2833
.quests-list-row .quests-list-item {
2834
flex: 1;
2835
min-width: 0;
2836
}
2837
2838
.quests-favorite-btn {
2839
flex: 0 0 auto;
2840
min-width: 2.2rem;
2841
padding: 0.35rem 0.45rem;
2842
border: 1px solid #3a4250;
2843
background: #1a1f28;
2844
color: #6a7384;
2845
font-size: 1.05rem;
2846
line-height: 1;
2847
cursor: pointer;
2848
}
2849
2850
.quests-favorite-btn:hover:not(:disabled) {
2851
border-color: #e0a84a;
2852
color: #e8c84a;
2853
}
2854
2855
.quests-favorite-btn.active {
2856
border-color: #e0a84a;
2857
color: #e8c84a;
2858
background: rgba(224, 168, 74, 0.12);
2859
}
2860
2861
.quests-favorite-btn:disabled {
2862
opacity: 0.35;
2863
cursor: default;
2864
}
2865
2796
2866
.quests-detail-layout {
2797
2867
display: grid;
2798
2868
grid-template-columns: 1fr 1fr;
@@ -192,7 +192,7 @@ body {192
color: #f0f2f6;192
color: #f0f2f6;193
}193
}194
194
195
#toast-stack {195
#top-center-stack {196
position: fixed;196
position: fixed;197
top: 3.4rem;197
top: 3.4rem;198
left: 50%;198
left: 50%;@@ -207,6 +207,36 @@ body {207
width: max-content;207
width: max-content;208
}208
}209
209
210
#toast-stack {211
display: flex;212
flex-direction: column;213
align-items: center;214
gap: 0.4rem;215
pointer-events: none;216
width: 100%;217
}218
219
#quest-tracker {220
box-sizing: border-box;221
width: 100%;222
background: rgba(12, 14, 18, 0.94);223
border: 1px solid #4a5568;224
padding: 0.28rem 0.85rem;225
font-size: 0.95rem;226
line-height: 1.25;227
text-align: center;228
color: #f0ebe0;229
white-space: nowrap;230
overflow: hidden;231
text-overflow: ellipsis;232
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);233
pointer-events: none;234
}235
236
#quest-tracker[hidden] {237
display: none !important;238
}239
210
#world-tooltip {240
#world-tooltip {211
position: fixed;241
position: fixed;212
z-index: 11;242
z-index: 11;@@ -2793,6 +2823,46 @@ button.friend-account-name:hover {2793
width: 100%;2823
width: 100%;2794
}2824
}2795
2825
2826
.quests-list-row {2827
display: flex;2828
align-items: stretch;2829
gap: 0.35rem;2830
width: 100%;2831
}2832
2833
.quests-list-row .quests-list-item {2834
flex: 1;2835
min-width: 0;2836
}2837
2838
.quests-favorite-btn {2839
flex: 0 0 auto;2840
min-width: 2.2rem;2841
padding: 0.35rem 0.45rem;2842
border: 1px solid #3a4250;2843
background: #1a1f28;2844
color: #6a7384;2845
font-size: 1.05rem;2846
line-height: 1;2847
cursor: pointer;2848
}2849
2850
.quests-favorite-btn:hover:not(:disabled) {2851
border-color: #e0a84a;2852
color: #e8c84a;2853
}2854
2855
.quests-favorite-btn.active {2856
border-color: #e0a84a;2857
color: #e8c84a;2858
background: rgba(224, 168, 74, 0.12);2859
}2860
2861
.quests-favorite-btn:disabled {2862
opacity: 0.35;2863
cursor: default;2864
}2865
2796
.quests-detail-layout {2866
.quests-detail-layout {2797
display: grid;2867
display: grid;2798
grid-template-columns: 1fr 1fr;2868
grid-template-columns: 1fr 1fr;@@ -0,0 +1,47 @@
1
import test from "node:test";
2
import assert from "node:assert/strict";
3
import {
4
clearFavoriteQuestId,
5
loadFavoriteQuestId,
6
saveFavoriteQuestId
7
} from "../../shared/quests/favoriteQuest.js";
8
import { formatObjectiveDisplayText } from "../../shared/quests/objectiveProgress.js";
9
10
test("favorite quest id is stored per character", () =>
11
{
12
const store = new Map();
13
const original = globalThis.localStorage;
14
globalThis.localStorage = {
15
getItem (key)
16
{ return store.has(key) ? store.get(key) : null; },
17
setItem (key, value)
18
{ store.set(key, String(value)); },
19
removeItem (key)
20
{ store.delete(key); }
21
};
22
try
23
{
24
saveFavoriteQuestId(7, "fetch-rock");
25
saveFavoriteQuestId(8, "pine-logs");
26
assert.equal(loadFavoriteQuestId(7), "fetch-rock");
27
assert.equal(loadFavoriteQuestId(8), "pine-logs");
28
clearFavoriteQuestId(7);
29
assert.equal(loadFavoriteQuestId(7), null);
30
assert.equal(loadFavoriteQuestId(8), "pine-logs");
31
}
32
finally
33
{
34
if (original === undefined)
35
{ delete globalThis.localStorage; }
36
else
37
{ globalThis.localStorage = original; }
38
}
39
});
40
41
test("tracker label uses objective progress formatting", () =>
42
{
43
assert.equal(
44
formatObjectiveDisplayText("Collect Pine Logs", { current: 5, required: 30 }),
45
"Collect Pine Logs (5 / 30)"
46
);
47
});
@@ -0,0 +1,47 @@1
import test from "node:test";2
import assert from "node:assert/strict";3
import {4
clearFavoriteQuestId,5
loadFavoriteQuestId,6
saveFavoriteQuestId7
} from "../../shared/quests/favoriteQuest.js";8
import { formatObjectiveDisplayText } from "../../shared/quests/objectiveProgress.js";9
10
test("favorite quest id is stored per character", () =>11
{12
const store = new Map();13
const original = globalThis.localStorage;14
globalThis.localStorage = {15
getItem (key)16
{ return store.has(key) ? store.get(key) : null; },17
setItem (key, value)18
{ store.set(key, String(value)); },19
removeItem (key)20
{ store.delete(key); }21
};22
try23
{24
saveFavoriteQuestId(7, "fetch-rock");25
saveFavoriteQuestId(8, "pine-logs");26
assert.equal(loadFavoriteQuestId(7), "fetch-rock");27
assert.equal(loadFavoriteQuestId(8), "pine-logs");28
clearFavoriteQuestId(7);29
assert.equal(loadFavoriteQuestId(7), null);30
assert.equal(loadFavoriteQuestId(8), "pine-logs");31
}32
finally33
{34
if (original === undefined)35
{ delete globalThis.localStorage; }36
else37
{ globalThis.localStorage = original; }38
}39
});40
41
test("tracker label uses objective progress formatting", () =>42
{43
assert.equal(44
formatObjectiveDisplayText("Collect Pine Logs", { current: 5, required: 30 }),45
"Collect Pine Logs (5 / 30)"46
);47
});