diff --git a/server/static/ui_hud.js b/server/static/ui_hud.js new file mode 100644 index 0000000..b742f5c --- /dev/null +++ b/server/static/ui_hud.js @@ -0,0 +1,48 @@ +export function setupHUD(root) { + root.innerHTML = ` + + `; + const panel = root.firstElementChild; + const zoom = panel.querySelector('#hud-zoom'); + + zoom.addEventListener('input', () => { + const z = parseFloat(zoom.value); + window.setGameZoom?.(z); + }); + + panel.querySelector('#hud-inv').onclick = () => { + window.InventoryUI?.toggle(); + }; + panel.querySelector('#hud-craft').onclick = () => { + window.CraftingUI?.toggle(); + }; + panel.querySelector('#hud-logout').onclick = async () => { + await fetch('/api/logout', { method: 'POST' }); + location.reload(); + }; + + // functions for other modules to update XP + window.updateXP = level => { + const label = panel.querySelector('#xplabel'); + label.textContent = `Lvl ${level}`; + const fill = panel.querySelector('#xpfill'); + const pct = Math.min(100, level); // dumb visual + fill.style.width = `${pct}%`; + }; +}