BlueGit

timfa questward

Give each XP gain HUD row its own five-second timer.

Only the skill that just gained XP resets; chrome around the icon and bar is removed.

timfa Tim Falken · pushed by timfa

Authored 2026-08-30 · 2 months ago

Hash
49cdb10779f8d7cc7c716217a850686b2ef23e9d
Parent
d7d4b922
2 files changed +37 −29
client/src/play/skills.js +37 −19
@@ -8,9 +8,8 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})
8 8 const list = document.getElementById("skills-list");
9 9 const gainHud = document.getElementById("xp-gain-hud");
10 10 let current = [];
11 /** @type {Map<string, { skill: object, gainedAt: number }>} */
11 /** @type {Map<string, { skill: object, gainedAt: number, timer: number|null }>} */
12 12 const recentGains = new Map();
13 let hideTimer = null;
14 13
15 14 document.getElementById("skills-toggle").addEventListener("click", () =>
16 15 {
@@ -27,22 +26,33 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})
27 26 );
28 27 }
29 28
30 function clearHideTimer ()
29 function clearGainTimer (entry)
31 30 {
32 if (hideTimer != null)
31 if (entry?.timer != null)
33 32 {
34 window.clearTimeout(hideTimer);
35 hideTimer = null;
33 window.clearTimeout(entry.timer);
34 entry.timer = null;
36 35 }
37 36 }
38 37
39 function scheduleHide ()
38 function clearAllGainTimers ()
40 39 {
41 clearHideTimer();
42 hideTimer = window.setTimeout(() =>
40 for (const entry of recentGains.values())
41 { clearGainTimer(entry); }
42 }
43
44 function scheduleGainHide (skillId)
45 {
46 const entry = recentGains.get(skillId);
47 if (!entry)
48 { return; }
49 clearGainTimer(entry);
50 entry.timer = window.setTimeout(() =>
43 51 {
44 hideTimer = null;
45 recentGains.clear();
52 const currentEntry = recentGains.get(skillId);
53 if (currentEntry)
54 { clearGainTimer(currentEntry); }
55 recentGains.delete(skillId);
46 56 renderGainHud();
47 57 }, XP_GAIN_VISIBLE_MS);
48 58 }
@@ -64,21 +74,29 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})
64 74 { return; }
65 75 const prevById = new Map((previous ?? []).map((skill) => [skill.skillId, skill]));
66 76 const now = performance.now();
67 let anyGain = false;
77 let changed = false;
68 78 for (const skill of nextSkills ?? [])
69 79 {
70 80 const prev = prevById.get(skill.skillId);
71 81 if (skillGainedXp(prev, skill))
72 82 {
73 recentGains.set(skill.skillId, { skill: { ...skill }, gainedAt: now });
74 anyGain = true;
83 const existing = recentGains.get(skill.skillId);
84 clearGainTimer(existing);
85 recentGains.set(skill.skillId, {
86 skill: { ...skill },
87 gainedAt: now,
88 timer: null
89 });
90 scheduleGainHide(skill.skillId);
91 changed = true;
75 92 }
76 93 else if (recentGains.has(skill.skillId))
77 { recentGains.get(skill.skillId).skill = { ...skill }; }
94 {
95 recentGains.get(skill.skillId).skill = { ...skill };
96 changed = true;
97 }
78 98 }
79 if (anyGain)
80 { scheduleHide(); }
81 if (anyGain || recentGains.size)
99 if (changed)
82 100 { renderGainHud(); }
83 101 }
84 102
@@ -143,7 +161,7 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})
143 161 hide ()
144 162 {
145 163 panel.hidden = true;
146 clearHideTimer();
164 clearAllGainTimers();
147 165 recentGains.clear();
148 166 if (gainHud)
149 167 {
@@ -8,9 +8,8 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})
8 const list = document.getElementById("skills-list");
8 const list = document.getElementById("skills-list");
9 const gainHud = document.getElementById("xp-gain-hud");
9 const gainHud = document.getElementById("xp-gain-hud");
10 let current = [];
10 let current = [];
11 /** @type {Map<string, { skill: object, gainedAt: number }>} */
11 /** @type {Map<string, { skill: object, gainedAt: number, timer: number|null }>} */
12 const recentGains = new Map();
12 const recentGains = new Map();
13 let hideTimer = null;
14
13
15 document.getElementById("skills-toggle").addEventListener("click", () =>
14 document.getElementById("skills-toggle").addEventListener("click", () =>
16 {
15 {
@@ -27,22 +26,33 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})
27 );
26 );
28 }
27 }
29
28
30 function clearHideTimer ()
29 function clearGainTimer (entry)
31 {
30 {
32 if (hideTimer != null)
31 if (entry?.timer != null)
33 {
32 {
34 window.clearTimeout(hideTimer);
33 window.clearTimeout(entry.timer);
35 hideTimer = null;
34 entry.timer = null;
36 }
35 }
37 }
36 }
38
37
39 function scheduleHide ()
38 function clearAllGainTimers ()
40 {
39 {
41 clearHideTimer();
40 for (const entry of recentGains.values())
42 hideTimer = window.setTimeout(() =>
41 { clearGainTimer(entry); }
42 }
43
44 function scheduleGainHide (skillId)
45 {
46 const entry = recentGains.get(skillId);
47 if (!entry)
48 { return; }
49 clearGainTimer(entry);
50 entry.timer = window.setTimeout(() =>
43 {
51 {
44 hideTimer = null;
52 const currentEntry = recentGains.get(skillId);
45 recentGains.clear();
53 if (currentEntry)
54 { clearGainTimer(currentEntry); }
55 recentGains.delete(skillId);
46 renderGainHud();
56 renderGainHud();
47 }, XP_GAIN_VISIBLE_MS);
57 }, XP_GAIN_VISIBLE_MS);
48 }
58 }
@@ -64,21 +74,29 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})
64 { return; }
74 { return; }
65 const prevById = new Map((previous ?? []).map((skill) => [skill.skillId, skill]));
75 const prevById = new Map((previous ?? []).map((skill) => [skill.skillId, skill]));
66 const now = performance.now();
76 const now = performance.now();
67 let anyGain = false;
77 let changed = false;
68 for (const skill of nextSkills ?? [])
78 for (const skill of nextSkills ?? [])
69 {
79 {
70 const prev = prevById.get(skill.skillId);
80 const prev = prevById.get(skill.skillId);
71 if (skillGainedXp(prev, skill))
81 if (skillGainedXp(prev, skill))
72 {
82 {
73 recentGains.set(skill.skillId, { skill: { ...skill }, gainedAt: now });
83 const existing = recentGains.get(skill.skillId);
74 anyGain = true;
84 clearGainTimer(existing);
85 recentGains.set(skill.skillId, {
86 skill: { ...skill },
87 gainedAt: now,
88 timer: null
89 });
90 scheduleGainHide(skill.skillId);
91 changed = true;
75 }
92 }
76 else if (recentGains.has(skill.skillId))
93 else if (recentGains.has(skill.skillId))
77 { recentGains.get(skill.skillId).skill = { ...skill }; }
94 {
95 recentGains.get(skill.skillId).skill = { ...skill };
96 changed = true;
97 }
78 }
98 }
79 if (anyGain)
99 if (changed)
80 { scheduleHide(); }
81 if (anyGain || recentGains.size)
82 { renderGainHud(); }
100 { renderGainHud(); }
83 }
101 }
84
102
@@ -143,7 +161,7 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})
143 hide ()
161 hide ()
144 {
162 {
145 panel.hidden = true;
163 panel.hidden = true;
146 clearHideTimer();
164 clearAllGainTimers();
147 recentGains.clear();
165 recentGains.clear();
148 if (gainHud)
166 if (gainHud)
149 {
167 {
client/ui/play.css +0 −10
@@ -81,34 +81,24 @@ body {
81 81 display: flex;
82 82 align-items: center;
83 83 gap: 0.45rem;
84 padding: 0.3rem 0.4rem;
85 background: rgba(12, 14, 18, 0.9);
86 border: 1px solid #3a4250;
87 84 }
88 85
89 86 .xp-gain-icon {
90 87 flex: 0 0 28px;
91 88 width: 28px;
92 89 height: 28px;
93 border-radius: 4px;
94 background: #101216;
95 border: 1px solid #3a4250;
96 90 }
97 91
98 92 .xp-gain-track {
99 93 flex: 1;
100 94 height: 8px;
101 95 min-width: 0;
102 background: #101216;
103 border: 1px solid #3a4250;
104 border-radius: 4px;
105 96 overflow: hidden;
106 97 }
107 98
108 99 .xp-gain-fill {
109 100 height: 100%;
110 101 background: linear-gradient(90deg, #6a7a40, #d4c48a);
111 border-radius: 3px;
112 102 transition: width 0.2s ease-out;
113 103 }
114 104
@@ -81,34 +81,24 @@ body {
81 display: flex;
81 display: flex;
82 align-items: center;
82 align-items: center;
83 gap: 0.45rem;
83 gap: 0.45rem;
84 padding: 0.3rem 0.4rem;
85 background: rgba(12, 14, 18, 0.9);
86 border: 1px solid #3a4250;
87}
84}
88
85
89.xp-gain-icon {
86.xp-gain-icon {
90 flex: 0 0 28px;
87 flex: 0 0 28px;
91 width: 28px;
88 width: 28px;
92 height: 28px;
89 height: 28px;
93 border-radius: 4px;
94 background: #101216;
95 border: 1px solid #3a4250;
96}
90}
97
91
98.xp-gain-track {
92.xp-gain-track {
99 flex: 1;
93 flex: 1;
100 height: 8px;
94 height: 8px;
101 min-width: 0;
95 min-width: 0;
102 background: #101216;
103 border: 1px solid #3a4250;
104 border-radius: 4px;
105 overflow: hidden;
96 overflow: hidden;
106}
97}
107
98
108.xp-gain-fill {
99.xp-gain-fill {
109 height: 100%;
100 height: 100%;
110 background: linear-gradient(90deg, #6a7a40, #d4c48a);
101 background: linear-gradient(90deg, #6a7a40, #d4c48a);
111 border-radius: 3px;
112 transition: width 0.2s ease-out;
102 transition: width 0.2s ease-out;
113}
103}
114
104