BlueGit

timfa questward

Show a short-lived XP progress HUD when skills gain experience.

Icon and bar stack under the top HUD, sorted by most recent gain, and the five-second timer resets on each XP tick.

timfa Tim Falken · pushed by timfa

Authored 2026-08-30 · 2 months ago

Hash
5271ac24714ea7a5094716d943e27ca36b21e69a
Parent
70146bec
3 files changed +215 −10
.cursor/rules/git-feature-branch-workflow.mdc added +22 −0
@@ -0,0 +1,22 @@
1 ---
2 description: Commit on feature branches after work; push means merge to master
3 alwaysApply: true
4 ---
5
6 # Git: commit as you go, push only when asked
7
8 ## After finishing a change set
9
10 - Create or reuse a **feature branch** (do not leave finished work only on dirty `master`).
11 - **Commit immediately** without asking for confirmation — prefer several small, focused commits over one dump.
12 - Do **not** push unless the user asks.
13
14 ## When the user asks to push
15
16 “Push” / “naar origin” means this sequence:
17
18 1. Merge the feature branch into `master` (fast-forward when possible).
19 2. Push `master` to `origin`.
20 3. Delete the local (and remote, if it existed) feature branch — it is obsolete after merge.
21
22 Do not leave the finished work only on a remote feature branch unless the user explicitly wants a PR instead of merging to master.
@@ -0,0 +1,22 @@
1---
2description: Commit on feature branches after work; push means merge to master
3alwaysApply: true
4---
5
6# Git: commit as you go, push only when asked
7
8## After finishing a change set
9
10- Create or reuse a **feature branch** (do not leave finished work only on dirty `master`).
11- **Commit immediately** without asking for confirmation — prefer several small, focused commits over one dump.
12- Do **not** push unless the user asks.
13
14## When the user asks to push
15
16“Push” / “naar origin” means this sequence:
17
181. Merge the feature branch into `master` (fast-forward when possible).
192. Push `master` to `origin`.
203. Delete the local (and remote, if it existed) feature branch — it is obsolete after merge.
21
22Do not leave the finished work only on a remote feature branch unless the user explicitly wants a PR instead of merging to master.
client/src/play/skills.js +141 −8
@@ -1,15 +1,22 @@
1 1 import { equipmentBonusesFromSlots } from "/shared/equipment/stats.js";
2 2
3 const XP_GAIN_VISIBLE_MS = 5000;
4
3 5 export function initSkills ({ getEquipmentSlots, getSettings } = {})
4 6 {
5 7 const panel = document.getElementById("skills-panel");
6 8 const list = document.getElementById("skills-list");
9 const gainHud = document.getElementById("xp-gain-hud");
7 10 let current = [];
11 /** @type {Map<string, { skill: object, gainedAt: number }>} */
12 const recentGains = new Map();
13 let hideTimer = null;
14
8 15 document.getElementById("skills-toggle").addEventListener("click", () =>
9 16 {
10 17 panel.hidden = !panel.hidden;
11 18 if (!panel.hidden)
12 { render(current); }
19 { renderPanel(current); }
13 20 });
14 21
15 22 function equipmentBonuses ()
@@ -20,23 +27,114 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})
20 27 );
21 28 }
22 29
23 function render (skills)
30 function clearHideTimer ()
31 {
32 if (hideTimer != null)
33 {
34 window.clearTimeout(hideTimer);
35 hideTimer = null;
36 }
37 }
38
39 function scheduleHide ()
40 {
41 clearHideTimer();
42 hideTimer = window.setTimeout(() =>
43 {
44 hideTimer = null;
45 recentGains.clear();
46 renderGainHud();
47 }, XP_GAIN_VISIBLE_MS);
48 }
49
50 function skillGainedXp (prev, next)
51 {
52 if (!prev)
53 { return false; }
54 if ((next.level | 0) > (prev.level | 0))
55 { return true; }
56 if ((next.level | 0) === (prev.level | 0) && (next.xp | 0) > (prev.xp | 0))
57 { return true; }
58 return false;
59 }
60
61 function noteXpGains (previous, nextSkills)
62 {
63 if (!gainHud)
64 { return; }
65 const prevById = new Map((previous ?? []).map((skill) => [skill.skillId, skill]));
66 const now = performance.now();
67 let anyGain = false;
68 for (const skill of nextSkills ?? [])
69 {
70 const prev = prevById.get(skill.skillId);
71 if (skillGainedXp(prev, skill))
72 {
73 recentGains.set(skill.skillId, { skill: { ...skill }, gainedAt: now });
74 anyGain = true;
75 }
76 else if (recentGains.has(skill.skillId))
77 { recentGains.get(skill.skillId).skill = { ...skill }; }
78 }
79 if (anyGain)
80 { scheduleHide(); }
81 if (anyGain || recentGains.size)
82 { renderGainHud(); }
83 }
84
85 function renderGainHud ()
86 {
87 if (!gainHud)
88 { return; }
89 if (!recentGains.size)
90 {
91 gainHud.hidden = true;
92 gainHud.replaceChildren();
93 return;
94 }
95 const rows = [...recentGains.values()]
96 .sort((a, b) => b.gainedAt - a.gainedAt);
97 gainHud.replaceChildren();
98 for (const entry of rows)
99 { gainHud.append(renderGainRow(entry.skill)); }
100 gainHud.hidden = false;
101 }
102
103 function renderPanel (skills)
24 104 {
25 current = skills ?? [];
26 105 const bonuses = equipmentBonuses();
27 106 list.replaceChildren();
28 for (const skill of current)
107 for (const skill of skills)
29 108 {
30 109 list.append(renderSkillRow(skill, bonuses[skill.skillId] | 0));
31 110 }
32 111 }
33 112
113 function render (skills)
114 {
115 const next = skills ?? [];
116 const previous = current;
117 noteXpGains(previous, next);
118 current = next;
119 if (!panel.hidden)
120 { renderPanel(current); }
121 }
122
34 123 return {
35 124 render,
36 125 refresh ()
37 126 {
38 if (current.length)
39 { render(current); }
127 if (current.length && !panel.hidden)
128 { renderPanel(current); }
129 if (recentGains.size)
130 {
131 for (const skill of current)
132 {
133 if (recentGains.has(skill.skillId))
134 { recentGains.get(skill.skillId).skill = { ...skill }; }
135 }
136 renderGainHud();
137 }
40 138 },
41 139 skillLevel (skillId)
42 140 {
@@ -45,10 +143,46 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})
45 143 hide ()
46 144 {
47 145 panel.hidden = true;
146 clearHideTimer();
147 recentGains.clear();
148 if (gainHud)
149 {
150 gainHud.hidden = true;
151 gainHud.replaceChildren();
152 }
48 153 }
49 154 };
50 155 }
51 156
157 function xpPercent (skill)
158 {
159 return skill.xpToNext > 0 ? Math.min(100, (skill.xp / skill.xpToNext) * 100) : 100;
160 }
161
162 function renderGainRow (skill)
163 {
164 const row = document.createElement("div");
165 row.className = "xp-gain-row";
166
167 const icon = document.createElement("img");
168 icon.className = "xp-gain-icon";
169 icon.src = skill.icon;
170 icon.alt = skill.displayName ?? "";
171 icon.loading = "lazy";
172 icon.title = `${skill.displayName} — Level ${skill.level}`;
173
174 const track = document.createElement("div");
175 track.className = "xp-gain-track";
176 track.title = `${skill.xp} / ${skill.xpToNext} XP to next level`;
177 const fill = document.createElement("div");
178 fill.className = "xp-gain-fill";
179 fill.style.width = `${xpPercent(skill)}%`;
180 track.append(fill);
181
182 row.append(icon, track);
183 return row;
184 }
185
52 186 function renderSkillRow (skill, bonus)
53 187 {
54 188 const row = document.createElement("div");
@@ -72,8 +206,7 @@ function renderSkillRow (skill, bonus)
72 206 track.className = "skill-xp-track";
73 207 const fill = document.createElement("div");
74 208 fill.className = "skill-xp-fill";
75 const pct = skill.xpToNext > 0 ? Math.min(100, (skill.xp / skill.xpToNext) * 100) : 100;
76 fill.style.width = `${pct}%`;
209 fill.style.width = `${xpPercent(skill)}%`;
77 210 track.title = `${skill.xp} / ${skill.xpToNext} XP to next level`;
78 211 track.append(fill);
79 212
@@ -1,15 +1,22 @@
1import { equipmentBonusesFromSlots } from "/shared/equipment/stats.js";
1import { equipmentBonusesFromSlots } from "/shared/equipment/stats.js";
2
2
3const XP_GAIN_VISIBLE_MS = 5000;
4
3export function initSkills ({ getEquipmentSlots, getSettings } = {})
5export function initSkills ({ getEquipmentSlots, getSettings } = {})
4{
6{
5 const panel = document.getElementById("skills-panel");
7 const panel = document.getElementById("skills-panel");
6 const list = document.getElementById("skills-list");
8 const list = document.getElementById("skills-list");
9 const gainHud = document.getElementById("xp-gain-hud");
7 let current = [];
10 let current = [];
11 /** @type {Map<string, { skill: object, gainedAt: number }>} */
12 const recentGains = new Map();
13 let hideTimer = null;
14
8 document.getElementById("skills-toggle").addEventListener("click", () =>
15 document.getElementById("skills-toggle").addEventListener("click", () =>
9 {
16 {
10 panel.hidden = !panel.hidden;
17 panel.hidden = !panel.hidden;
11 if (!panel.hidden)
18 if (!panel.hidden)
12 { render(current); }
19 { renderPanel(current); }
13 });
20 });
14
21
15 function equipmentBonuses ()
22 function equipmentBonuses ()
@@ -20,23 +27,114 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})
20 );
27 );
21 }
28 }
22
29
23 function render (skills)
30 function clearHideTimer ()
31 {
32 if (hideTimer != null)
33 {
34 window.clearTimeout(hideTimer);
35 hideTimer = null;
36 }
37 }
38
39 function scheduleHide ()
40 {
41 clearHideTimer();
42 hideTimer = window.setTimeout(() =>
43 {
44 hideTimer = null;
45 recentGains.clear();
46 renderGainHud();
47 }, XP_GAIN_VISIBLE_MS);
48 }
49
50 function skillGainedXp (prev, next)
51 {
52 if (!prev)
53 { return false; }
54 if ((next.level | 0) > (prev.level | 0))
55 { return true; }
56 if ((next.level | 0) === (prev.level | 0) && (next.xp | 0) > (prev.xp | 0))
57 { return true; }
58 return false;
59 }
60
61 function noteXpGains (previous, nextSkills)
62 {
63 if (!gainHud)
64 { return; }
65 const prevById = new Map((previous ?? []).map((skill) => [skill.skillId, skill]));
66 const now = performance.now();
67 let anyGain = false;
68 for (const skill of nextSkills ?? [])
69 {
70 const prev = prevById.get(skill.skillId);
71 if (skillGainedXp(prev, skill))
72 {
73 recentGains.set(skill.skillId, { skill: { ...skill }, gainedAt: now });
74 anyGain = true;
75 }
76 else if (recentGains.has(skill.skillId))
77 { recentGains.get(skill.skillId).skill = { ...skill }; }
78 }
79 if (anyGain)
80 { scheduleHide(); }
81 if (anyGain || recentGains.size)
82 { renderGainHud(); }
83 }
84
85 function renderGainHud ()
86 {
87 if (!gainHud)
88 { return; }
89 if (!recentGains.size)
90 {
91 gainHud.hidden = true;
92 gainHud.replaceChildren();
93 return;
94 }
95 const rows = [...recentGains.values()]
96 .sort((a, b) => b.gainedAt - a.gainedAt);
97 gainHud.replaceChildren();
98 for (const entry of rows)
99 { gainHud.append(renderGainRow(entry.skill)); }
100 gainHud.hidden = false;
101 }
102
103 function renderPanel (skills)
24 {
104 {
25 current = skills ?? [];
26 const bonuses = equipmentBonuses();
105 const bonuses = equipmentBonuses();
27 list.replaceChildren();
106 list.replaceChildren();
28 for (const skill of current)
107 for (const skill of skills)
29 {
108 {
30 list.append(renderSkillRow(skill, bonuses[skill.skillId] | 0));
109 list.append(renderSkillRow(skill, bonuses[skill.skillId] | 0));
31 }
110 }
32 }
111 }
33
112
113 function render (skills)
114 {
115 const next = skills ?? [];
116 const previous = current;
117 noteXpGains(previous, next);
118 current = next;
119 if (!panel.hidden)
120 { renderPanel(current); }
121 }
122
34 return {
123 return {
35 render,
124 render,
36 refresh ()
125 refresh ()
37 {
126 {
38 if (current.length)
127 if (current.length && !panel.hidden)
39 { render(current); }
128 { renderPanel(current); }
129 if (recentGains.size)
130 {
131 for (const skill of current)
132 {
133 if (recentGains.has(skill.skillId))
134 { recentGains.get(skill.skillId).skill = { ...skill }; }
135 }
136 renderGainHud();
137 }
40 },
138 },
41 skillLevel (skillId)
139 skillLevel (skillId)
42 {
140 {
@@ -45,10 +143,46 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})
45 hide ()
143 hide ()
46 {
144 {
47 panel.hidden = true;
145 panel.hidden = true;
146 clearHideTimer();
147 recentGains.clear();
148 if (gainHud)
149 {
150 gainHud.hidden = true;
151 gainHud.replaceChildren();
152 }
48 }
153 }
49 };
154 };
50}
155}
51
156
157function xpPercent (skill)
158{
159 return skill.xpToNext > 0 ? Math.min(100, (skill.xp / skill.xpToNext) * 100) : 100;
160}
161
162function renderGainRow (skill)
163{
164 const row = document.createElement("div");
165 row.className = "xp-gain-row";
166
167 const icon = document.createElement("img");
168 icon.className = "xp-gain-icon";
169 icon.src = skill.icon;
170 icon.alt = skill.displayName ?? "";
171 icon.loading = "lazy";
172 icon.title = `${skill.displayName} — Level ${skill.level}`;
173
174 const track = document.createElement("div");
175 track.className = "xp-gain-track";
176 track.title = `${skill.xp} / ${skill.xpToNext} XP to next level`;
177 const fill = document.createElement("div");
178 fill.className = "xp-gain-fill";
179 fill.style.width = `${xpPercent(skill)}%`;
180 track.append(fill);
181
182 row.append(icon, track);
183 return row;
184}
185
52function renderSkillRow (skill, bonus)
186function renderSkillRow (skill, bonus)
53{
187{
54 const row = document.createElement("div");
188 const row = document.createElement("div");
@@ -72,8 +206,7 @@ function renderSkillRow (skill, bonus)
72 track.className = "skill-xp-track";
206 track.className = "skill-xp-track";
73 const fill = document.createElement("div");
207 const fill = document.createElement("div");
74 fill.className = "skill-xp-fill";
208 fill.className = "skill-xp-fill";
75 const pct = skill.xpToNext > 0 ? Math.min(100, (skill.xp / skill.xpToNext) * 100) : 100;
209 fill.style.width = `${xpPercent(skill)}%`;
76 fill.style.width = `${pct}%`;
77 track.title = `${skill.xp} / ${skill.xpToNext} XP to next level`;
210 track.title = `${skill.xp} / ${skill.xpToNext} XP to next level`;
78 track.append(fill);
211 track.append(fill);
79
212
client/ui/play.css +52 −2
@@ -60,6 +60,58 @@ body {
60 60 display: none !important;
61 61 }
62 62
63 #xp-gain-hud {
64 position: fixed;
65 z-index: 3;
66 top: 2.85rem;
67 right: 0.75rem;
68 display: flex;
69 flex-direction: column;
70 gap: 0.35rem;
71 align-items: stretch;
72 width: min(200px, 42vw);
73 pointer-events: none;
74 }
75
76 #xp-gain-hud[hidden] {
77 display: none !important;
78 }
79
80 .xp-gain-row {
81 display: flex;
82 align-items: center;
83 gap: 0.45rem;
84 padding: 0.3rem 0.4rem;
85 background: rgba(12, 14, 18, 0.9);
86 border: 1px solid #3a4250;
87 }
88
89 .xp-gain-icon {
90 flex: 0 0 28px;
91 width: 28px;
92 height: 28px;
93 border-radius: 4px;
94 background: #101216;
95 border: 1px solid #3a4250;
96 }
97
98 .xp-gain-track {
99 flex: 1;
100 height: 8px;
101 min-width: 0;
102 background: #101216;
103 border: 1px solid #3a4250;
104 border-radius: 4px;
105 overflow: hidden;
106 }
107
108 .xp-gain-fill {
109 height: 100%;
110 background: linear-gradient(90deg, #6a7a40, #d4c48a);
111 border-radius: 3px;
112 transition: width 0.2s ease-out;
113 }
114
63 115 #settings-panel {
64 116 position: fixed;
65 117 z-index: 5;
@@ -1187,7 +1239,6 @@ button.friend-account-name:hover {
1187 1239 cursor: pointer;
1188 1240 }
1189 1241
1190
1191 1242 .craft-recipe-cell.craftable {
1192 1243 border-color: #3f9d62;
1193 1244 box-shadow: inset 0 0 0 1px rgba(63, 157, 98, 0.85);
@@ -1199,7 +1250,6 @@ button.friend-account-name:hover {
1199 1250 }
1200 1251
1201 1252 .craft-recipe-cell.selected {
1202
1203 1253 outline: 2px solid #d4c48a;
1204 1254 }
1205 1255
@@ -60,6 +60,58 @@ body {
60 display: none !important;
60 display: none !important;
61}
61}
62
62
63#xp-gain-hud {
64 position: fixed;
65 z-index: 3;
66 top: 2.85rem;
67 right: 0.75rem;
68 display: flex;
69 flex-direction: column;
70 gap: 0.35rem;
71 align-items: stretch;
72 width: min(200px, 42vw);
73 pointer-events: none;
74}
75
76#xp-gain-hud[hidden] {
77 display: none !important;
78}
79
80.xp-gain-row {
81 display: flex;
82 align-items: center;
83 gap: 0.45rem;
84 padding: 0.3rem 0.4rem;
85 background: rgba(12, 14, 18, 0.9);
86 border: 1px solid #3a4250;
87}
88
89.xp-gain-icon {
90 flex: 0 0 28px;
91 width: 28px;
92 height: 28px;
93 border-radius: 4px;
94 background: #101216;
95 border: 1px solid #3a4250;
96}
97
98.xp-gain-track {
99 flex: 1;
100 height: 8px;
101 min-width: 0;
102 background: #101216;
103 border: 1px solid #3a4250;
104 border-radius: 4px;
105 overflow: hidden;
106}
107
108.xp-gain-fill {
109 height: 100%;
110 background: linear-gradient(90deg, #6a7a40, #d4c48a);
111 border-radius: 3px;
112 transition: width 0.2s ease-out;
113}
114
63#settings-panel {
115#settings-panel {
64 position: fixed;
116 position: fixed;
65 z-index: 5;
117 z-index: 5;
@@ -1187,7 +1239,6 @@ button.friend-account-name:hover {
1187 cursor: pointer;
1239 cursor: pointer;
1188}
1240}
1189
1241
1190
1191.craft-recipe-cell.craftable {
1242.craft-recipe-cell.craftable {
1192 border-color: #3f9d62;
1243 border-color: #3f9d62;
1193 box-shadow: inset 0 0 0 1px rgba(63, 157, 98, 0.85);
1244 box-shadow: inset 0 0 0 1px rgba(63, 157, 98, 0.85);
@@ -1199,7 +1250,6 @@ button.friend-account-name:hover {
1199}
1250}
1200
1251
1201.craft-recipe-cell.selected {
1252.craft-recipe-cell.selected {
1202
1203 outline: 2px solid #d4c48a;
1253 outline: 2px solid #d4c48a;
1204}
1254}
1205
1255