xonecas.ioDon't click! Sean Caetano Martin Sign in

tiny-adventure / commits / a590cc9

Replace DOM HUD with Three.js overlay UI

Title, HUD, combat, inventory, journal and end screens are drawn in an
orthographic overlay layer with canvas-generated textures, nine-slice frames
and a shared text helper. Layout scales from renderer size and DPR so it holds
from 390x844 to 2560x1440. window.__game reports the widget rects.

Co-Authored-By: Claude Sonnet 5.5

sacenox3 days agoa590cc9bc782f85eb6095faf7d3d1e2e77100c60parent 57023ec19 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

web/css/style.css+0-82
@@ -1,82 +0,0 @@
1-:root { --gold: #d9b23a; --ink: #2b1b0c; --metal: #3a3530; --parch: url(/assets/ui_parchment.png); }
2-* { box-sizing: border-box; }
3-html, body { margin: 0; height: 100%; overflow: hidden; background: #150e08; font-family: Georgia, 'Palatino Linotype', serif; color: #f4e6c0; user-select: none; }
4-#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
5-[hidden] { display: none !important; }
6-button { font: inherit; cursor: pointer; color: #f4e6c0; background: linear-gradient(#5a524a, #2e2a26); border: 2px solid #1a1612; outline: 1px solid #8a7a5a; border-radius: 3px; padding: 6px 12px; }
7-button:hover { background: linear-gradient(#6e645a, #3a342e); }
8-kbd { margin-left: 6px; color: var(--gold); font-size: 11px; }
9-.metal { background: linear-gradient(#4a443e, #26221e); border: 2px solid #14110e; box-shadow: inset 0 0 0 1px #8a7a5a, 0 4px 14px #000a; }
10-
11-#topbar { position: fixed; top: 8px; left: 50%; transform: translateX(-50%); display: flex; gap: 18px; align-items: center; padding: 5px 18px; background: linear-gradient(#4a443e, #26221e); border: 2px solid #14110e; box-shadow: inset 0 0 0 1px #8a7a5a; border-radius: 4px; font-size: 14px; }
12-#objective::before { content: '❖ '; color: var(--gold); }
13-#gold { color: var(--gold); }
14-
15-#log { position: fixed; left: 8px; bottom: 124px; width: 330px; max-height: 190px; overflow-y: auto; padding: 6px 10px; font-size: 12.5px; line-height: 1.35; background: #1a1410cc; border: 1px solid #8a7a5a; border-radius: 3px; scrollbar-width: thin; }
16-#log p { margin: 2px 0; }
17-#log .head { color: var(--gold); font-weight: bold; }
18-#log .crit { color: #ffd04a; }
19-#log .kill { color: #ff7a5a; }
20-#log .reward { color: #8fe08a; }
21-#log .hint { color: #b8c8e8; font-style: italic; }
22-
23-#bottom { position: fixed; left: 0; right: 0; bottom: 0; height: 116px; display: flex; align-items: center; gap: 22px; padding: 8px 18px; background: linear-gradient(#3a342e, #1c1814); border-top: 3px solid #0e0c0a; box-shadow: inset 0 2px 0 #8a7a5a; }
24-#portraits { display: flex; gap: 8px; }
25-.portrait { width: 118px; padding: 5px; background: var(--parch) center/175% auto; color: var(--ink); border: 2px solid #14110e; outline: 1px solid #8a7a5a; border-radius: 3px; cursor: pointer; position: relative; }
26-.portrait.sel { outline: 2px solid var(--gold); }
27-.portrait.dead { filter: grayscale(1) brightness(0.6); }
28-.face { float: left; width: 38px; height: 38px; margin-right: 6px; border: 2px solid #14110e; border-radius: 50%; display: grid; place-items: center; font-weight: bold; font-size: 20px; color: #fff; position: relative; text-shadow: 0 1px 2px #000; }
29-.face b { position: absolute; right: -6px; bottom: -6px; font-size: 11px; background: #14110e; border-radius: 8px; padding: 0 4px; color: var(--gold); }
30-.c-fighter { background: #b8392e; } .c-rogue { background: #3f8a4a; } .c-mage { background: #3f62c8; } .c-cleric { background: #a89a60; }
31-.pname { font-size: 12px; font-weight: bold; line-height: 38px; height: 38px; overflow: hidden; white-space: nowrap; }
32-.bar { height: 12px; margin-top: 4px; background: #1a1010; border: 1px solid #14110e; position: relative; clear: both; }
33-.bar span { display: block; height: 100%; transition: width 0.25s; }
34-.bar.hp span { background: linear-gradient(#e0483a, #8a1c14); }
35-.bar.xp { height: 6px; } .bar.xp span { background: linear-gradient(#6ab0ff, #2a5ab0); }
36-.bar em { position: absolute; inset: 0; font-style: normal; font-size: 10px; line-height: 10px; text-align: center; color: #fff; text-shadow: 0 1px 1px #000; }
37-
38-#abilities { display: flex; gap: 6px; padding: 8px; background: #14110e; border: 2px solid #0a0806; outline: 1px solid #8a7a5a; border-radius: 3px; min-width: 150px; min-height: 76px; }
39-.ability { width: 56px; height: 56px; position: relative; border: 2px solid #8a7a5a; background: #222; }
40-.icon { display: block; width: 100%; height: 100%; background-size: 400% 400%; image-rendering: auto; }
41-.ability .key { position: absolute; left: 2px; top: 0; font-size: 10px; color: var(--gold); text-shadow: 0 0 3px #000; }
42-.ability .aname { position: absolute; left: 0; right: 0; bottom: -17px; text-align: center; font-size: 10px; white-space: nowrap; color: #f4e6c0; }
43-#menu { margin-left: auto; display: flex; flex-direction: column; gap: 6px; }
44-
45-.panel { position: fixed; top: 54px; bottom: 132px; width: 380px; padding: 14px 16px; overflow-y: auto; background: var(--parch) center/175% auto; color: var(--ink); border: 4px solid #2a2218; outline: 2px solid #8a7a5a; box-shadow: 0 8px 30px #000a; font-size: 13px; }
46-#panel-inv { right: 12px; } #panel-journal { left: 12px; width: 420px; }
47-.panel h2 { margin: 0 0 8px; font-size: 20px; border-bottom: 2px solid #6a4a2a; }
48-.panel h3, .panel h4 { margin: 8px 0 4px; } .panel .close { position: absolute; top: 8px; right: 10px; padding: 0 8px; }
49-.panel li.done { text-decoration: line-through; opacity: 0.6; }
50-.panel ol, .panel ul { padding-left: 22px; margin: 4px 0; } .panel li { list-style: none; margin: 3px 0; margin-left: -18px; }
51-.hint { margin: 4px 0; font-size: 12px; } .seed { opacity: 0.6; font-size: 11px; }
52-.tabs { display: flex; gap: 4px; flex-wrap: wrap; } .tabs button { padding: 2px 8px; font-size: 12px; } .tabs .on { outline-color: var(--gold); }
53-.hero { margin: 8px 0 4px; font-weight: bold; text-transform: capitalize; }
54-.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
55-.slot, .cell { display: flex; align-items: center; gap: 6px; padding: 4px; background: #00000022; border: 1px solid #6a4a2a; cursor: pointer; font-size: 12px; text-transform: capitalize; }
56-.slot .icon, .cell .icon { width: 38px; height: 38px; flex: none; border: 1px solid #14110e; background-color: #222; }
57-.slot .ghost { opacity: 0.25; }
58-.slot:not(.filled) { cursor: default; }
59-.slot span, .cell span { background: #1a1410; padding: 1px 5px; border-radius: 2px; }
60-.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
61-.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 8px; } .stats span { display: flex; justify-content: space-between; padding: 2px 6px; background: #00000018; } .empty { opacity: 0.6; }
62-
63-#floaters { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
64-.floater { position: absolute; transform: translate(-50%, -50%); font-size: 26px; font-weight: bold; text-shadow: 0 2px 3px #000, 0 0 6px #000; animation: rise 1.2s ease-out forwards; }
65-.floater.dmg { color: #fff; } .floater.hurt { color: #ff6a5a; } .floater.heal { color: #6aff8a; } .floater.crit { color: #ffd04a; font-size: 38px; }
66-@keyframes rise { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -70px; } }
67-#toast { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); padding: 8px 18px; background: #1a1410ee; border: 1px solid var(--gold); border-radius: 3px; opacity: 0; transition: opacity 0.3s; pointer-events: none; }
68-#toast.show { opacity: 1; }
69-#combat-banner { position: fixed; top: 90px; left: 50%; transform: translateX(-50%); font-size: 30px; letter-spacing: 6px; color: #ff6a4a; text-shadow: 0 2px 6px #000; opacity: 0; transition: opacity 0.4s; pointer-events: none; }
70-body.combat #combat-banner { opacity: 1; }
71-
72-#screen { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(#0000 20%, #000c); }
73-#screen.title { background: radial-gradient(#0000 35%, #000a); }
74-#screen.end { background: #000b; }
75-.card { width: 520px; padding: 28px 34px; text-align: center; background: var(--parch) center/175% auto; color: var(--ink); border: 5px solid #2a2218; outline: 2px solid #8a7a5a; box-shadow: 0 10px 50px #000; }
76-.card h1 { margin: 0; font-size: 44px; letter-spacing: 2px; text-shadow: 1px 1px 0 #d9b23a66; }
77-.card h2 { margin: 14px 0 4px; font-size: 22px; }
78-.sub { margin: 4px 0; font-style: italic; } .meta, .party, .help { margin: 6px 0; font-size: 13px; } .help { opacity: 0.7; font-size: 11px; }
79-.row { display: flex; gap: 12px; justify-content: center; margin: 16px 0 8px; }
80-.card button { font-size: 18px; padding: 10px 22px; }
81-.card .alt { font-size: 14px; }
82-.card table { margin: 14px auto; border-collapse: collapse; width: 80%; font-size: 16px; } .card td { padding: 4px 8px; border-bottom: 1px dotted #6a4a2a; } .card td + td { text-align: right; font-weight: bold; }
web/index.html+3-17
@@ -3,27 +3,13 @@
33 <head>
44 <meta charset="utf-8">
55 <title>Tiny Adventure</title>
6-<meta name="viewport" content="width=device-width, initial-scale=1">
6+<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
77 <link rel="icon" href="data:,">
8-<link rel="stylesheet" href="/css/style.css">
8+<style>html,body{margin:0;height:100%;overflow:hidden;background:#150e08}canvas{display:block;touch-action:none}pre{color:#f4e6c0;font:16px Georgia,serif;padding:24px}</style>
99 </head>
1010 <body>
1111 <canvas id="stage"></canvas>
12-<div id="hud" hidden>
13- <div id="topbar"><span id="objective"></span><span id="gold"></span></div>
14- <div id="log"></div>
15- <div id="floaters"></div>
16- <div id="toast"></div>
17- <div id="combat-banner">⚔ COMBAT ⚔</div>
18- <div id="bottom">
19- <div id="portraits"></div>
20- <div id="abilities"></div>
21- <div id="menu"><button id="btn-inv" title="Inventory (I)">Inventory<kbd>I</kbd></button><button id="btn-journal" title="Journal (J)">Journal<kbd>J</kbd></button></div>
22- </div>
23- <section id="panel-inv" class="panel" hidden><h2>Inventory</h2><button class="close">×</button><div id="inv-body"></div></section>
24- <section id="panel-journal" class="panel" hidden><h2>Quest Journal</h2><button class="close">×</button><div id="journal-body"></div></section>
25-</div>
26-<div id="screen"></div>
12+<pre id="fatal" hidden></pre>
2713 <script type="module" src="/js/main.js"></script>
2814 </body>
2915 </html>
web/js/camera.js+1-0
@@ -33,6 +33,7 @@ export function createCamera(canvas) {
3333
3434 function resize(w, h) {
3535 camera.aspect = w / h;
36+ camera.zoom = THREE.MathUtils.clamp(camera.aspect / 1.3, 0.55, 1);
3637 camera.updateProjectionMatrix();
3738 }
3839
web/js/chrome.js+12-0
@@ -0,0 +1,12 @@
1+import { drawText } from './text.js';
2+
3+export const INK = '#2b1b0c';
4+export const PAD = 38;
5+
6+export function chrome(ctx, w, h, title, wd, f, m) {
7+ f.parchment(ctx, 0, 0, w, h, 34);
8+ drawText(ctx, title, w / 2, 24, { size: 20, weight: 'bold', align: 'center', color: INK, shadow: '#fff4' });
9+ const cx = w - PAD - 22;
10+ f.button(ctx, cx, 22, 26, 24, 'x', { hover: wd.hovered('close'), size: 15 });
11+ wd.hit(cx, 22, 26, 24, { name: 'close', key: 'close', onClick: () => m.closePanel() });
12+}
web/js/debug.js+1-43
@@ -1,46 +1,4 @@
1-const VISIBLE = [
2- ['topbar', '#topbar'],
3- ['log', '#log'],
4- ['bottom', '#bottom'],
5- ['portraits', '#portraits'],
6- ['abilities', '#abilities'],
7- ['menu', '#menu'],
8- ['btn-inv', '#btn-inv'],
9- ['btn-journal', '#btn-journal'],
10- ['panel-inv', '#panel-inv'],
11- ['panel-journal', '#panel-journal'],
12- ['toast.show', '#toast.show'],
13- ['card', '#screen .card'],
14-];
15-const MULTI = [
16- ['portrait', '#portraits .portrait'],
17- ['ability', '#abilities .ability'],
18- ['button', '#screen button'],
19-];
20-
21-function rectOf(el) {
22- const r = el.getBoundingClientRect();
23- if (!r.width || !r.height || el.closest('[hidden]')) return null;
24- return { x: r.x, y: r.y, w: r.width, h: r.height };
25-}
26-
27-function domRects() {
28- const out = [];
29- for (const [name, sel] of VISIBLE) {
30- const el = document.querySelector(sel);
31- const r = el && rectOf(el);
32- if (r) out.push({ name, ...r, essential: name !== 'toast.show' });
33- }
34- for (const [name, sel] of MULTI) {
35- document.querySelectorAll(sel).forEach((el, i) => {
36- const r = rectOf(el);
37- if (r) out.push({ name: `${name}-${i}`, ...r, essential: true });
38- });
39- }
40- return out;
41-}
42-
43-export const track = { mode: 'loading', busy: false, rects: domRects };
1+export const track = { mode: 'loading', busy: false, rects: () => [] };
442
453 export function installDebug(ctx) {
464 const { THREE, getState, getWorld, cam, party } = ctx;
web/js/floaters.js+38-0
@@ -0,0 +1,38 @@
1+import * as THREE from '../vendor/three.module.js';
2+import { labelTexture } from './text.js';
3+
4+const COLORS = { dmg: '#ffe08a', crit: '#ffb020', hurt: '#ff6a5a', heal: '#7ae88a', info: '#d8e8ff' };
5+const SIZE = { dmg: 26, crit: 38, hurt: 26, heal: 26, info: 20 };
6+const LIFE = 1.3;
7+
8+export function createFloaters(layer) {
9+ const live = [];
10+
11+ function spawn(x, y, text, cls = 'dmg') {
12+ const lab = labelTexture(String(text), COLORS[cls] || COLORS.dmg);
13+ const mat = new THREE.SpriteMaterial({ map: lab.texture, transparent: true, depthTest: false, toneMapped: false });
14+ const sprite = new THREE.Sprite(mat);
15+ const hgt = SIZE[cls] * 1.5 * layer.scale;
16+ sprite.scale.set(hgt * lab.aspect, hgt, 1);
17+ sprite.renderOrder = 20;
18+ live.push({ sprite, x, y, t: 0, rise: 56 * layer.scale });
19+ layer.scene.add(sprite);
20+ }
21+
22+ function update(dt) {
23+ for (let i = live.length - 1; i >= 0; i--) {
24+ const f = live[i];
25+ f.t += dt;
26+ const p = Math.min(1, f.t / LIFE);
27+ f.sprite.position.set(f.x, layer.h - f.y + f.rise * (1 - Math.pow(1 - p, 2)), 5);
28+ f.sprite.material.opacity = p < 0.6 ? 1 : 1 - (p - 0.6) / 0.4;
29+ if (p >= 1) {
30+ layer.scene.remove(f.sprite);
31+ f.sprite.material.dispose();
32+ live.splice(i, 1);
33+ }
34+ }
35+ }
36+
37+ return { spawn, update };
38+}
web/js/frames.js+114-0
@@ -0,0 +1,114 @@
1+import { drawText } from './text.js';
2+
3+const PARCH_CROP = [115, 5, 790, 1005];
4+const PARCH_SLICE = 170;
5+
6+function sheet(w, h, paint) {
7+ const c = new OffscreenCanvas(w, h);
8+ paint(c.getContext('2d'), w, h);
9+ return c;
10+}
11+
12+function rounded(g, x, y, w, h, r) {
13+ g.beginPath();
14+ g.roundRect(x, y, w, h, r);
15+}
16+
17+function metal(top, bottom, line) {
18+ return sheet(64, 64, (g, w, h) => {
19+ rounded(g, 0, 0, w, h, 9);
20+ const grad = g.createLinearGradient(0, 0, 0, h);
21+ grad.addColorStop(0, top);
22+ grad.addColorStop(1, bottom);
23+ g.fillStyle = grad;
24+ g.fill();
25+ g.lineWidth = 3;
26+ g.strokeStyle = '#120f0c';
27+ g.stroke();
28+ rounded(g, 5, 5, w - 10, h - 10, 5);
29+ g.lineWidth = 1.5;
30+ g.strokeStyle = line;
31+ g.stroke();
32+ });
33+}
34+
35+export function nineSlice(ctx, src, sx, sy, sw, sh, slice, x, y, w, h, edge) {
36+ const e = Math.min(edge, w / 2, h / 2);
37+ const xs = [0, slice, sw - slice, sw];
38+ const ys = [0, slice, sh - slice, sh];
39+ const xd = [0, e, w - e, w];
40+ const yd = [0, e, h - e, h];
41+ for (let j = 0; j < 3; j++) {
42+ for (let i = 0; i < 3; i++) {
43+ ctx.drawImage(src, sx + xs[i], sy + ys[j], xs[i + 1] - xs[i], ys[j + 1] - ys[j], x + xd[i], y + yd[j], xd[i + 1] - xd[i], yd[j + 1] - yd[j]);
44+ }
45+ }
46+}
47+
48+function loadImage(url) {
49+ return fetch(url).then((r) => r.blob()).then(createImageBitmap);
50+}
51+
52+function keyOutWhite(img) {
53+ const c = new OffscreenCanvas(img.width, img.height);
54+ const g = c.getContext('2d');
55+ g.drawImage(img, 0, 0);
56+ const data = g.getImageData(0, 0, c.width, c.height);
57+ const px = data.data;
58+ for (let i = 0; i < px.length; i += 4) {
59+ const lo = Math.min(px[i], px[i + 1], px[i + 2]);
60+ if (lo >= 246) px[i + 3] = 0;
61+ else if (lo > 222) px[i + 3] = Math.round(((246 - lo) / 24) * 255);
62+ }
63+ g.putImageData(data, 0, 0);
64+ return c;
65+}
66+
67+export async function loadFrames() {
68+ const [parchRaw, abilities, items] = await Promise.all([
69+ loadImage('/assets/ui_parchment.png'),
70+ loadImage('/assets/icons_abilities.png'),
71+ loadImage('/assets/icons_items.png'),
72+ ]);
73+ const parch = keyOutWhite(parchRaw);
74+ const src = {
75+ metal: metal('#4a443e', '#26221e', '#8a7a5a'),
76+ metalLight: metal('#6a6258', '#3a342e', '#b49a62'),
77+ metalDark: metal('#2c2824', '#161310', '#5a4e38'),
78+ metalGold: metal('#6a5a2a', '#3a2e12', '#e0bc4a'),
79+ slot: metal('#201c18', '#14110e', '#5a4e38'),
80+ };
81+
82+ const panel = (ctx, x, y, w, h, kind = 'metal') => nineSlice(ctx, src[kind], 0, 0, 64, 64, 16, x, y, w, h, 16);
83+
84+ const parchment = (ctx, x, y, w, h, edge = 40) => nineSlice(ctx, parch, ...PARCH_CROP.slice(0, 2), PARCH_CROP[2], PARCH_CROP[3], PARCH_SLICE, x, y, w, h, edge);
85+
86+ const button = (ctx, x, y, w, h, label, { hover = false, key = '', primary = false, size = 15 } = {}) => {
87+ panel(ctx, x, y, w, h, primary ? (hover ? 'metalGold' : 'metalGold') : hover ? 'metalLight' : 'metal');
88+ if (primary && hover) {
89+ ctx.fillStyle = '#ffe9a022';
90+ ctx.fillRect(x + 4, y + 4, w - 8, h - 8);
91+ }
92+ drawText(ctx, label, x + w / 2 - (key ? 7 : 0), y + (h - size * 1.2) / 2, { size, align: 'center', weight: 'bold', maxW: w - 16 - (key ? 18 : 0), fit: true });
93+ if (key) drawText(ctx, key, x + w - 14, y + (h - 12 * 1.2) / 2 + 1, { size: 12, color: '#d9b23a', align: 'center' });
94+ };
95+
96+ const bar = (ctx, x, y, w, h, ratio, color, back = '#1a1010') => {
97+ ctx.fillStyle = back;
98+ ctx.fillRect(x, y, w, h);
99+ ctx.fillStyle = color;
100+ ctx.fillRect(x + 1, y + 1, Math.max(0, (w - 2) * Math.min(1, Math.max(0, ratio))), h - 2);
101+ ctx.strokeStyle = '#000';
102+ ctx.lineWidth = 1;
103+ ctx.strokeRect(x + 0.5, y + 0.5, w - 1, h - 1);
104+ };
105+
106+ const icon = (ctx, sheetName, i, x, y, size) => {
107+ const img = sheetName === 'items' ? items : abilities;
108+ const cell = 256;
109+ const pad = 22;
110+ ctx.drawImage(img, (i % 4) * cell + pad, Math.floor(i / 4) * cell + pad, cell - pad * 2, cell - pad * 2, x, y, size, size);
111+ };
112+
113+ return { panel, parchment, button, bar, icon };
114+}
web/js/hud.js+175-0
@@ -0,0 +1,175 @@
1+import { drawText, wrap } from './text.js';
2+import { abilityIcon } from './icons.js';
3+import { classColor } from './props.js';
4+
5+const LOG_COLORS = { head: '#d9b23a', crit: '#ffd04a', kill: '#ff7a5a', reward: '#8fe08a', hint: '#b8c8e8' };
6+const INK = '#f4e6c0';
7+const GOLD = '#d9b23a';
8+
9+function coin(ctx, x, y, r) {
10+ ctx.beginPath();
11+ ctx.arc(x, y, r, 0, Math.PI * 2);
12+ ctx.fillStyle = GOLD;
13+ ctx.fill();
14+ ctx.lineWidth = 1.5;
15+ ctx.strokeStyle = '#6a4e10';
16+ ctx.stroke();
17+}
18+
19+export function logRows(ctx, log, width) {
20+ const rows = [];
21+ for (const l of log.slice(-8)) wrap(ctx, l.text, 12.5, l.cls === 'head' ? 'bold' : 'normal', width).forEach((t) => rows.push({ t, cls: l.cls }));
22+ return rows;
23+}
24+
25+export function createHud(layer, m, f) {
26+ const topbar = layer.add('topbar', {
27+ z: 2,
28+ draw(ctx, w, h) {
29+ f.panel(ctx, 0, 0, w, h);
30+ const s = m.state;
31+ const next = s.campaign.main.steps.find((q) => !q.done);
32+ const text = m.toast || (next ? next.text : 'The deed is done.');
33+ ctx.fillStyle = m.toast ? '#ffd27a' : GOLD;
34+ ctx.beginPath();
35+ ctx.moveTo(14, h / 2 - 5);
36+ ctx.lineTo(19, h / 2);
37+ ctx.lineTo(14, h / 2 + 5);
38+ ctx.lineTo(9, h / 2);
39+ ctx.fill();
40+ const goldW = 64;
41+ drawText(ctx, text, 28, (h - 17) / 2, { size: 14, color: m.toast ? '#ffe9b0' : INK, maxW: w - 28 - goldW - 14, fit: true });
42+ coin(ctx, w - goldW + 6, h / 2, 6);
43+ drawText(ctx, String(s.party.gold), w - goldW + 16, (h - 17) / 2, { size: 14, color: GOLD, weight: 'bold' });
44+ },
45+ });
46+
47+ const log = layer.add('log', {
48+ z: 2,
49+ passive: true,
50+ draw(ctx, w, h) {
51+ ctx.fillStyle = '#1a1410d8';
52+ ctx.beginPath();
53+ ctx.roundRect(0, 0, w, h, 5);
54+ ctx.fill();
55+ ctx.strokeStyle = '#8a7a5a';
56+ ctx.lineWidth = 1;
57+ ctx.stroke();
58+ const n = Math.floor((h - 12) / 17);
59+ logRows(ctx, m.log, w - 16).slice(-n).forEach((l, i) => drawText(ctx, l.t, 8, 6 + i * 17, { size: 12.5, color: LOG_COLORS[l.cls] || INK, weight: l.cls === 'head' ? 'bold' : 'normal' }));
60+ },
61+ });
62+
63+ const bottom = layer.add('bottom', {
64+ z: 1,
65+ draw(ctx, w, h) {
66+ const g = ctx.createLinearGradient(0, 0, 0, h);
67+ g.addColorStop(0, '#3a342e');
68+ g.addColorStop(1, '#1c1814');
69+ ctx.fillStyle = g;
70+ ctx.fillRect(0, 0, w, h);
71+ ctx.fillStyle = '#8a7a5a';
72+ ctx.fillRect(0, 0, w, 2);
73+ ctx.fillStyle = '#0e0c0a';
74+ ctx.fillRect(0, 2, w, 2);
75+ },
76+ });
77+
78+ const portraits = layer.add('portraits', {
79+ z: 2,
80+ draw(ctx, w, h, wd) {
81+ const units = m.state.party.units;
82+ const gap = 8;
83+ const cw = (w - gap * 3) / 4;
84+ const small = cw < 110;
85+ units.forEach((u, i) => {
86+ const x = i * (cw + gap);
87+ const cur = m.hp ? m.hp.get(u.id) ?? u.stats.hp : u.stats.hp;
88+ const dead = cur <= 0;
89+ const sel = u.id === m.selected;
90+ f.panel(ctx, x, 0, cw, h, sel ? 'metalGold' : 'metalDark');
91+ const d = small ? 24 : 34;
92+ const fx = x + 8 + d / 2;
93+ const fy = 8 + d / 2;
94+ ctx.beginPath();
95+ ctx.arc(fx, fy, d / 2, 0, Math.PI * 2);
96+ ctx.fillStyle = classColor(u.class);
97+ ctx.fill();
98+ ctx.lineWidth = 2;
99+ ctx.strokeStyle = '#14110e';
100+ ctx.stroke();
101+ drawText(ctx, u.class[0].toUpperCase(), fx, fy - d * 0.3, { size: d * 0.55, weight: 'bold', align: 'center', color: u.class === 'cleric' ? '#3a2e12' : '#fff' });
102+ ctx.fillStyle = '#14110e';
103+ ctx.beginPath();
104+ ctx.roundRect(fx + d / 2 - 8, fy + d / 2 - 9, 16, 12, 5);
105+ ctx.fill();
106+ drawText(ctx, String(u.level), fx + d / 2, fy + d / 2 - 9, { size: 10, align: 'center', color: GOLD, weight: 'bold' });
107+ const tx = x + 8 + d + 8;
108+ drawText(ctx, u.name, tx, 7, { size: small ? 11 : 13, weight: 'bold', maxW: x + cw - 6 - tx, fit: true, color: dead ? '#8a8a8a' : INK });
109+ drawText(ctx, u.class, tx, small ? 19 : 22, { size: small ? 9 : 10.5, color: '#b8a888', maxW: x + cw - 6 - tx });
110+ const by = h - (small ? 25 : 30);
111+ const bw = cw - 16;
112+ f.bar(ctx, x + 8, by, bw, small ? 11 : 13, Math.max(0, cur) / u.stats.maxHp, '#c43a2a');
113+ drawText(ctx, `${Math.max(0, cur)}/${u.stats.maxHp}`, x + cw / 2, by + (small ? 0 : 0.5), { size: small ? 9 : 10.5, align: 'center', weight: 'bold' });
114+ f.bar(ctx, x + 8, h - 11, bw, 4, Math.min(1, u.xp / (40 * u.level)), '#4a8ae0');
115+ if (dead) {
116+ ctx.fillStyle = '#000b';
117+ ctx.fillRect(x + 3, 3, cw - 6, h - 6);
118+ }
119+ wd.hit(x, 0, cw, h, { name: `portrait-${i}`, key: `portrait-${i}`, onClick: () => m.select(u.id) });
120+ if (wd.hovered(`portrait-${i}`) && !sel) {
121+ ctx.strokeStyle = '#ffe9a0';
122+ ctx.lineWidth = 1.5;
123+ ctx.strokeRect(x + 1.5, 1.5, cw - 3, h - 3);
124+ }
125+ });
126+ },
127+ });
128+
129+ const abilities = layer.add('abilities', {
130+ z: 2,
131+ draw(ctx, w, h) {
132+ const list = m.unit().abilities;
133+ const tw = Math.min(w / Math.max(1, list.length) - 4, 66);
134+ const small = h < 70;
135+ list.forEach((a, i) => {
136+ const x = i * (tw + 4);
137+ f.panel(ctx, x, 0, tw, h, 'slot');
138+ const is = small ? 26 : 40;
139+ f.icon(ctx, 'abilities', abilityIcon(a), x + (tw - is) / 2, small ? 4 : 7, is);
140+ drawText(ctx, String(i + 1), x + 6, 3, { size: 10, color: GOLD, weight: 'bold' });
141+ drawText(ctx, a.name, x + tw / 2, h - (small ? 15 : 22), { size: small ? 9 : 11, align: 'center', maxW: tw - 6, fit: true });
142+ if (a.cooldown) drawText(ctx, `cd${a.cooldown}`, x + tw - 4, 3, { size: 9, align: 'right', color: '#9ab' });
143+ });
144+ },
145+ });
146+
147+ const menu = layer.add('menu', {
148+ z: 2,
149+ draw(ctx, w, h, wd) {
150+ const wide = h > 60;
151+ const items = [['btn-inv', 'Inventory', 'I', 'inv'], ['btn-journal', 'Journal', 'J', 'journal']];
152+ items.forEach(([name, label, key, panel], i) => {
153+ const bw = wide ? w : (w - 6) / 2;
154+ const bh = wide ? (h - 8) / 2 : h;
155+ const x = wide ? 0 : i * (bw + 6);
156+ const y = wide ? i * (bh + 8) : 0;
157+ f.button(ctx, x, y, bw, bh, label, { hover: wd.hovered(name) || m.panel === panel, key: wide ? key : '', size: wide ? 14 : 13 });
158+ wd.hit(x, y, bw, bh, { name, key: name, onClick: () => m.togglePanel(panel) });
159+ });
160+ },
161+ });
162+
163+ const banner = layer.add('combat-banner', {
164+ z: 2,
165+ passive: true,
166+ draw(ctx, w, h) {
167+ f.panel(ctx, 0, 0, w, h, 'metalDark');
168+ ctx.fillStyle = '#7a1a1088';
169+ ctx.fillRect(5, 5, w - 10, h - 10);
170+ drawText(ctx, 'COMBAT', w / 2, (h - 22) / 2, { size: 20, weight: 'bold', align: 'center', color: '#ff7a5a' });
171+ },
172+ });
173+
174+ return { topbar, log, bottom, portraits, abilities, menu, banner };
175+}
web/js/icons.js+7-0
@@ -0,0 +1,7 @@
1+const ABILITY_ICON = { strike: 6, 'power-strike': 5, backstab: 8, firebolt: 0, fireball: 0, smite: 9, heal: 1, rally: 13, cleave: 12, 'venom-bite': 4, 'dark-bolt': 11, 'doom-wave': 11, 'war-cry': 13, mend: 1 };
2+const KIND_ICON = { damage: 6, magic: 2, aoe: 12, heal: 1, buff: 13 };
3+const SLOT_ICON = { weapon: 0, armor: 6, helm: 5, trinket: 9 };
4+
5+export const abilityIcon = (a) => ABILITY_ICON[a.id] ?? KIND_ICON[a.kind] ?? 3;
6+export const itemIcon = (it) => (it.key ? 12 : SLOT_ICON[it.slot] ?? 14);
7+export const slotIcon = (slot) => SLOT_ICON[slot] ?? 14;
web/js/inventory.js+114-0
@@ -0,0 +1,114 @@
1+import { drawText } from './text.js';
2+import { itemIcon, slotIcon } from './icons.js';
3+import { rarityColor } from './props.js';
4+import { chrome, INK, PAD } from './chrome.js';
5+
6+export const SLOTS = ['weapon', 'armor', 'helm', 'trinket'];
7+const STATS = [['maxHp', 'Health'], ['attack', 'Attack'], ['defense', 'Defense'], ['magic', 'Magic'], ['speed', 'Speed'], ['crit', 'Crit %']];
8+const CELL = { w: 66, h: 62, gap: 6 };
9+
10+export const bonusText = (b) => Object.entries(b || {}).filter(([, v]) => v).map(([k, v]) => `${v > 0 ? '+' : ''}${v} ${k}`).join(', ');
11+const describe = (it) => `${it.name} [${it.rarity}] ${bonusText(it.bonus) || 'no bonus'}`;
12+
13+export function createInventory(layer, m, f) {
14+ return layer.add('panel-inv', {
15+ z: 3,
16+ wheel(dy) {
17+ m.packRow = Math.max(0, Math.min(m.packMax || 0, m.packRow + (dy > 0 ? 1 : -1)));
18+ this.invalidate();
19+ },
20+ draw(ctx, w, h, wd) {
21+ chrome(ctx, w, h, 'Inventory', wd, f, m);
22+ const s = m.state;
23+ const u = m.unit();
24+ const two = w >= 560;
25+ const inner = w - PAD * 2;
26+ const tabW = (inner - 18) / 4;
27+ s.party.units.forEach((x, i) => {
28+ const tx = PAD + i * (tabW + 6);
29+ f.button(ctx, tx, 56, tabW, 26, x.name, { hover: wd.hovered(`tab-${i}`) || x.id === u.id, size: 13, primary: x.id === u.id });
30+ wd.hit(tx, 56, tabW, 26, { name: `tab-${i}`, key: `tab-${i}`, onClick: () => m.select(x.id) });
31+ });
32+ const leftW = two ? 240 : inner;
33+ const topY = 92;
34+ drawText(ctx, `${u.name} the ${u.class}, level ${u.level}`, PAD, topY, { size: 14, weight: 'bold', color: INK, shadow: null, maxW: leftW });
35+ const tips = {};
36+ const order = [];
37+ const sw = (leftW - 6) / 2;
38+ SLOTS.forEach((slot, i) => {
39+ const x = PAD + (i % 2) * (sw + 6);
40+ const y = topY + 22 + Math.floor(i / 2) * 48;
41+ const it = u.gear?.[slot];
42+ const key = `slot-${i}`;
43+ f.panel(ctx, x, y, sw, 44, 'slot');
44+ ctx.globalAlpha = it ? 1 : 0.3;
45+ f.icon(ctx, 'items', it ? itemIcon(it) : slotIcon(slot), x + 6, y + 6, 32);
46+ ctx.globalAlpha = 1;
47+ drawText(ctx, slot, x + 44, y + 6, { size: 10, color: '#b8a888', maxW: sw - 50 });
48+ drawText(ctx, it ? it.name : 'empty', x + 44, y + 22, { size: 12, color: it ? rarityColor(it.rarity) : '#8a7a5a', maxW: sw - 50, fit: true });
49+ tips[key] = it ? `${describe(it)} - click to unequip` : `${slot}: empty`;
50+ order[i] = key;
51+ if (it) wd.hit(x, y, sw, 44, { key, onClick: () => m.unequip(u.id, it.id) });
52+ if (wd.hovered(key) || (m.cursorOn && m.cursor === i)) {
53+ ctx.strokeStyle = '#ffe9a0';
54+ ctx.lineWidth = 2;
55+ ctx.strokeRect(x + 1, y + 1, sw - 2, 42);
56+ }
57+ });
58+ const statY = topY + 22 + 96 + 8;
59+ STATS.forEach(([k, label], i) => {
60+ const x = PAD + (i % 3) * (leftW / 3);
61+ const y = statY + Math.floor(i / 3) * 32;
62+ drawText(ctx, label, x, y, { size: 10.5, color: '#5a4a30', shadow: null });
63+ drawText(ctx, String(m.total(u, k)), x, y + 12, { size: 16, weight: 'bold', color: INK, shadow: null });
64+ });
65+
66+ const px = two ? PAD + leftW + 16 : PAD;
67+ const py = two ? topY : statY + 72;
68+ const pw = two ? w - PAD - px : inner;
69+ const inv = s.party.inventory;
70+ drawText(ctx, `Pack (${inv.length})`, px, py, { size: 14, weight: 'bold', color: INK, shadow: null });
71+ const gy = py + 22;
72+ const tipH = 32;
73+ const cols = Math.max(1, Math.floor((pw + CELL.gap) / (CELL.w + CELL.gap)));
74+ const rows = Math.max(1, Math.floor((h - PAD - tipH - gy + CELL.gap) / (CELL.h + CELL.gap)));
75+ const total = Math.ceil(inv.length / cols);
76+ m.packMax = Math.max(0, total - rows);
77+ m.packCols = cols;
78+ m.packRows = rows;
79+ m.packRow = Math.min(m.packRow, m.packMax);
80+ if (!inv.length) drawText(ctx, 'Nothing yet. Explore for loot.', px, gy + 6, { size: 13, color: '#5a4a30', shadow: null, maxW: pw });
81+ for (let r = 0; r < rows; r++) {
82+ for (let c = 0; c < cols; c++) {
83+ const idx = (m.packRow + r) * cols + c;
84+ const it = inv[idx];
85+ if (!it) continue;
86+ const x = px + c * (CELL.w + CELL.gap);
87+ const y = gy + r * (CELL.h + CELL.gap);
88+ const key = `item-${idx}`;
89+ f.panel(ctx, x, y, CELL.w, CELL.h, 'slot');
90+ f.icon(ctx, 'items', itemIcon(it), x + (CELL.w - 32) / 2, y + 4, 32);
91+ drawText(ctx, it.name, x + CELL.w / 2, y + 40, { size: 10, align: 'center', color: rarityColor(it.rarity), maxW: CELL.w - 6, fit: true });
92+ drawText(ctx, it.slot, x + CELL.w / 2, y + 50, { size: 8.5, align: 'center', color: '#8a7a5a', maxW: CELL.w - 6 });
93+ tips[key] = `${describe(it)} - click to equip`;
94+ wd.hit(x, y, CELL.w, CELL.h, { key, onClick: () => m.equip(u.id, it.id) });
95+ if (wd.hovered(key) || (m.cursorOn && m.cursor === 4 + idx)) {
96+ ctx.strokeStyle = '#ffe9a0';
97+ ctx.lineWidth = 2;
98+ ctx.strokeRect(x + 1, y + 1, CELL.w - 2, CELL.h - 2);
99+ }
100+ }
101+ }
102+ if (m.packMax > 0) {
103+ const th = rows * (CELL.h + CELL.gap) - CELL.gap;
104+ const x = px + pw - 4;
105+ ctx.fillStyle = '#5a4a3055';
106+ ctx.fillRect(x, gy, 4, th);
107+ ctx.fillStyle = '#5a3a18';
108+ ctx.fillRect(x, gy + (th * m.packRow) / total, 4, (th * rows) / total);
109+ }
110+ const key = wd.hoverKey() ?? (m.cursorOn ? (m.cursor < 4 ? `slot-${m.cursor}` : `item-${m.cursor - 4}`) : null);
111+ drawText(ctx, tips[key] || 'I or Esc closes. Arrows move, Enter equips, Tab switches hero.', PAD + 28, h - PAD - 14, { size: 12, color: '#3a2a14', shadow: null, maxW: inner - 28, fit: true });
112+ },
113+ });
114+}
web/js/journal.js+82-0
@@ -0,0 +1,82 @@
1+import { drawText, font, wrap, lineHeight } from './text.js';
2+import { chrome, INK, PAD } from './chrome.js';
3+
4+function blocks(c, hints) {
5+ const out = [];
6+ const head = (t, size = 15) => out.push({ t, size, weight: 'bold', color: INK, gap: 8 });
7+ const steps = (q) => q.steps.forEach((s) => out.push({ t: s.text, size: 13, color: s.done ? '#6a5a40' : INK, indent: 20, box: s.done ? 2 : 1 }));
8+ head(c.main.name, 17);
9+ steps(c.main);
10+ for (const q of c.sideQuests) {
11+ head(q.name);
12+ steps(q);
13+ }
14+ head('Factions');
15+ c.factions.forEach((x) => out.push({ t: `${x.name} (${x.theme}, power ${x.power})`, size: 13, color: INK, indent: 8 }));
16+ head('Rumours');
17+ hints.forEach((s) => out.push({ t: `${s.kind}: ${s.hint}`, size: 13, color: '#3a3a5a', indent: 8 }));
18+ if (c.systems.length) out.push({ t: c.systems.join(', '), size: 11, color: '#6a5a40', gap: 10 });
19+ return out;
20+}
21+
22+export function createJournal(layer, m, f) {
23+ return layer.add('panel-journal', {
24+ z: 3,
25+ wheel(dy) {
26+ m.scrollJournal(dy > 0 ? 44 : -44);
27+ },
28+ draw(ctx, w, h, wd) {
29+ chrome(ctx, w, h, 'Quest Journal', wd, f, m);
30+ const top = 58;
31+ const bottom = h - PAD + 4;
32+ const width = w - PAD * 2 - 12;
33+ const lines = [];
34+ for (const b of blocks(m.state.campaign, m.state.map.spawns)) {
35+ const ls = wrap(ctx, b.t, b.size, b.weight, width - (b.indent || 0));
36+ if (b.gap) lines.push({ gap: b.gap });
37+ ls.forEach((t, i) => lines.push({ t, b, first: i === 0 }));
38+ }
39+ const total = lines.reduce((n, l) => n + (l.gap ?? lineHeight(l.b.size)), 0);
40+ m.jMax = Math.max(0, total - (bottom - top));
41+ m.jScroll = Math.min(m.jScroll, m.jMax);
42+ ctx.save();
43+ ctx.beginPath();
44+ ctx.rect(PAD - 4, top, w - PAD * 2 + 8, bottom - top);
45+ ctx.clip();
46+ let y = top - m.jScroll;
47+ for (const l of lines) {
48+ if (l.gap) {
49+ y += l.gap;
50+ continue;
51+ }
52+ const { b } = l;
53+ const lh = lineHeight(b.size);
54+ if (l.first && b.box) {
55+ ctx.strokeStyle = INK;
56+ ctx.lineWidth = 1.5;
57+ ctx.strokeRect(PAD + 2, y + 2, 11, 11);
58+ if (b.box === 2) {
59+ ctx.beginPath();
60+ ctx.moveTo(PAD + 4, y + 8);
61+ ctx.lineTo(PAD + 7, y + 12);
62+ ctx.lineTo(PAD + 14, y);
63+ ctx.strokeStyle = '#2a7a2a';
64+ ctx.lineWidth = 2.5;
65+ ctx.stroke();
66+ }
67+ }
68+ ctx.font = font(b.size, b.weight);
69+ drawText(ctx, l.t, PAD + (b.indent || 0), y, { size: b.size, weight: b.weight, color: b.color, shadow: null });
70+ y += lh;
71+ }
72+ ctx.restore();
73+ if (m.jMax > 0) {
74+ const th = bottom - top;
75+ ctx.fillStyle = '#5a4a3055';
76+ ctx.fillRect(w - PAD - 2, top, 4, th);
77+ ctx.fillStyle = '#5a3a18';
78+ ctx.fillRect(w - PAD - 2, top + (th * m.jScroll) / total, 4, (th * th) / total);
79+ }
80+ },
81+ });
82+}
web/js/kit.js+131-0
@@ -0,0 +1,131 @@
1+import * as THREE from '../vendor/three.module.js';
2+
3+const MAX_PX = 4096;
4+
5+export function createLayer(renderer) {
6+ const scene = new THREE.Scene();
7+ const camera = new THREE.OrthographicCamera(0, 1, 1, 0, -10, 10);
8+ const widgets = [];
9+ const geometry = new THREE.PlaneGeometry(1, 1);
10+ const layer = { scene, camera, widgets, scale: 1, lw: 1, lh: 1, w: 1, h: 1, hover: null };
11+
12+ layer.add = (name, o) => {
13+ const mesh = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial({ transparent: true, depthTest: false, depthWrite: false, toneMapped: false }));
14+ mesh.visible = false;
15+ mesh.renderOrder = o.z ?? 0;
16+ scene.add(mesh);
17+ const wd = { name, essential: true, modal: false, lowres: false, ...o, mesh, rect: null, hits: [], dirty: true, px: '' };
18+ wd.hit = (x, y, w, h, extra) => wd.hits.push({ x, y, w, h, ...extra });
19+ wd.invalidate = () => (wd.dirty = true);
20+ wd.hoverKey = () => (layer.hover?.wd === wd ? layer.hover.key : null);
21+ wd.hovered = (key) => layer.hover?.wd === wd && layer.hover.key === key;
22+ widgets.push(wd);
23+ return wd;
24+ };
25+
26+ layer.resize = (w, h, scale) => {
27+ layer.w = w;
28+ layer.h = h;
29+ layer.scale = scale;
30+ layer.lw = w / scale;
31+ layer.lh = h / scale;
32+ camera.right = w;
33+ camera.top = h;
34+ camera.updateProjectionMatrix();
35+ for (const wd of widgets) wd.px = '';
36+ };
37+
38+ layer.place = (wd, rect) => {
39+ if (!rect) {
40+ wd.rect = null;
41+ wd.mesh.visible = false;
42+ return;
43+ }
44+ const prev = wd.rect;
45+ if (!prev || prev.w !== rect.w || prev.h !== rect.h) wd.dirty = true;
46+ wd.rect = rect;
47+ wd.mesh.visible = true;
48+ const s = layer.scale;
49+ wd.mesh.scale.set(rect.w * s, rect.h * s, 1);
50+ wd.mesh.position.set((rect.x + rect.w / 2) * s, layer.h - (rect.y + rect.h / 2) * s, 0);
51+ };
52+
53+ function paint(wd) {
54+ const k = wd.lowres ? 0.05 : Math.min(layer.scale * renderer.getPixelRatio(), MAX_PX / Math.max(wd.rect.w, wd.rect.h));
55+ const pw = Math.max(1, Math.ceil(wd.rect.w * k));
56+ const ph = Math.max(1, Math.ceil(wd.rect.h * k));
57+ const sig = `${pw}x${ph}`;
58+ if (sig !== wd.px) {
59+ wd.px = sig;
60+ wd.mesh.material.map?.dispose();
61+ const t = new THREE.CanvasTexture(new OffscreenCanvas(pw, ph));
62+ t.colorSpace = THREE.SRGBColorSpace;
63+ t.generateMipmaps = false;
64+ t.minFilter = THREE.LinearFilter;
65+ wd.mesh.material.map = t;
66+ wd.mesh.material.needsUpdate = true;
67+ }
68+ const t = wd.mesh.material.map;
69+ const ctx = t.image.getContext('2d');
70+ ctx.setTransform(1, 0, 0, 1, 0, 0);
71+ ctx.clearRect(0, 0, pw, ph);
72+ ctx.setTransform(pw / wd.rect.w, 0, 0, ph / wd.rect.h, 0, 0);
73+ wd.hits = [];
74+ wd.draw(ctx, wd.rect.w, wd.rect.h, wd);
75+ t.needsUpdate = true;
76+ wd.dirty = false;
77+ }
78+
79+ layer.update = () => {
80+ for (const wd of widgets) if (wd.rect && (wd.dirty || wd.px === '')) paint(wd);
81+ };
82+
83+ layer.render = () => {
84+ renderer.clearDepth();
85+ renderer.render(scene, camera);
86+ };
87+
88+ layer.pick = (cx, cy) => {
89+ const x = cx / layer.scale;
90+ const y = cy / layer.scale;
91+ let best = null;
92+ for (const wd of widgets) {
93+ const r = wd.rect;
94+ if (!r || !(x >= r.x && y >= r.y && x < r.x + r.w && y < r.y + r.h)) continue;
95+ if (wd.passive) continue;
96+ if (!best || (wd.z ?? 0) >= (best.z ?? 0)) best = wd;
97+ }
98+ if (!best) {
99+ const modal = widgets.find((q) => q.rect && q.modal);
100+ return modal ? { widget: modal, hit: null, x: 0, y: 0 } : null;
101+ }
102+ const lx = x - best.rect.x;
103+ const ly = y - best.rect.y;
104+ let hit = null;
105+ for (const h of best.hits) if (lx >= h.x && ly >= h.y && lx < h.x + h.w && ly < h.y + h.h) hit = h;
106+ return { widget: best, hit, x: lx, y: ly };
107+ };
108+
109+ layer.setHover = (p) => {
110+ const key = p?.hit?.key ?? null;
111+ const wd = key == null ? null : p.widget;
112+ if (layer.hover?.wd === wd && layer.hover?.key === key) return;
113+ layer.hover?.wd?.invalidate();
114+ layer.hover = wd ? { wd, key } : null;
115+ wd?.invalidate();
116+ };
117+
118+ layer.rects = () => {
119+ const s = layer.scale;
120+ const out = [];
121+ for (const wd of widgets) {
122+ if (!wd.rect) continue;
123+ const r = wd.rect;
124+ out.push({ name: wd.name, x: r.x * s, y: r.y * s, w: r.w * s, h: r.h * s, essential: wd.essential });
125+ for (const h of wd.hits) if (h.name) out.push({ name: h.name, x: (r.x + h.x) * s, y: (r.y + h.y) * s, w: h.w * s, h: h.h * s, essential: h.essential ?? true });
126+ }
127+ return out;
128+ };
129+
130+ return layer;
131+}
web/js/layout.js+49-0
@@ -0,0 +1,49 @@
1+const TOP = 44;
2+const PORTRAIT_GAP = 8;
3+
4+export function uiScale(w, h) {
5+ if (w < 640) return Math.min(1.4, Math.max(0.8, w / 440));
6+ return Math.min(2.5, Math.max(0.85, Math.min(w / 1000, h / 620)));
7+}
8+
9+export function layoutFor(lw, lh, m) {
10+ const out = {};
11+ const pad = 8;
12+ const abilityN = m.abilityCount || 3;
13+ const wideNeed = 10 + 4 * 124 + 3 * PORTRAIT_GAP + 16 + abilityN * 70 + 16 + 116 + 10;
14+ const wide = wideNeed <= lw;
15+ out.wide = wide;
16+ out.scrim = m.screen ? { x: 0, y: 0, w: lw, h: lh } : null;
17+ const cw = Math.min(lw - 2 * pad, 520);
18+ const ch = Math.min(lh - 2 * pad, cw < 470 ? 440 : m.screen === 'end' ? 420 : 370);
19+ out.card = m.screen ? { x: (lw - cw) / 2, y: (lh - ch) / 2, w: cw, h: ch } : null;
20+ if (!m.hud) return { ...out, topbar: null, log: null, bottom: null, portraits: null, abilities: null, menu: null, banner: null, inv: null, journal: null };
21+
22+ const tw = Math.min(lw - 2 * pad, 560);
23+ out.topbar = { x: (lw - tw) / 2, y: 6, w: tw, h: 32 };
24+ const bh = wide ? 100 : 140;
25+ out.bottom = { x: 0, y: lh - bh, w: lw, h: bh };
26+ if (wide) {
27+ const pw = 4 * 124 + 3 * PORTRAIT_GAP;
28+ out.portraits = { x: 10, y: lh - bh + 8, w: pw, h: 84 };
29+ const aw = abilityN * 70;
30+ out.abilities = { x: 10 + pw + 16, y: lh - bh + 10, w: aw, h: 80 };
31+ out.menu = { x: lw - 126, y: lh - bh + 8, w: 116, h: 84 };
32+ } else {
33+ out.abilities = { x: pad, y: lh - bh + 8, w: Math.min(abilityN * 60, lw - 2 * pad - 180), h: 56 };
34+ out.menu = { x: lw - pad - 172, y: lh - bh + 10, w: 172, h: 48 };
35+ out.portraits = { x: pad, y: lh - bh + 72, w: lw - 2 * pad, h: 60 };
36+ }
37+ const avail = lh - bh - TOP - pad;
38+ const pw = Math.min(lw - 2 * pad, 640);
39+ const ph = Math.min(avail, wide ? 500 : 640);
40+ const panel = { x: (lw - pw) / 2, y: TOP + (avail - ph) / 2, w: pw, h: ph };
41+ out.inv = m.panel === 'inv' ? panel : null;
42+ out.journal = m.panel === 'journal' ? panel : null;
43+ const logW = Math.min(wide ? 380 : lw - 2 * pad, lw * (wide ? 0.4 : 1));
44+ const lines = Math.min(m.logRowsFor(logW), wide ? 6 : 4);
45+ const logH = lines * 17 + 12;
46+ out.log = m.panel || !lines ? null : { x: pad, y: lh - bh - pad - logH, w: logW, h: logH };
47+ out.banner = m.combat ? { x: (lw - 240) / 2, y: TOP, w: 240, h: 34 } : null;
48+ return out;
49+}
web/js/main.js+18-7
@@ -6,7 +6,6 @@ import { createParty } from './party.js';
66 import { createCamera } from './camera.js';
77 import { createCombat } from './combat.js';
88 import { createUI } from './ui.js';
9-import { showTitle, showEnd } from './screens.js';
109 import { mat } from './props.js';
1110 import { installDebug, track } from './debug.js';
1211
@@ -15,6 +14,7 @@ const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
1514 renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
1615 renderer.shadowMap.enabled = true;
1716 renderer.shadowMap.type = THREE.PCFSoftShadowMap;
17+renderer.autoClear = false;
1818 renderer.toneMapping = THREE.ACESFilmicToneMapping;
1919 renderer.toneMappingExposure = 1.5;
2020
@@ -36,7 +36,7 @@ marker.rotation.x = Math.PI / 2;
3636 marker.visible = false;
3737 scene.add(marker);
3838
39-const ui = createUI({
39+const ui = await createUI(renderer, canvas, {
4040 onEquip: (unit, item) => mutate(() => api.equip(unit, item)),
4141 onUnequip: (unit, item) => mutate(() => api.equip(unit, item, true)),
4242 });
@@ -58,8 +58,10 @@ async function mutate(fn) {
5858 }
5959
6060 function resize() {
61+ renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
6162 renderer.setSize(innerWidth, innerHeight);
6263 cam.resize(innerWidth, innerHeight);
64+ ui.resize(innerWidth, innerHeight);
6365 }
6466 addEventListener('resize', resize);
6567 resize();
@@ -103,6 +105,10 @@ canvas.addEventListener('pointerup', (e) => {
103105 });
104106 canvas.addEventListener('pointermove', (e) => {
105107 if (!world || busy) return;
108+ if (ui.over(e.clientX, e.clientY)) {
109+ marker.visible = false;
110+ return;
111+ }
106112 const t = world.pick(ndc(e), cam.camera);
107113 marker.visible = !!t && state.map.tiles[t.y][t.x].walkable;
108114 if (t) marker.position.copy(world.worldPos(t.x, t.y)).setY(world.worldPos(t.x, t.y).y + 0.06);
@@ -164,12 +170,12 @@ async function restart() {
164170 load(s);
165171 ui.show(false);
166172 track.mode = 'title';
167- showTitle(s, { onStart: begin, onNew: restart });
173+ ui.showTitle(s, { onStart: begin, onNew: restart });
168174 }
169175
170176 function endGame(s) {
171177 track.mode = 'end';
172- showEnd(s, restart);
178+ ui.showEnd(s, restart);
173179 }
174180
175181 function begin() {
@@ -193,7 +199,10 @@ function frame() {
193199 }
194200 combat.update(dt);
195201 cam.update(dt);
202+ renderer.clear();
196203 renderer.render(scene, cam.camera);
204+ ui.tick(dt);
205+ ui.draw();
197206 requestAnimationFrame(frame);
198207 }
199208
@@ -202,13 +211,15 @@ async function boot() {
202211 load(await api.getState());
203212 frame();
204213 installDebug({ THREE, getState: () => state, getWorld: () => world, cam, party });
214+ window.__game.setRects(ui.rects);
205215 if (state.winner || state.phase === 'victory') return endGame(state);
206216 track.mode = 'title';
207- showTitle(state, { onStart: begin, onNew: restart });
217+ ui.showTitle(state, { onStart: begin, onNew: restart });
208218 }
209219
210220 boot().catch((e) => {
211221 console.error(e);
212- document.getElementById('screen').innerHTML = `<div class="card"><h1>Tiny Adventure</h1><p>${e.message}</p></div>`;
213- document.getElementById('screen').hidden = false;
222+ const fatal = document.getElementById('fatal');
223+ fatal.textContent = `Tiny Adventure failed to start: ${e.message}`;
224+ fatal.hidden = false;
214225 });
web/js/props.js+1-3
@@ -30,9 +30,7 @@ export function hashColor(id) {
3030 }
3131
3232 export function label(text, color = '#f4e6c0') {
33- const c = document.createElement('canvas');
34- c.width = 512;
35- c.height = 96;

Cut short: this commit's diff is over 1000 lines.

web/js/screens.js+71-32

Cut short: this commit's diff is over 1000 lines.

web/js/text.js+79-0

Cut short: this commit's diff is over 1000 lines.

web/js/textures.js+1-2

Cut short: this commit's diff is over 1000 lines.

web/js/ui.js+210-103

Cut short: this commit's diff is over 1000 lines.