tiny-adventure / commits / 959ee7d
Live hero medallions, turn-by-turn combat, level-ups, route preview and gear comparison
Hero cards show a live render of each hero's own mini in a medallion, with level, stats, HP and XP. In combat only the acting figure winds up and lunges, the hit lands on impact, and Space or a click speeds it up. A level-up makes the hero hop and glow, and the gains rise above their card. Hovering a hex draws the server's route with its length and a warning when night falls on the way. Walking goes one hex per request, so a new click changes course and Esc stops. The inventory and the trader compare every item with the selected hero's gear, and the top bar counts keys. Verified headless: verify.sh with 0 failures at 6 resolutions, and a seed 7 playthrough won on day 12. Co-Authored-By: Claude Opus 5.5
@@ -36,14 +36,15 @@ Beating the boss ends the campaign with a victory screen. If the whole party fal
3636
3737 ## Playing
3838
39-- Click a hex to walk there. Roads are fast, hills, shallows and forest are slow. Right-drag or Q/E rotates, the wheel zooms.
39+- Click a hex to walk there. Roads are fast, hills, shallows and forest are slow. Hovering a hex marks the route and its length, and warns when night would fall on the way. Click another hex while walking to change course, or Esc or a click on the party to stop. Right-drag or Q/E rotates, the wheel zooms.
4040 - The next main objective is always marked with a light beam and labelled with its level (`Lv N`), even in the fog. J opens the journal, which marks the next step.
4141 - Walking toward a place that is still held stops you next to it and shows its defenders, your chance to win, and how much health the fight should cost. Fight (Enter) or back off (Esc).
42-- Every hex walked spends daylight, and fights take time too. After dusk, make camp (C) once to heal everyone and start a new day, away from enemies. Wounds carry until then. Shallows, mountains and harsh biomes wear the party down as it walks. P drinks a potion on the selected hero.
42+- Every hex walked spends daylight, and fights take time too. A day is long enough for several fights, so wounds pile up and potions carry you between camps. After dusk, make camp (C) once to heal everyone and start a new day, away from enemies. Shallows, mountains and harsh biomes wear the party down as it walks. P drinks a potion on the selected hero.
4343 - Traders (T) work at the spawns and at camps and villages you cleared. They sell potions and gear.
4444 - Roaming bands chase a party that comes near, from farther away at night. Backing off from a band shakes it off for a few moves. Some chests are guarded, trapped, or mimics. Lookouts reveal the land, shrines heal, and old caches grant XP.
45-- Walking over loot picks it up. Items may carry a trait, such as fire, lifesteal or taunt, paid for with a lower stat. Enemies show their traits, weaknesses and resistances on the threat card. Prepare (G) opens the inventory with live odds, so you can gear for the fight in front of you.
46-- A lost fight ends the campaign.
45+- The main quest asks you to recover keys from the places it names. The top bar counts them, and the boss stays sealed until you hold them all.
46+- Walking over loot picks it up. Each base item has its own stats: daggers trade attack for speed and crit, plate trades speed for defense. The inventory and the trader compare every item with the selected hero's gear. Items may carry a trait, such as fire, lifesteal or taunt, paid for with a lower stat. Enemies show their traits, weaknesses and resistances on the threat card. Prepare (G) opens the inventory with live odds, so you can gear for the fight in front of you.
47+- Fights play out one turn at a time. Space or a click speeds them up. Heroes who level up hop on the board, and their gains rise above their cards. A lost fight ends the campaign.
4748 - M toggles sound.
4849
4950 ## Check
@@ -13,6 +13,7 @@ function normalize(s) {
1313 const arr = (o, k) => (o[k] ||= []);
1414 arr(s, 'log');
1515 arr(s.party, 'inventory');
16+ arr(s.party, 'keys');
1617 arr(s.campaign, 'sideQuests');
1718 arr(s.campaign, 'factions');
1819 arr(s.campaign, 'systems');
@@ -26,7 +27,8 @@ function normalize(s) {
2627
2728 export const getState = () => call('GET', '/api/state');
2829 export const newGame = (seed) => call('POST', '/api/new', seed ? { seed } : {});
29-export const move = (x, y) => call('POST', '/api/move', { x, y });
30+export const move = (x, y, steps = 0) => call('POST', '/api/move', { x, y, steps });
31+export const path = (x, y) => call('GET', `/api/path?x=${x}&y=${y}`);
3032 export const interact = (id) => call('POST', '/api/interact', { id });
3133 export const equip = (unit, item, unequip = false) => call('POST', '/api/equip', { unit, item, unequip });
3234 export const rest = () => call('POST', '/api/rest', {});
@@ -107,5 +107,7 @@ export function createBeast(kind, seed) {
107107 beast.wings?.forEach((w, i) => (w.rotation.z = (i ? 1 : -1) * (0.35 + (0.15 + 0.5 * fight + (beast.hover ? 0.5 : 0)) * Math.sin(clock * (1.5 + 6 * fight + (beast.hover ? 10 : 0))))));
108108 }
109109
110- return { object, animate, get strike() { return strike * weights.fight; }, radius: 0.35 * look.scale };
110+ const swing = () => (clock = 0);
111+
112+ return { object, head: beast.head, animate, swing, get strike() { return strike * weights.fight; }, radius: 0.35 * look.scale };
111113 }
@@ -79,5 +79,12 @@ export function createCamera(canvas) {
7979 goal.copy(pos);
8080 }
8181
82- return { camera, resize, follow, setFocus, update, snap, shake, orbit };
82+ function screenOf(obj, lift = 1.5) {
83+ const v = obj.position.clone();
84+ v.y += lift * obj.scale.y;
85+ v.project(camera);
86+ return [(v.x * 0.5 + 0.5) * innerWidth, (-v.y * 0.5 + 0.5) * innerHeight];
87+ }
88+
89+ return { camera, resize, follow, setFocus, update, snap, shake, orbit, screenOf };
8390 }
@@ -1,6 +1,6 @@
11 import * as THREE from '../vendor/three.module.js';
22 import { part } from './props.js';
3-import { createMini } from './minis.js';
3+import { createMini, flash } from './minis.js';
44 import { maxHp } from './stats.js';
55 import { T } from './theme.js';
66
@@ -10,6 +10,8 @@ export function createCombat(scene, party, cam, ui, sound) {
1010 const anims = [];
1111 const bars = [];
1212 let enemies = [];
13+ let fast = false;
14+ const hp = new Map();
1315
1416 const tween = (dur, fn) => anims.push({ t: 0, dur, fn });
1517
@@ -53,30 +55,34 @@ export function createCombat(scene, party, cam, ui, sound) {
5355 tween(dur, (p) => fig.position.copy(home).addScaledVector(dir, Math.sin(p * Math.PI)));
5456 }
5557
56- function flash(fig, color = '#ff3020') {
57- const meshes = [];
58- fig.traverse((o) => o.isMesh && o.material.emissive && meshes.push(o));
59- meshes.forEach((o) => {
60- o.userData.paint ||= o.material;
61- const c = o.userData.paint.clone();
62- c.emissive = new THREE.Color(color);
63- c.emissiveIntensity = 1.2;
64- o.material = c;
65- });
66- clearTimeout(fig.userData.flash);
67- fig.userData.flash = setTimeout(() => meshes.forEach((o) => (o.material = o.userData.paint)), 160);
68- }
69-
7058 function squash(fig) {
7159 const body = fig.userData.body;
7260 tween(0.18, (p) => body.scale.set(1 + Math.sin(p * Math.PI) * 0.18, 1 - Math.sin(p * Math.PI) * 0.22, 1 + Math.sin(p * Math.PI) * 0.18));
7361 }
7462
75- function screenOf(fig) {
76- const v = fig.position.clone();
77- v.y += 1.5 * fig.scale.y;
78- v.project(cam.camera);
79- return [(v.x * 0.5 + 0.5) * innerWidth, (-v.y * 0.5 + 0.5) * innerHeight];
63+ function strike(ev, t, ab, heal) {
64+ const cur = hp.get(ev.target) ?? 0;
65+ const next = heal ? Math.min(t.max, cur + ev.amount) : Math.max(0, cur - ev.amount);
66+ hp.set(ev.target, next);
67+ if (!t.ally) setBar(t.bar, next / t.max);
68+ if (!heal && ev.amount > 0) {
69+ flash(t.fig);
70+ squash(t.fig);
71+ sound.play(ev.crit ? 'crit' : 'hit');
72+ if (ev.crit) cam.shake(0.5);
73+ } else if (heal) {
74+ flash(t.fig, T.heal);
75+ sound.play('heal');
76+ }
77+ const [sx, sy] = cam.screenOf(t.fig);
78+ ui.floater(sx, sy, heal ? `+${ev.amount}` : ev.amount > 0 ? `${ev.amount}${ev.crit ? '!' : ''}` : ab ? ab.name : '', heal ? 'heal' : ev.crit ? 'crit' : t.ally ? 'hurt' : 'dmg');
79+ if (ev.killed) {
80+ sound.play('fall');
81+ cam.shake(0.35);
82+ const f = t.fig;
83+ if (t.ally) tween(0.4, (p) => (f.rotation.z = (p * Math.PI) / 2));
84+ else tween(0.5, (p) => (f.scale.setScalar(Math.max(0.01, (1 - p) * f.userData.size)), (f.position.y = t.home.y - p * 0.3)));
85+ }
8086 }
8187
8288 async function play(state, before) {
@@ -87,7 +93,7 @@ export function createCombat(scene, party, cam, ui, sound) {
8793 const foes = spawnEnemies(enc);
8894 enemies = foes;
8995 const ids = new Map();
90- const hp = new Map();
96+ hp.clear();
9197 const abilities = new Map();
9298 foes.forEach((f) => {
9399 ids.set(f.unit.id, f);
@@ -102,53 +108,41 @@ export function createCombat(scene, party, cam, ui, sound) {
102108 hp.set(u.id, p.stats.hp);
103109 u.abilities.forEach((a) => abilities.set(a.id, a));
104110 });
105- for (const f of party.figures.values()) f.rotation.y = Math.PI / 2;
106- party.setPose('fight');
111+ for (const f of party.figures.values()) {
112+ f.rotation.y = Math.PI / 2;
113+ f.userData.mode = 'idle';
114+ }
107115 const mid = party.pos.clone();
108116 mid.x += 1.6;
109117 cam.setFocus(mid, 10);
110118 ui.render(before, hp);
111119 ui.logLine(`${enc.boss ? 'Boss fight' : 'Fight'}: ${foes.map((f) => f.unit.name).join(', ')}`, 'head');
112- await sleep(900);
120+ ui.logLine('Space or a click speeds up the fight.', 'hint');
121+ fast = false;
122+ await sleep(700);
113123
114- const delay = THREE.MathUtils.clamp(9000 / Math.max(log.length, 1), 160, 520);
124+ const base = THREE.MathUtils.clamp(24000 / Math.max(log.length, 1), 450, 800);
115125 for (const ev of log) {
126+ const turn = fast ? 220 : base;
116127 const a = ids.get(ev.actor);
117128 const t = ids.get(ev.target);
118129 const ab = abilities.get(ev.ability);
119- if (a && t && a !== t) lunge(a.fig, t.fig.position, delay / 1000 * 0.8);
120130 const heal = ab && ab.kind === 'heal';
121- if (t) {
122- const cur = hp.get(ev.target) ?? 0;
123- const next = heal ? Math.min(t.max, cur + ev.amount) : Math.max(0, cur - ev.amount);
124- hp.set(ev.target, next);
125- if (!t.ally) setBar(t.bar, next / t.max);
126- if (!heal && ev.amount > 0) {
127- flash(t.fig);
128- squash(t.fig);
129- sound.play(ev.crit ? 'crit' : 'hit');
130- if (ev.crit) cam.shake(0.5);
131- } else if (heal) {
132- flash(t.fig, T.heal);
133- sound.play('heal');
134- }
135- const [sx, sy] = screenOf(t.fig);
136- ui.floater(sx, sy, heal ? `+${ev.amount}` : ev.amount > 0 ? `${ev.amount}${ev.crit ? '!' : ''}` : ab ? ab.name : '', heal ? 'heal' : ev.crit ? 'crit' : t.ally ? 'hurt' : 'dmg');
137- if (ev.killed) {
138- sound.play('fall');
139- cam.shake(0.35);
140- const f = t.fig;
141- if (t.ally) tween(0.4, (p) => (f.rotation.z = p * Math.PI / 2));
142- else tween(0.5, (p) => (f.scale.setScalar(Math.max(0.01, (1 - p) * (t.fig.userData.size))), (f.position.y = t.home.y - p * 0.3)));
143- }
131+ if (a) {
132+ a.fig.userData.mode = heal ? 'cast' : 'fight';
133+ a.fig.userData.swing?.();
134+ if (t && a !== t && !heal) lunge(a.fig, t.fig.position, (turn / 1000) * 0.9);
144135 }
136+ await sleep(turn * 0.45);
137+ if (t) strike(ev, t, ab, heal);
145138 ui.logLine(ev.text, ev.killed ? 'kill' : ev.crit ? 'crit' : '');
146139 ui.render(before, hp);
147- await sleep(delay);
140+ await sleep(turn * 0.55);
141+ if (a) a.fig.userData.mode = 'idle';
148142 }
149143 await sleep(500);
150144 for (const u of state.party.units) party.figures.get(u.id).rotation.z = 0;
151- party.setPose(null);
145+ for (const f of party.figures.values()) f.userData.mode = null;
152146 for (const f of foes) scene.remove(f.fig);
153147 bars.length = 0;
154148 enemies = [];
@@ -157,7 +151,7 @@ export function createCombat(scene, party, cam, ui, sound) {
157151 }
158152
159153 function update(dt) {
160- for (const e of enemies) e.fig.userData.animate('fight', dt);
154+ for (const e of enemies) e.fig.userData.animate(e.fig.userData.mode || 'idle', dt);
161155 for (let i = anims.length - 1; i >= 0; i--) {
162156 const a = anims[i];
163157 a.t += dt;
@@ -168,5 +162,5 @@ export function createCombat(scene, party, cam, ui, sound) {
168162 for (const b of bars) b.quaternion.copy(b.parent.quaternion).invert().multiply(cam.camera.quaternion);
169163 }
170164
171- return { play, update };
165+ return { play, update, hurry: () => (fast = true) };
172166 }
@@ -202,5 +202,7 @@ export function createFigure(raceName, kind, seed, accent) {
202202 head.rotation.y = turn;
203203 }
204204
205- return { object: root, animate, get strike() { return strike; }, radius: 0.3 * Math.sqrt(race.width) };
205+ const swing = () => (clock = ranged ? CAST_SECONDS * 0.05 : 0);
206+
207+ return { object: root, head, animate, swing, get strike() { return strike; }, radius: 0.3 * Math.sqrt(race.width) };
206208 }
@@ -2,8 +2,8 @@ import * as THREE from '../vendor/three.module.js';
22 import { labelTexture } from './text.js';
33 import { T } from './theme.js';
44
5-const COLORS = { dmg: T.fg, crit: T.accent, hurt: T.danger, heal: T.heal, info: T.muted };
6-const SIZE = { dmg: 26, crit: 38, hurt: 26, heal: 26, info: 20 };
5+const COLORS = { dmg: T.fg, crit: T.accent, hurt: T.danger, heal: T.heal, info: T.muted, level: T.accent, gain: T.fg };
6+const SIZE = { dmg: 26, crit: 38, hurt: 26, heal: 26, info: 20, level: 26, gain: 17 };
77 const LIFE = 1.3;
88
99 export function createFloaters(layer) {
@@ -17,7 +17,8 @@ export function createFloaters(layer) {
1717 const hgt = SIZE[cls] * 1.5 * layer.scale;
1818 sprite.scale.set(hgt * lab.aspect, hgt, 1);
1919 sprite.renderOrder = 20;
20- live.push({ sprite, x: x + ((count++ % 3) - 1) * 22 * layer.scale, y, t: 0, rise: 56 * layer.scale });
20+ const spread = cls === 'level' || cls === 'gain' ? 0 : ((count++ % 3) - 1) * 22;
21+ live.push({ sprite, x: x + spread * layer.scale, y, t: 0, rise: 56 * layer.scale });
2122 layer.scene.add(sprite);
2223 }
2324
@@ -1,8 +1,8 @@
11 import { bearing } from './compass.js';
22 import { drawText, wrap } from './text.js';
3-import { classColor } from './paint.js';
4-import { maxHp } from './stats.js';
3+import { maxHp, total } from './stats.js';
54 import { T } from './theme.js';
5+import { LIP } from './layout.js';
66
77 const LOG_COLORS = { head: T.fg, crit: T.accent, kill: T.danger, reward: T.heal, hint: T.muted };
88 const LOG_SIZE = 12.5;
@@ -42,6 +42,18 @@ function dial(ctx, x, y, clock) {
4242 }
4343 }
4444
45+function keyIcon(ctx, x, y, color) {
46+ ctx.strokeStyle = color;
47+ ctx.lineWidth = 2;
48+ ctx.beginPath();
49+ ctx.arc(x - 3, y, 3.5, 0, Math.PI * 2);
50+ ctx.moveTo(x + 0.5, y);
51+ ctx.lineTo(x + 8, y);
52+ ctx.moveTo(x + 6, y);
53+ ctx.lineTo(x + 6, y + 3.5);
54+ ctx.stroke();
55+}
56+
4557 function coin(ctx, x, y) {
4658 ctx.fillStyle = T.muted;
4759 ctx.beginPath();
@@ -66,11 +78,18 @@ export function createHud(layer, m, f) {
6678 ctx.lineTo(9, h / 2);
6779 ctx.fill();
6880 const purse = 112;
69- const time = 104;
81+ const want = s.campaign.main.steps.filter((q) => q.slots.item).length;
82+ const keys = want ? 62 : 0;
83+ const time = 104 + keys;
7084 const night = s.clock.time >= s.clock.dayLength;
7185 drawText(ctx, text, 28, 0, { h, size: 14, color: m.toast ? T.accent : T.fg, maxW: w - 28 - purse - time - 8, fit: true });
7286 drawText(ctx, `Day ${s.clock.day}`, w - purse - time + 6, 0, { h, size: 14, weight: 'bold', color: night ? T.accent : T.fg });
73- dial(ctx, w - purse - 44, h / 2, s.clock);
87+ dial(ctx, w - purse - keys - 44, h / 2, s.clock);
88+ if (want) {
89+ const kx = w - purse - keys + 2;
90+ keyIcon(ctx, kx + 4, h / 2, s.party.keys.length === want ? T.accent : T.muted);
91+ drawText(ctx, `${s.party.keys.length}/${want}`, kx + 16, 0, { h, size: 14, weight: 'bold', color: s.party.keys.length === want ? T.accent : T.fg });
92+ }
7493 coin(ctx, w - purse + 8, h / 2);
7594 drawText(ctx, String(s.party.gold), w - purse + 18, 0, { h, size: 14, weight: 'bold' });
7695 potion(ctx, w - 40, h / 2, T.muted);
@@ -94,9 +113,9 @@ export function createHud(layer, m, f) {
94113 z: 1,
95114 draw(ctx, w, h) {
96115 ctx.fillStyle = T.bg;
97- ctx.fillRect(0, 0, w, h);
116+ ctx.fillRect(0, LIP, w, h - LIP);
98117 ctx.fillStyle = T.line;
99- ctx.fillRect(0, 0, w, 1);
118+ ctx.fillRect(0, LIP, w, 1);
100119 },
101120 });
102121
@@ -106,29 +125,27 @@ export function createHud(layer, m, f) {
106125 const units = m.state.party.units;
107126 const gap = 8;
108127 const cw = (w - gap * 3) / 4;
109- const small = cw < 110;
128+ const small = cw < 120;
129+ const top = small ? 8 : 14;
130+ const d = small ? 38 : 56;
131+ wd.spots = [];
110132 units.forEach((u, i) => {
111133 const x = i * (cw + gap);
112134 const max = maxHp(u);
113135 const cur = Math.max(0, m.hp ? m.hp.get(u.id) ?? u.stats.hp : u.stats.hp);
114136 const sel = u.id === m.selected;
115137 const hov = wd.hovered(`portrait-${i}`);
116- f.panel(ctx, x, 0, cw, h, sel ? 'raised' : 'surface', sel ? T.accent : hov ? T.muted : T.line);
117- const d = small ? 22 : 30;
118- const fx = x + 8 + d / 2;
119- const fy = 8 + d / 2;
120- ctx.beginPath();
121- ctx.arc(fx, fy, d / 2, 0, Math.PI * 2);
122- ctx.fillStyle = classColor(u.class);
123- ctx.fill();
124- drawText(ctx, String(u.level), fx, 8, { h: d, size: d * 0.5, weight: 'bold', align: 'center', color: u.class === 'cleric' ? T.accentFg : T.fg });
125- const tx = x + 8 + d + 8;
126- drawText(ctx, u.name, tx, 8, { h: d / 2, size: small ? 11 : 13.5, weight: 'bold', maxW: x + cw - 6 - tx, fit: true, color: cur ? T.fg : T.faint });
127- drawText(ctx, u.class, tx, 8 + d / 2, { h: d / 2, size: small ? 9.5 : 11, color: T.muted, maxW: x + cw - 6 - tx });
138+ const low = cur / max < 0.35;
139+ f.panel(ctx, x, top, cw, h - top, sel ? 'raised' : 'surface', sel ? T.accent : hov ? T.muted : T.line);
140+ wd.spots.push({ id: u.id, cx: x + 6 + d / 2, cy: d / 2, d, down: !cur, rim: sel ? T.accent : low ? T.danger : hov ? T.muted : T.line });
141+ const tx = x + 6 + d + 6;
142+ const tw = x + cw - 6 - tx;
143+ drawText(ctx, u.name, tx, top + 3, { h: small ? 15 : 18, size: small ? 11.5 : 14, weight: 'bold', maxW: tw, fit: true, color: cur ? T.fg : T.faint });
144+ drawText(ctx, `Lv ${u.level} ${u.class}`, tx, top + (small ? 18 : 21), { h: small ? 13 : 16, size: small ? 9.5 : 11.5, color: T.muted, maxW: tw, fit: true });
145+ if (!small) drawText(ctx, `${total(u, 'attack')} atk ${total(u, 'defense')} def ${total(u, 'magic')} mag`, x + 8, d + 1, { h: 16, size: 11, color: T.faint, maxW: cw - 16, fit: true });
128146 const bh = small ? 12 : 14;
129147 const by = h - 10 - bh;
130148 const bw = cw - 16;
131- const low = cur / max < 0.35;
132149 f.bar(ctx, x + 8, by, bw, bh, cur / max, low ? T.danger : T.muted);
133150 const split = x + 8 + bw * Math.min(1, cur / max);
134151 [[x, split - x, low ? T.fg : T.bg], [split, x + cw - split, T.fg]].forEach(([cx, cw2, color]) => {
@@ -139,7 +156,7 @@ export function createHud(layer, m, f) {
139156 drawText(ctx, `${cur}/${max}`, x + cw / 2, by, { h: bh, size: small ? 10 : 11, align: 'center', weight: 'bold', color });
140157 ctx.restore();
141158 });
142- f.bar(ctx, x + 8, h - 8, bw, 2, Math.min(1, u.xp / (40 * u.level)), T.faint);
159+ f.bar(ctx, x + 8, h - 7, bw, 2, Math.min(1, u.xp / (40 * u.level)), T.faint);
143160 wd.hit(x, 0, cw, h, { name: `portrait-${i}`, key: `portrait-${i}`, onClick: () => m.select(u.id) });
144161 });
145162 },
@@ -1,7 +1,7 @@
11 import { drawText } from './text.js';
22 import { chrome, PAD } from './chrome.js';
33 import { T, rarityColor } from './theme.js';
4-import { total, maxHp, bonusText } from './stats.js';
4+import { total, maxHp, bonusText, compareText } from './stats.js';
55 import { traitText, traitName, heroTraits } from './traits.js';
66 import { oddsWord } from './threat.js';
77
@@ -76,6 +76,7 @@ export function createInventory(layer, m, f) {
7676 const pw = two ? w - PAD - px : inner;
7777 const inv = s.party.inventory;
7878 drawText(ctx, `Pack ${inv.length}`, px, py, { h: 20, size: 15, weight: 'bold' });
79+ if (inv.length) drawText(ctx, `compared with ${u.name}'s gear`, px + pw, py, { h: 20, size: 12, color: T.faint, align: 'right' });
7980 const gy = py + 22;
8081 const th = s.threat;
8182 const prep = m.preparing && th;
@@ -99,8 +100,9 @@ export function createInventory(layer, m, f) {
99100 const key = `item-${idx}`;
100101 f.panel(ctx, x, y, cw, CELL.h, 'raised', wd.hovered(key) ? T.muted : T.line);
101102 drawText(ctx, it.name, x + 7, y + 4, { h: 19, size: 12.5, color: rarityColor(it.rarity), maxW: cw - 12, fit: true });
102- drawText(ctx, it.key ? 'quest item' : it.trait ? `${it.slot}, ${traitName(it.trait)}` : `${it.slot} ${bonusText(it.bonus)}`, x + 7, y + 23, { h: 16, size: 11.5, color: it.trait ? T.muted : T.faint, maxW: cw - 12, fit: true });
103- tips[key] = `${describe(it)} · click to equip`;
103+ const worn = u.gear?.[it.slot];
104+ drawText(ctx, `${compareText(it, worn)}${it.trait ? `, ${traitName(it.trait)}` : ''}`, x + 7, y + 23, { h: 16, size: 11.5, color: T.muted, maxW: cw - 12, fit: true });
105+ tips[key] = `${describe(it)} · ${worn ? `vs ${worn.name}: ${compareText(it, worn)}` : `${it.slot} slot is empty`} · click to equip`;
104106 wd.hit(x, y, cw, CELL.h, { key, name: key, onClick: () => m.equip(u.id, it.id) });
105107 if (m.cursorOn && m.cursor === 4 + idx) focusRing(ctx, x, y, cw, CELL.h);
106108 }
@@ -1,8 +1,9 @@
11 import { threatHeight } from './threat.js';
22
33 const TOP = 44;
4-const PORTRAITS_W = 4 * 124 + 3 * 8;
4+const PORTRAITS_W = 4 * 140 + 3 * 8;
55 const MENU_W = 238;
6+export const LIP = 6;
67
78 export function uiScale(w, h) {
89 if (w < 640) return Math.min(1.4, Math.max(0.8, w / 440));
@@ -22,13 +23,13 @@ export function layoutFor(lw, lh, m) {
2223 const tw = Math.min(lw - 2 * pad, 600);
2324 out.topbar = { x: (lw - tw) / 2, y: 6, w: tw, h: 32 };
2425 const bh = wide ? 100 : 128;
25- out.bottom = { x: 0, y: lh - bh, w: lw, h: bh };
26+ out.bottom = { x: 0, y: lh - bh - LIP, w: lw, h: bh + LIP };
2627 if (wide) {
27- out.portraits = { x: 10, y: lh - bh + 8, w: PORTRAITS_W, h: 84 };
28+ out.portraits = { x: 10, y: lh - bh - LIP, w: PORTRAITS_W, h: bh - 2 };
2829 out.menu = { x: lw - MENU_W - 10, y: lh - bh + 8, w: MENU_W, h: 84 };
2930 } else {
3031 out.menu = { x: pad, y: lh - bh + 8, w: lw - 2 * pad, h: 44 };
31- out.portraits = { x: pad, y: lh - bh + 60, w: lw - 2 * pad, h: 60 };
32+ out.portraits = { x: pad, y: lh - bh + 52, w: lw - 2 * pad, h: bh - 58 };
3233 }
3334 const avail = lh - bh - TOP - pad;
3435 const pw = Math.min(lw - 2 * pad, 660);
@@ -45,7 +46,7 @@ export function layoutFor(lw, lh, m) {
4546 const logW = Math.min(wide ? 380 : lw - 2 * pad, lw * (wide ? 0.4 : 1));
4647 const lines = Math.min(m.logRowsFor(logW), wide ? 6 : 4);
4748 const logH = lines * 17 + 12;
48- out.log = m.panel || m.threat || !lines ? null : { x: pad, y: lh - bh - pad - logH, w: logW, h: logH };
49+ out.log = m.panel || m.threat || m.hush || !lines ? null : { x: pad, y: lh - bh - pad - logH, w: logW, h: logH };
4950 out['combat-banner'] = m.combat ? { x: (lw - 300) / 2, y: TOP, w: 300, h: 34 } : null;
5051 return out;
5152 }
@@ -0,0 +1,44 @@
1+import { flash } from './minis.js';
2+import { bonusText } from './stats.js';
3+import { T } from './theme.js';
4+
5+const HOP = 0.7;
6+const LINE = 17;
7+const HUSH = 1400;
8+
9+export function createLevelUp(party, cam, ui, sound) {
10+ const hops = [];
11+
12+ function play(before, after) {
13+ const prev = new Map(before.party.units.map((u) => [u.id, u]));
14+ for (const u of after.party.units) {
15+ const old = prev.get(u.id);
16+ const fig = party.figures.get(u.id);
17+ if (!old || !fig || u.level <= old.level) continue;
18+ const gain = Object.fromEntries(Object.keys(u.stats).filter((k) => k !== 'hp').map((k) => [k, u.stats[k] - old.stats[k]]));
19+ const gains = bonusText(gain).split(' ');
20+ sound.play('level');
21+ flash(fig, T.accent, 700);
22+ hops.push({ fig, t: 0 });
23+ ui.logLine(`${u.name} reaches level ${u.level}: ${gains.join(', ')}`, 'reward');
24+ const at = ui.cardTop(u.id);
25+ if (!at) continue;
26+ const [x, y, k] = at;
27+ ui.floater(x, y - LINE * k * (gains.length + 1), `Level ${u.level}`, 'level');
28+ ui.hush(HUSH);
29+ gains.forEach((g, i) => ui.floater(x, y - LINE * k * (gains.length - i), g, 'gain'));
30+ }
31+ }
32+
33+ function update(dt) {
34+ for (let i = hops.length - 1; i >= 0; i--) {
35+ const h = hops[i];
36+ h.t += dt;
37+ const p = Math.min(1, h.t / HOP);
38+ h.fig.userData.body.position.y = 0.06 + Math.sin(p * Math.PI) * 0.35;
39+ if (p >= 1) hops.splice(i, 1);
40+ }
41+ }
42+
43+ return { play, update };
44+}
@@ -12,6 +12,8 @@ import { hurt } from './stats.js';
1212 import { installDebug, track, tickFrame } from './debug.js';
1313 import { loadFonts } from './text.js';
1414 import { createSky } from './sky.js';
15+import { createRoute } from './route.js';
16+import { createLevelUp } from './levelup.js';
1517
1618 const canvas = document.getElementById('stage');
1719 const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
@@ -33,11 +35,17 @@ const marker = new THREE.Mesh(new THREE.TorusGeometry(0.54, 0.035, 4, 6).rotateZ
3335 marker.rotation.x = Math.PI / 2;
3436 marker.visible = false;
3537 scene.add(marker);
38+const goal = marker.clone();
39+scene.add(goal);
40+const route = createRoute(scene);
3641
3742 let world = null;
3843 let state = null;
3944 let busy = false;
4045 let lastTile = '';
46+let dest = null;
47+let hoverKey = '';
48+let hoverSeq = 0;
4149
4250 const ui = createUI(renderer, canvas, {
4351 onEquip: (unit, item) => mutate(() => api.equip(unit, item), 'click'),
@@ -58,8 +66,11 @@ const ui = createUI(renderer, canvas, {
5866 onBack: () => backOff(),
5967 onClick: () => sound.play('click'),
6068 onMute: () => ui.toast(sound.toggle() ? 'Sound off' : 'Sound on'),
69+ onHurry: () => combat.hurry(),
70+ onHalt: () => halt(),
6171 });
6272 const combat = createCombat(scene, party, cam, ui, sound);
73+const levelUp = createLevelUp(party, cam, ui, sound);
6374
6475 async function mutate(fn, cue) {
6576 if (busy) return;
@@ -90,6 +101,7 @@ function load(s) {
90101 party.place(p);
91102 cam.snap(p);
92103 lastTile = '';
104+ preview(null);
93105 ui.clearLog();
94106 ui.render(s);
95107 world.refresh(s);
@@ -115,26 +127,46 @@ canvas.addEventListener('pointerup', (e) => {
115127 if (e.button !== 0 || !down) return;
116128 const moved = Math.hypot(e.clientX - down.x, e.clientY - down.y) > 5;
117129 down = null;
118- if (!moved && !busy && world && track.mode === 'explore') {
119- const t = world.pick(ndc(e), cam.camera);
120- if (t) go(t);
121- }
130+ if (moved || !world) return;
131+ if (track.mode === 'combat') return combat.hurry();
132+ if (track.mode !== 'explore' || (busy && !dest)) return;
133+ const t = world.pick(ndc(e), cam.camera);
134+ if (!t) return;
135+ if (dest && t.x === state.party.x && t.y === state.party.y) return halt();
136+ go(t);
122137 });
123138 addEventListener('keydown', () => sound.wake());
124139 canvas.addEventListener('pointermove', (e) => {
125- if (!world || busy || track.mode !== 'explore' || ui.over(e.clientX, e.clientY)) {
140+ if (!world || (busy && !dest) || track.mode !== 'explore' || ui.over(e.clientX, e.clientY)) {
126141 marker.visible = false;
142+ preview(null);
127143 return;
128144 }
129145 const t = world.pick(ndc(e), cam.camera);
130146 marker.visible = !!t && world.walkable(t.x, t.y);
147+ preview(marker.visible ? t : null);
131148 if (t) marker.position.copy(world.worldPos(t.x, t.y)).setY(world.worldPos(t.x, t.y).y + 0.06);
132149 });
133150
151+async function preview(t) {
152+ const key = t ? `${t.x},${t.y}` : '';
153+ if (key === hoverKey) return;
154+ hoverKey = key;
155+ const seq = ++hoverSeq;
156+ if (!t) return route.clear();
157+ try {
158+ const r = await api.path(t.x, t.y);
159+ if (seq === hoverSeq) route.show(r, world.worldPos);
160+ } catch {
161+ if (seq === hoverSeq) route.clear();
162+ }
163+}
164+
134165 async function act(fn) {
135166 busy = true;
136167 track.busy = true;
137168 marker.visible = false;
169+ preview(null);
138170 try {
139171 await fn();
140172 } catch (e) {
@@ -146,6 +178,7 @@ async function act(fn) {
146178 }
147179
148180 function settle(next) {
181+ levelUp.play(state, next);
149182 state = next;
150183 world.refresh(next);
151184 ui.render(next);
@@ -160,19 +193,44 @@ function settle(next) {
160193 }
161194 }
162195
196+function aim(t) {
197+ dest = t;
198+ goal.visible = !!t;
199+ if (t) goal.position.copy(world.worldPos(t.x, t.y)).setY(world.worldPos(t.x, t.y).y + 0.06);
200+}
201+
202+function halt() {
203+ if (dest) aim(null);
204+}
205+
163206 function go(t) {
164207 if (!world.walkable(t.x, t.y)) return ui.toast('Impassable terrain');
165208 ui.closePanel();
209+ const walking = !!dest;
210+ aim(t);
211+ if (walking) return;
166212 return act(async () => {
167- const next = await api.move(t.x, t.y);
168- sky.setClock(next.clock);
169- world.moveBands(next);
170- await party.walk(world.trail(next));
171- settle(next);
172- if (next.threat) return showThreat(next.threat);
173- const sp = next.map.spawns.find((s) => s.x === next.party.x && s.y === next.party.y);
174- if (sp) ui.logLine(sp.hint, 'hint');
175- if (next.shop && next.party.x === t.x && next.party.y === t.y) ui.logLine(`A trader works here. Press T to trade.`, 'hint');
213+ try {
214+ while (dest && (state.party.x !== dest.x || state.party.y !== dest.y)) {
215+ const next = await api.move(dest.x, dest.y, 1);
216+ const stuck = !next.trail?.length;
217+ sky.setClock(next.clock);
218+ world.moveBands(next);
219+ await party.walk(world.trail(next));
220+ settle(next);
221+ if (next.threat) {
222+ aim(null);
223+ return showThreat(next.threat);
224+ }
225+ if (stuck || next.phase !== 'explore') break;
226+ }
227+ const s = state;
228+ const sp = s.map.spawns.find((q) => q.x === s.party.x && q.y === s.party.y);
229+ if (sp) ui.logLine(sp.hint, 'hint');
230+ if (s.shop) ui.logLine(`A trader works here. Press T to trade.`, 'hint');
231+ } finally {
232+ aim(null);
233+ }
176234 });
177235 }
178236
@@ -277,6 +335,7 @@ function frame() {
277335 const dt = Math.min(raw, 0.1);
278336 if (world) {
279337 party.update(dt);
338+ levelUp.update(dt);
280339 world.update(clock.elapsedTime);
281340 const key = tileOf(party.pos);
282341 if (key !== lastTile) {
@@ -0,0 +1,83 @@
1+import * as THREE from '../vendor/three.module.js';
2+import { createMini } from './minis.js';
3+import { T } from './theme.js';
4+
5+const RES = 192;
6+const FOV = 24;
7+
8+export function createMedallions(renderer, layer) {
9+ const stage = new THREE.Scene();
10+ stage.background = new THREE.Color(T.raised);
11+ stage.add(new THREE.HemisphereLight('#f4ead8', '#3a3026', 1.7));
12+ const sun = new THREE.DirectionalLight('#ffe4bd', 2.4);
13+ sun.position.set(1.2, 2.4, 3);
14+ stage.add(sun);
15+ const camera = new THREE.PerspectiveCamera(FOV, 1, 0.05, 30);
16+ const disc = new THREE.CircleGeometry(0.5, 48);
17+ const ring = new THREE.RingGeometry(0.5, 0.56, 48);
18+ const slots = new Map();
19+ let ids = '';
20+
21+ function slot(u) {
22+ const mini = createMini(u);
23+ mini.rotation.y = 0.4;
24+ mini.visible = false;
25+ stage.add(mini);
26+ mini.updateMatrixWorld(true);
27+ const box = new THREE.Box3().setFromObject(mini.userData.model.head);
28+ const eye = (box.min.y + box.max.y) / 2;
29+ const tall = Math.max(0.12, box.max.y - box.min.y) * 1.25;
30+ const target = new THREE.WebGLRenderTarget(RES, RES, { samples: 4 });
31+ const face = new THREE.Mesh(disc, new THREE.MeshBasicMaterial({ map: target.texture, transparent: true, depthTest: false, depthWrite: false }));
32+ const rim = new THREE.Mesh(ring, new THREE.MeshBasicMaterial({ color: T.line, transparent: true, depthTest: false, depthWrite: false, toneMapped: false }));
33+ face.renderOrder = rim.renderOrder = 3;
34+ layer.scene.add(face, rim);
35+ return { mini, target, face, rim, eye, dist: (tall * 0.5) / Math.tan(THREE.MathUtils.degToRad(FOV / 2)) };
36+ }
37+
38+ function sync(units) {
39+ const next = units.map((u) => u.id).join();
40+ if (next === ids) return;
41+ ids = next;
42+ for (const s of slots.values()) {
43+ stage.remove(s.mini);
44+ layer.scene.remove(s.face, s.rim);
45+ s.target.dispose();
46+ s.face.material.dispose();
47+ s.rim.material.dispose();
48+ }
49+ slots.clear();
50+ for (const u of units) slots.set(u.id, slot(u));
51+ }
52+
53+ function update(dt, spots, rect) {
54+ for (const s of slots.values()) s.face.visible = s.rim.visible = false;
55+ if (!rect || !spots) return;
56+ const k = layer.scale;
57+ const prev = renderer.getRenderTarget();
58+ for (const p of spots) {
59+ const s = slots.get(p.id);
60+ if (!s) continue;
61+ s.mini.visible = true;
62+ s.mini.userData.animate('idle', dt);
63+ camera.position.set(0, s.eye + s.dist * 0.12, s.dist);
64+ camera.lookAt(0, s.eye - s.dist * 0.05, 0);
65+ renderer.setRenderTarget(s.target);
66+ renderer.clear();
67+ renderer.render(stage, camera);
68+ s.mini.visible = false;
69+ const x = (rect.x + p.cx) * k;
70+ const y = layer.h - (rect.y + p.cy) * k;
71+ s.face.position.set(x, y, 0);
72+ s.rim.position.set(x, y, 0);
73+ s.face.scale.setScalar(p.d * k);
74+ s.rim.scale.setScalar(p.d * k);
75+ s.face.material.color.set(p.down ? '#5a5650' : '#ffffff');
76+ s.rim.material.color.set(p.rim);
77+ s.face.visible = s.rim.visible = true;
78+ }
79+ renderer.setRenderTarget(prev);
80+ }
81+
82+ return { sync, update };
83+}
@@ -27,6 +27,20 @@ export function createMini(unit, { enemy = false, boss = false } = {}) {
2727 g.add(body);
2828 const size = boss ? BOSS : enemy ? FOE : HERO;
2929 g.scale.setScalar(size);
30- Object.assign(g.userData, { body, size, animate: model.animate, model });
30+ Object.assign(g.userData, { body, size, animate: model.animate, swing: model.swing, model, mode: null });
3131 return g;
3232 }
33+
34+export function flash(fig, color = '#ff3020', ms = 160) {
35+ const meshes = [];
36+ fig.traverse((o) => o.isMesh && o.material.emissive && meshes.push(o));
37+ meshes.forEach((o) => {
38+ o.userData.paint ||= o.material;
39+ const c = o.userData.paint.clone();
40+ c.emissive = new THREE.Color(color);
41+ c.emissiveIntensity = 1.2;
42+ o.material = c;
43+ });
44+ clearTimeout(fig.userData.flash);
45+ fig.userData.flash = setTimeout(() => meshes.forEach((o) => (o.material = o.userData.paint)), ms);
46+}
@@ -12,7 +12,6 @@ export function createParty(scene) {
1212 const pos = new THREE.Vector3();
1313 let route = [];
1414 let resolve = null;
15- let pose = null;
1615
1716 function setUnits(units) {
1817 for (const f of figures.values()) root.remove(f);
@@ -67,10 +66,8 @@ export function createParty(scene) {
6766 }
6867 layout();
6968 const moving = route.length > 0;
70- for (const f of figures.values()) f.userData.animate(pose || (moving ? 'walk' : 'idle'), dt, moving ? PACE : 0);
69+ for (const f of figures.values()) f.userData.animate(f.userData.mode || (moving ? 'walk' : 'idle'), dt, moving ? PACE : 0);
7170 }
7271
73- const setPose = (p) => (pose = p);
74-
75- return { root, figures, pos, setUnits, place, walk, update, setPose, moving: () => route.length > 0 };
72+ return { root, figures, pos, setUnits, place, walk, update, moving: () => route.length > 0 };
7673 }
@@ -0,0 +1,44 @@
1+import * as THREE from '../vendor/three.module.js';
2+import { label } from './props.js';
3+import { T } from './theme.js';
4+
5+const MAX = 128;
6+
7+export function createRoute(scene) {
8+ const dots = new THREE.InstancedMesh(new THREE.CylinderGeometry(0.11, 0.11, 0.03, 12), new THREE.MeshBasicMaterial({ color: T.accent, transparent: true, opacity: 0.9, depthWrite: false, toneMapped: false }), MAX);
9+ dots.frustumCulled = false;
10+ dots.count = 0;
11+ scene.add(dots);
12+ const m = new THREE.Matrix4();
13+ let tag = null;
14+
15+ function clear() {
16+ dots.count = 0;
17+ if (tag) {
18+ scene.remove(tag);
19+ tag.material.dispose();
20+ tag = null;
21+ }
22+ }
23+
24+ function show(route, worldPos) {
25+ clear();
26+ const path = route.path.slice(0, MAX);
27+ if (!path.length) return;
28+ path.forEach(([x, y], i) => {
29+ const p = worldPos(x, y);
30+ dots.setMatrixAt(i, m.makeTranslation(p.x, p.y + 0.07, p.z));
31+ });
32+ dots.count = path.length;
33+ dots.instanceMatrix.needsUpdate = true;
34+ const n = route.path.length;
35+ const notes = [`${n} ${n === 1 ? 'hex' : 'hexes'}`, route.dusk && 'night falls on the way', route.blocked && 'stops at a fight'].filter(Boolean);
36+ tag = label(notes.join(', '));
37+ tag.scale.multiplyScalar(0.7);
38+ const end = worldPos(...path.at(-1));
39+ tag.position.set(end.x, end.y + 0.75, end.z);
40+ scene.add(tag);
41+ }
42+
43+ return { show, clear };
44+}
@@ -1,13 +1,13 @@
11 import { drawText } from './text.js';
22 import { chrome, PAD } from './chrome.js';
33 import { T, rarityColor } from './theme.js';
4-import { bonusText } from './stats.js';
4+import { bonusText, compareText } from './stats.js';
55 import { traitName } from './traits.js';
66
77 const ROW = 44;
88 const sellPrice = (it) => Math.max(1, Math.floor(it.value / 2));
99
10-function list(ctx, f, wd, x, y, w, h, title, items, price, verb, onPick, afford, scroll) {
10+function list(ctx, f, wd, x, y, w, h, title, items, price, verb, onPick, afford, scroll, unit) {
1111 drawText(ctx, title, x, y, { h: 20, size: 15, weight: 'bold' });
1212 const rows = Math.max(1, Math.floor((h - 26) / (ROW + 4)));
1313 const start = Math.min(scroll, Math.max(0, items.length - rows));
@@ -18,7 +18,7 @@ function list(ctx, f, wd, x, y, w, h, title, items, price, verb, onPick, afford,
1818 const ok = afford(it);
1919 f.panel(ctx, x, ry, w, ROW, 'raised', wd.hovered(key) && ok ? T.muted : T.line);
2020 drawText(ctx, it.name, x + 8, ry + 4, { h: 19, size: 13, color: ok ? rarityColor(it.rarity) : T.faint, maxW: w - 80, fit: true });
21- drawText(ctx, `${it.slot} ${bonusText(it.bonus)}${it.trait ? `, ${traitName(it.trait)}` : ''}`, x + 8, ry + 23, { h: 16, size: 11.5, color: T.faint, maxW: w - 80, fit: true });
21+ drawText(ctx, `${it.slot} ${unit ? compareText(it, unit.gear?.[it.slot]) : bonusText(it.bonus)}${it.trait ? `, ${traitName(it.trait)}` : ''}`, x + 8, ry + 23, { h: 16, size: 11.5, color: T.faint, maxW: w - 80, fit: true });
2222 drawText(ctx, `${price(it)} gold`, x + w - 8, ry, { h: ROW, size: 13, weight: 'bold', align: 'right', color: ok ? T.fg : T.faint });
2323 wd.hit(x, ry, w, ROW, { key, name: key, onClick: () => ok && onPick(it) });
2424 });
@@ -48,7 +48,7 @@ export function createShop(layer, m, f) {
4848 const colW = two ? (w - PAD * 2 - 16) / 2 : w - PAD * 2;
4949 const bottom = h - PAD;
5050 const shopH = two ? bottom - top : Math.min(26 + shop.stock.length * (ROW + 4), 26 + 2 * (ROW + 4));
51- list(ctx, f, wd, PAD, top, colW, shopH, 'For sale', shop.stock, (it) => it.value, 'buy', (it) => m.buy(it.id), (it) => s.party.gold >= it.value, 0);
51+ list(ctx, f, wd, PAD, top, colW, shopH, `For sale, vs ${m.unit().name}`, shop.stock, (it) => it.value, 'buy', (it) => m.buy(it.id), (it) => s.party.gold >= it.value, 0, m.unit());
5252 const sellable = s.party.inventory.filter((it) => !it.key);
5353 const sx = two ? PAD + colW + 16 : PAD;
5454 const sy = two ? top : top + shopH + 10;
@@ -10,6 +10,7 @@ const VOICES = {
1010 loot: [['triangle', 660, 990, 0.18, 0.12]],
1111 rest: [['sine', 392, 392, 0.5, 0.1], ['sine', 494, 494, 0.5, 0.08, 0.12], ['sine', 587, 587, 0.6, 0.08, 0.24]],
1212 win: [['triangle', 523, 523, 0.18, 0.14], ['triangle', 659, 659, 0.18, 0.14, 0.14], ['triangle', 784, 784, 0.4, 0.14, 0.28]],
13+ level: [['sine', 523, 1047, 0.3, 0.12], ['sine', 784, 1568, 0.4, 0.1, 0.15]],
1314 lose: [['triangle', 392, 392, 0.25, 0.14], ['triangle', 311, 311, 0.25, 0.14, 0.2], ['triangle', 262, 262, 0.5, 0.14, 0.4]],
1415 };
1516
@@ -1,4 +1,6 @@
11 export const total = (u, k) => u.stats[k] + Object.values(u.gear || {}).reduce((n, it) => n + (it?.bonus?.[k] || 0), 0);
22 export const maxHp = (u) => total(u, 'maxHp');
33 export const hurt = (u) => u.stats.hp * 2 < maxHp(u);
4-export const bonusText = (b) => Object.entries(b || {}).filter(([, v]) => v).map(([k, v]) => `${v > 0 ? '+' : ''}${v} ${k === 'maxHp' ? 'hp' : k}`).join(' ');
4+const SHORT = { maxHp: 'hp', attack: 'atk', defense: 'def', magic: 'mag', speed: 'spd', crit: 'crit' };
5+export const bonusText = (b) => Object.entries(SHORT).filter(([k]) => b?.[k]).map(([k, n]) => `${b[k] > 0 ? '+' : '−'}${Math.abs(b[k])} ${n}`).join(' ');
6+export const compareText = (it, worn) => bonusText(Object.fromEntries(Object.keys(SHORT).map((k) => [k, (it.bonus?.[k] || 0) - (worn?.bonus?.[k] || 0)]))) || 'same stats';
@@ -45,7 +45,7 @@ export function createThreat(layer, m, f) {
4545 y += 16;
4646 if (threat.barred) {
4747 drawText(ctx, 'Sealed', PAD, y, { h: 28, size: 24, display: true, color: T.muted });
48- drawText(ctx, 'Finish the other main steps before you face this foe.', PAD, y + 34, { h: 18, size: 13, color: T.muted, maxW: w - PAD * 2, fit: true });
48+ drawText(ctx, threat.needs?.length ? `Recover the ${threat.needs.join(', the ')} first.` : 'Finish the other main steps before you face this foe.', PAD, y + 34, { h: 18, size: 13, color: T.muted, maxW: w - PAD * 2, fit: true });
4949 } else {
5050 const bad = threat.odds < 60;
5151 drawText(ctx, oddsWord(threat), PAD, y, { h: 28, size: 24, display: true, color: bad ? T.danger : T.fg });
@@ -8,6 +8,7 @@ import { createShop } from './shop.js';
88 import { createThreat } from './threat.js';
99 import { createScreens } from './screens.js';
1010 import { createFloaters } from './floaters.js';
11+import { createMedallions } from './medallions.js';
1112
1213 const LOG_MAX = 60;
1314
@@ -16,6 +17,7 @@ export function createUI(renderer, canvas, h) {
1617 const layer = createLayer(renderer);
1718 const probe = new OffscreenCanvas(8, 8).getContext('2d');
1819 const floaters = createFloaters(layer);
20+ const medallions = createMedallions(renderer, layer);
1921 let toastTimer = 0;
2022
2123 const m = {
@@ -148,6 +150,10 @@ export function createUI(renderer, canvas, h) {
148150 e.preventDefault();
149151 return;
150152 }
153+ if (m.combat && (k === ' ' || k === 'Enter')) {
154+ e.preventDefault();
155+ return h.onHurry();
156+ }
151157 if (!m.hud || m.combat) return;
152158 const units = m.state.party.units;
153159 if (k === 'i' || k === 'I') m.togglePanel('inv');
@@ -155,6 +161,7 @@ export function createUI(renderer, canvas, h) {
155161 else if (k === 't' || k === 'T') m.togglePanel('shop');
156162 else if ((k === 'c' || k === 'C') && m.state.clock.time >= m.state.clock.dayLength) m.rest();
157163 else if (k === 'p' || k === 'P') m.drink(m.unit().id);
164+ else if (k === 'Escape' && !m.panel) h.onHalt();
158165 else if (k === 'Escape') m.closePanel();
159166 else if (/^[1-4]$/.test(k) && units[Number(k) - 1]) m.select(units[Number(k) - 1].id);
160167 else if (k === 'Tab' && m.panel === 'inv') {
@@ -180,6 +187,7 @@ export function createUI(renderer, canvas, h) {
180187 tick(dt) {
181188 floaters.update(dt);
182189 layer.update();
190+ medallions.update(dt, widgets.portraits.spots, widgets.portraits.rect);
183191 },
184192 draw: () => layer.render(),
185193 panel: () => m.panel,
@@ -187,6 +195,7 @@ export function createUI(renderer, canvas, h) {
187195 render(s, hp) {
188196 m.state = s;
189197 m.hp = hp || null;
198+ medallions.sync(s.party.units);
190199 if (!m.selected || !s.party.units.some((u) => u.id === m.selected)) m.selected = s.party.units[0].id;
191200 m.cursor = Math.min(m.cursor, 3 + s.party.inventory.length);
192201 if (m.panel === 'shop' && !s.shop) m.panel = null;
@@ -211,6 +220,20 @@ export function createUI(renderer, canvas, h) {
211220 refresh();
212221 },
213222 floater: (x, y, text, cls) => floaters.spawn(x, y, text, cls),
223+ hush(ms) {
224+ m.hush = true;
225+ clearTimeout(m.hushTimer);
226+ m.hushTimer = setTimeout(() => {
227+ m.hush = false;
228+ refresh();
229+ }, ms);
230+ refresh();
231+ },
232+ cardTop(id) {
233+ const wd = widgets.portraits;
234+ const p = wd.rect && wd.spots?.find((q) => q.id === id);
235+ return p && [(wd.rect.x + p.cx) * layer.scale, (wd.rect.y + p.cy - p.d / 2) * layer.scale, layer.scale];
236+ },
214237 setCombat(on, title = '') {
215238 m.combat = on;
216239 m.combatTitle = title;