BlueGit

timfa questward

Files

questward / client / src / play / skills.js

skills.js

skills.js 1.5 KiB Download Raw
1export function initSkills ()
2{
3 const panel = document.getElementById("skills-panel");
4 const list = document.getElementById("skills-list");
5 let current = [];
6 document.getElementById("skills-toggle").addEventListener("click", () =>
7 {
8 panel.hidden = !panel.hidden;
9 });
10
11 function render (skills)
12 {
13 current = skills ?? [];
14 list.replaceChildren();
15 for (const skill of current)
16 {
17 list.append(renderSkillRow(skill));
18 }
19 }
20
21 return {
22 render,
23 skillLevel (skillId)
24 {
25 return current.find((entry) => entry.skillId === skillId)?.level ?? 1;
26 },
27 hide ()
28 {
29 panel.hidden = true;
30 }
31 };
32}
33
34function renderSkillRow (skill)
35{
36 const row = document.createElement("div");
37 row.className = "skill-row";
38
39 const icon = document.createElement("img");
40 icon.className = "skill-icon";
41 icon.src = skill.icon;
42 icon.alt = "";
43 icon.loading = "lazy";
44
45 const body = document.createElement("div");
46 body.className = "skill-body";
47
48 const title = document.createElement("div");
49 title.className = "skill-title";
50 title.textContent = `${skill.displayName} — Level ${skill.level}`;
51
52 const track = document.createElement("div");
53 track.className = "skill-xp-track";
54 const fill = document.createElement("div");
55 fill.className = "skill-xp-fill";
56 const pct = skill.xpToNext > 0 ? Math.min(100, (skill.xp / skill.xpToNext) * 100) : 100;
57 fill.style.width = `${pct}%`;
58 track.title = `${skill.xp} / ${skill.xpToNext} XP to next level`;
59 track.append(fill);
60
61 body.append(title, track);
62 row.append(icon, body);
63 return row;
64}