Mark discarded leader rerolls in battle popups

This commit is contained in:
coyotte508 2026-11-05 21:22:04 +00:00
commit ad6200403b
7 changed files with 178 additions and 7 deletions

View file

@ -964,3 +964,22 @@ and the six-age default; legacy Epic remains eight ages. The accessible AgeTrack
provides localized mode rules and ending captions on desktop and mobile.
No existing games are migrated or replayed. See
[implementation and verification](../../docs/monumental-game-length.md).
# Viewer 0.1.204 / engine unchanged (0.4.137)
Battle popups now match the journal: discarded dice explicitly recorded with the
`re-roll` effect have muted, struck-through values and a reroll icon. Final rolls,
inactive leader faces and blocked abilities retain their normal presentation.
Accessible labels identify rerolled dice. Combat values, hits, rules and saved
history are unchanged. Regression coverage retains repeated discarded rolls and
the final result exactly once; the battle-dice browser smoke checks 1400, 390 and
320px widths with animation enabled and reduced motion.
Publish only the viewer, preserving engine 0.4.137 and the current creation
options, including the exact game-length labels and Standard default. No live
game changes or smaller-city experiment are included.
Verified with 1,029 frontend tests, locale checks, Svelte checks, production build
and the focused battle-dice browser smoke. The older `combat-smoke.mjs` still
fails its unrelated map-label expectation (`Battle · C1` versus the existing
`Battle · Round 1`); this release does not change that label or suppress the test.

View file

@ -1,12 +1,12 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.203",
"version": "0.1.204",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@boardgamers/clash-web-client",
"version": "0.1.203",
"version": "0.1.204",
"dependencies": {
"@boardgamers/protocol": "0.9.0",
"lucide-svelte": "^0.577.0",

View file

@ -1,6 +1,6 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.203",
"version": "0.1.204",
"private": true,
"type": "module",
"scripts": {

View file

@ -0,0 +1,97 @@
import assert from 'node:assert/strict';
import { createServer } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { chromium } from 'playwright';
// Mount the real live/replay popup with recorded dice, without an engine or timer.
const server = await createServer({
configFile: false,
appType: 'custom',
root: new URL('..', import.meta.url).pathname,
plugins: [svelte()],
server: { host: '127.0.0.1', port: 0 },
});
server.middlewares.use(async (req, res, next) => {
if (req.url !== '/battle-dice-test') return next();
res.setHeader('Content-Type', 'text/html');
res.end(
await server.transformIndexHtml(
req.url,
`<!doctype html><meta name="viewport" content="width=device-width,initial-scale=1">
<style>:root { --muted: #777; --ink: #222; --paper2: #fff; --line: #ccc; }</style>
<div class="play-layout"><div class="live-battle" id="app"></div></div>
<script type="module">
import { mount } from 'svelte';
import { writable } from 'svelte/store';
import BattlePlayback from '/src/BattlePlayback.svelte';
import '/src/combat.css';
const session = writable({ battles: [] });
window.showBattle = (dice, motion) => session.set({
battles: [{ key: JSON.stringify(dice) + motion, roll: true, losses: [], combat: {
round: 1, attacker: { dice, value: 7, hits: 1, modifiers: [] },
defender: { dice: [], value: 0, hits: 0, modifiers: [] },
} }], battleAnimate: motion, reducedMotion: !motion,
});
mount(BattlePlayback, { target: document.querySelector('#app'), props: {
controller: { session, dismissBattles() { session.set({ battles: [] }); } },
} });
</script>`,
),
);
});
await server.listen();
const browser = await chromium.launch({ headless: true });
try {
for (const width of [1400, 390, 320]) {
const page = await browser.newPage({ viewport: { width, height: 900 } });
const errors = [];
page.on('pageerror', (error) => errors.push(error.message));
await page.goto(`http://127.0.0.1:${server.httpServer.address().port}/battle-dice-test`);
await page.waitForFunction(() => typeof window.showBattle === 'function');
for (const motion of [true, false]) {
for (const count of [0, 1, 3]) {
const dice = [
...Array.from({ length: count }, () => ({ value: 1, symbol: 'Leader', effect: 're-roll' })),
{ value: 6, symbol: 'Infantry', effect: '+1 combat value' },
{ value: 1, symbol: 'Leader' }, // No active leader: keep this face.
{ value: 1, symbol: 'Leader', blockedBy: 'High Ground' },
];
await page.evaluate(({ dice, motion }) => window.showBattle(dice, motion), { dice, motion });
const popup = page.getByRole('region', { name: 'Battle summary' });
await popup.waitFor();
assert.equal(await popup.locator('.battle-die').count(), dice.length);
assert.deepEqual(
await popup.locator('.battle-die b').allTextContents(),
dice.map((d) => String(d.value)),
);
assert.equal(
await popup.getByRole('img', { name: '1 · Leader face · Rerolled', exact: true }).count(),
count,
);
assert.equal(await popup.locator('.rerolled').count(), count);
assert.deepEqual(
await popup
.locator('.battle-die b')
.evaluateAll((nodes) =>
nodes.map((node) => getComputedStyle(node).textDecorationLine.includes('line-through')),
),
dice.map((d) => d.effect === 're-roll'),
);
assert.equal(await popup.locator('.ability-blocked.rerolled').count(), 0);
assert.equal(await popup.locator('.battle-hit-count').first().innerText(), '7 value\n1 hit');
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
}
}
await page.screenshot({ path: `/tmp/clash-battle-rerolls-${width}.png` });
assert.deepEqual(errors, []);
await page.getByRole('button', { name: 'Dismiss battle summary' }).click();
assert.equal(await page.locator('.battle-recap').count(), 0);
console.log(
`${width}px: discarded rerolls crossed; final, inactive and blocked rolls retained once, with and without motion.`,
);
await page.close();
}
} finally {
await browser.close();
await server.close();
}

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { Swords, Shield, X, CircleSlash } from 'lucide-svelte';
import { Swords, Shield, X, CircleSlash, RotateCcw } from 'lucide-svelte';
import type { Controller } from './controller';
import CivilizationEmblem from './CivilizationEmblem.svelte';
import UnitIcon from './UnitIcon.svelte';
@ -41,17 +41,22 @@
</div>
{#if side.dice}
<div class="battle-dice" aria-label={`${side.civilization ?? ''} recorded dice`}>
{#each side.dice as die, i}<span
{#each side.dice as die, i}
{@const label = `${die.value} · ${die.symbol ? `${die.symbol} face · ${die.effect === 're-roll' ? 'Rerolled' : (die.blockedBy ? `Ability blocked by ${die.blockedBy}` : die.effect ?? 'No ability activated')}` : 'Face not recorded'}`}
<span
class="battle-die"
class:activated={!!die.effect}
class:ability-blocked={!!die.blockedBy}
class:rerolled={die.effect === 're-roll'}
style={`--die-delay:${i * 45}ms`}
title={`${die.value}${die.symbol ? ` · ${die.symbol}` : ''}${die.blockedBy ? ` · Ability blocked by ${die.blockedBy}` : die.effect ? ` · ${die.effect}` : ''}`}
role="img"
aria-label={label}
title={label}
>
<b>{die.value}</b>{#if die.symbol}<UnitIcon
type={die.symbol === 'Leader' ? { Leader: 'Leader' } : die.symbol}
size={12}
/>{/if}{#if die.blockedBy}<CircleSlash size={10} />{/if}
/>{/if}{#if die.blockedBy}<CircleSlash size={10} />{/if}{#if die.effect === 're-roll'}<RotateCcw size={10} />{/if}
</span>{:else}<small>No dice</small>{/each}
</div>
{#if side.dice.some(d => d.blockedBy)}<small class="combat-blocked-note">Abilities blocked by {side.diceBlockedBy}</small>{/if}

View file

@ -125,3 +125,47 @@ test('rolls arriving after a tactics prompt stay assigned to their public battle
assert.equal(cue.combat.attacker.hits, 1);
assert.equal(cue.combat.defender.hits, 0);
});
test('popup cues retain every discarded leader roll and the final result exactly once', () => {
const game = fixture('retreat_no.outcome1');
game.log![0].rounds[0].turns[0].actions = [
{
items: [
{
player: 0,
origin: { Ability: 'Combat' },
CombatRound: {
round: 1,
attackers: { leader: 1, infantry: 1 },
defenders: { infantry: 1 },
defending_player: 1,
},
},
{
player: 0,
origin: { Ability: 'Combat' },
CombatRoll: {
rolls: [
{ value: 1, unit_type: 'Leader', bonus: true },
{ value: 1, unit_type: 'Leader', bonus: true },
{ value: 6, unit_type: 'Infantry', bonus: true },
{ value: 1, unit_type: 'Leader', bonus: false },
],
combat_value: 8,
hits: 1,
},
},
],
},
];
game.log_index = 1;
const [cue] = battleCues(game, 0);
assert.deepEqual(cue.combat.attacker.dice, [
{ value: 1, symbol: 'Leader', effect: 're-roll' },
{ value: 1, symbol: 'Leader', effect: 're-roll' },
{ value: 6, symbol: 'Infantry', effect: '+1 combat value' },
{ value: 1, symbol: 'Leader' },
]);
assert.equal(cue.combat.attacker.value, 8);
assert.equal(cue.combat.attacker.hits, 1);
});

View file

@ -227,6 +227,12 @@
border-color: #ad935d;
color: var(--ink);
}
.battle-die.rerolled {
color: var(--muted);
}
.battle-die.rerolled b {
text-decoration: line-through;
}
.battle-hit-count {
display: flex;
flex-wrap: wrap;