Fix mobile toolbar spacing and move Redo into Undo menu

This commit is contained in:
coyotte508 2026-10-13 03:18:48 +02:00
commit 21214e23b9
8 changed files with 170 additions and 32 deletions

View file

@ -315,3 +315,5 @@ Viewer 0.1.97 / engine 0.4.77 adds a Regions map guide using the engine's public
Viewer 0.1.98 keeps the region city count inline and only shows that count and the Ruler of the World combat explanation for the selected Greek civilization. Persia instead shows its count including the starting region and explains King of Persia, including its city-size limit. The region boundary guide remains available to all civilizations. Engine remains 0.4.77.
Viewer 0.1.99 / engine 0.4.78 fixes Revolution's independent sacrifices: the first prevents action loss and the second prevents government change. Step two no longer overwrites step one's result, and the government prompt checks the second sacrifice. Saved games already awaiting step two recover the first sacrifice from active (not undone) history. The journal explicitly names the consequence prevented. Validated all four sacrifice combinations and saved-step compatibility, plus the reported game's local copy; no live moves were submitted.
Viewer 0.1.100 fixes mobile map controls wrapping into a tall block and overlapping activity controls. The map toolbar stays on one compact row, with journal/chat above it. Smaller outer margins and an explicit width cap preserve a gap between player panels and the action bar. Redo no longer adds a toolbar column: Undo's menu arrow, long press, context menu, or keyboard Down opens Redo. Verified layout at 320/360/393/430px in both map views, keyboard access, and long-press without accidental Undo. Engine remains 0.4.78.

View file

@ -1,12 +1,12 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.99",
"version": "0.1.100",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@boardgamers/clash-web-client",
"version": "0.1.99",
"version": "0.1.100",
"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.99",
"version": "0.1.100",
"private": true,
"type": "module",
"scripts": {

View file

@ -0,0 +1,84 @@
// Mobile toolbar spacing and accessible Redo without an extra action column.
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { chromium } from 'playwright';
const engine = createRequire(import.meta.url)('../.engine/server.js');
const npcs = JSON.parse(await engine.init(2, [], {}, 'map-targets', {})).players.slice(2);
async function fixture(name) {
const game = JSON.parse(
await readFile(new URL(`../../server/tests/test_games/${name}.json`, import.meta.url), 'utf8'),
);
for (const npc of npcs)
if (!game.players.some((p) => p.civilization === npc.civilization))
game.players.push({ ...npc, id: game.players.length });
return game;
}
const browser = await chromium.launch({
headless: true,
args: ['--use-gl=angle', '--use-angle=swiftshader'],
});
const frame = (page) =>
page.evaluate(() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))));
async function open(width, height, state, strategy = false) {
const page = await browser.newPage({ viewport: { width, height } }),
errors = [],
sent = [];
page.on('pageerror', (e) => errors.push(e.message));
await page.exposeFunction('captureMove', (move) => sent.push(JSON.parse(move)));
await page.route('**/*', async (route) => {
const path = new URL(route.request().url()).pathname;
if (path === '/')
return route.fulfill({
contentType: 'text/html',
body: '<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><div id="app"></div><script src="/viewer.js"></script>',
});
if (!['/viewer.js', '/server_bg.wasm'].includes(path)) return route.abort();
return route.fulfill({
contentType: path.endsWith('.wasm') ? 'application/wasm' : 'text/javascript',
body: await readFile(new URL('../dist' + path, import.meta.url)),
});
});
await page.goto('http://clash.test/');
await page.evaluate(
({ state, strategy }) => {
window.host = clash3d.launch('#app');
host.on('move', (m) => window.captureMove(m));
host.emit('player', { index: 0 });
host.emit('preferences', { sound: false, mapView: strategy ? 'strategy' : '3d' });
host.emit('state', state);
},
{ state: engine.stripSecret(JSON.stringify(state), 0), strategy },
);
return { page, errors, sent };
}
try {
for(const width of [320,360,393,430]) {
const base=await fixture('advances/collect_free_economy');
const collected=engine.tryMove(JSON.stringify(base),JSON.stringify({Playing:{Collect:{city_position:'C2',collections:[{position:'B1',pile:{ore:1},times:1}],action_type:'Collect'}}}),0);
const g=JSON.parse(engine.tryMove(collected,JSON.stringify('Undo'),0));
const {page,errors,sent}=await open(width,700,g);
await page.evaluate(()=>document.querySelector('.game-shell').classList.add('dark'));
await page.locator('.player-card').first().waitFor();
for(const strategy of [false,true]) {
if(strategy)await page.getByRole('button',{name:'Strategy map',exact:true}).click();
const boxes=await page.evaluate(()=>Object.fromEntries(['.map-controls','.table-tools','.player-list','.board-toolbar'].map(s=>{const r=document.querySelector(s).getBoundingClientRect();return [s,{x:r.x,y:r.y,right:r.right,bottom:r.bottom,height:r.height}]})));
assert(boxes['.map-controls'].height<=50,JSON.stringify(boxes));
assert(boxes['.map-controls'].x>=0 && boxes['.map-controls'].right<=width);
assert(boxes['.table-tools'].bottom<=boxes['.map-controls'].y-4,JSON.stringify(boxes));
assert(boxes['.player-list'].right+9<=boxes['.board-toolbar'].x,JSON.stringify(boxes));
await page.screenshot({path:`/tmp/mobile-toolbar-${width}-${strategy}.png`});
}
const undo=page.getByRole('button',{name:'Undo last action',exact:true});
await undo.focus(); await page.keyboard.press('ArrowDown');
await page.getByRole('button',{name:'Redo last undone action',exact:true}).waitFor();
await page.keyboard.press('Escape');
const box=await undo.boundingBox(); await page.mouse.move(box.x+box.width/2,box.y+box.height/2);
await page.mouse.down(); await new Promise(r=>setTimeout(r,800)); await page.mouse.up();
assert.equal(sent.length,0,'Long press must not also Undo');
await page.getByRole('button',{name:'Redo last undone action',exact:true}).click();
assert.deepEqual(sent,['Redo']);
assert.deepEqual(errors,[]);await page.close();console.log(`${width}: controls, activity bar, and player/action spacing passed`);
}
} finally {await browser.close();}

View file

@ -3,6 +3,7 @@
import { formatPoints } from './score';
import { currentLocale, translateText } from './localization';
const translate = $derived((value: string) => translateText(value, $currentLocale));
import UndoControl from './UndoControl.svelte';
import CollectionBonusHints from './CollectionBonusHints.svelte';
import BarbarianIcon from './BarbarianIcon.svelte';
import CitySiteIcon from './CitySiteIcon.svelte';
@ -47,8 +48,6 @@
X,
ChevronRight,
Hourglass,
Undo2,
Redo2,
GraduationCap,
Target,
MapPin,
@ -1238,7 +1237,7 @@
>{/each}
</div>
</section>
<div class="board-toolbar" class:has-redo={$session.view?.canRedo} aria-label="Game controls">
<div class="board-toolbar" aria-label="Game controls">
<div
class="turn-banner"
class:waiting={!!waiting}
@ -1415,19 +1414,8 @@
aria-hidden="true"
/>{/if}</button
>
<button
title="Undo last action"
data-tutorial="undo"
aria-label="Undo last action"
disabled={!!$session.playback || !$session.view?.canUndo || $session.pending}
onclick={() => controller.submit('Undo')}><Undo2 size={19} /><span>Undo</span></button
>
{#if $session.view?.canRedo}<button
title="Redo last undone action"
aria-label="Redo last undone action"
disabled={!!$session.playback || $session.pending}
onclick={() => controller.submit('Redo')}><Redo2 size={19} /><span>Redo</span></button
>{/if}
<UndoControl canUndo={!!$session.view?.canUndo} canRedo={!!$session.view?.canRedo}
blocked={!!$session.playback || $session.pending} submit={action => controller.submit(action)}/>
<button
class:active={confirmEnd}
class:end-turn-ready={readyToEnd}

View file

@ -0,0 +1,49 @@
<script lang="ts">
import { onDestroy } from 'svelte';
import { Undo2, Redo2, ChevronDown } from 'lucide-svelte';
let { canUndo, canRedo, blocked, submit }: { canUndo: boolean; canRedo: boolean; blocked: boolean; submit: (action: 'Undo' | 'Redo') => void } = $props();
let open = $state(false), root = $state<HTMLDivElement>();
let timer: ReturnType<typeof setTimeout> | undefined;
let held = false;
function cancel() { clearTimeout(timer); timer = undefined; }
function start(event: PointerEvent) {
held = false; cancel();
if (!canRedo || blocked || event.button !== 0) return;
timer = setTimeout(() => { held = true; open = true; }, 500);
}
function undo() {
cancel();
if (held) { held = false; return; }
if (canUndo) { open = false; submit('Undo'); }
else if (canRedo) open = !open;
}
$effect(() => { if (!canRedo || blocked) open = false; });
onDestroy(cancel);
</script>
<svelte:window onpointerdown={event => { if (root && !root.contains(event.target as Node)) open = false; }} onkeydown={event => { if (event.key === 'Escape') open = false; }}/>
<div class="undo-control" bind:this={root}>
<button title={canRedo ? 'Undo last action · Hold or use the menu for Redo' : 'Undo last action'}
data-tutorial="undo" aria-label="Undo last action" disabled={blocked || (!canUndo && !canRedo)}
onpointerdown={start} onpointerup={cancel} onpointerleave={cancel} onpointercancel={cancel}
oncontextmenu={event => { if (canRedo && !blocked) { event.preventDefault(); held = true; open = true; } }}
onkeydown={event => { if (canRedo && (event.key === 'ArrowDown' || (event.shiftKey && event.key === 'F10'))) { event.preventDefault(); open = true; } }}
onclick={undo}><Undo2 size={19}/><span>Undo</span></button>
{#if canRedo}
<button class="undo-menu-toggle" title="Undo options" aria-label="Undo options" aria-expanded={open}
disabled={blocked} onclick={() => open = !open}><ChevronDown size={10}/></button>
{/if}
{#if open && canRedo && !blocked}
<div class="undo-options">
<button title="Redo last undone action" aria-label="Redo last undone action" onclick={() => { open = false; submit('Redo'); }}><Redo2 size={17}/><span>Redo</span></button>
</div>
{/if}
</div>
<style>
.undo-control { position: relative; min-width: 0; }
.undo-control > button:first-child { width: 100%; }
.undo-control .undo-menu-toggle { position: absolute; right: -3px; top: -4px; width: 12px; height: 12px; min-height: 12px; padding: 0; background: var(--paper2); border-radius: 4px; }
.undo-menu-toggle :global(svg) { width: 10px !important; height: 10px !important; }
.undo-options { position: absolute; right: 0; top: 100%; z-index: 30; padding: 5px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); box-shadow: 0 3px 12px #0003; }
.undo-options button { display: flex !important; align-items: center; gap: 6px !important; padding: 8px 12px !important; white-space: nowrap; }
.undo-options button span { display: inline !important; }
</style>

View file

@ -311,19 +311,7 @@
animation: none !important;
}
}
.board-toolbar.has-redo .board-actions {
grid-template-columns: repeat(11, minmax(0, 1fr));
}
.play-layout .board-toolbar.has-redo {
width: 590px;
}
@media (max-width: 760px), (max-width: 1000px) and (max-height: 500px) {
.play-layout .board-toolbar.has-redo {
width: 264px;
}
.board-toolbar.has-redo .board-actions {
grid-template-columns: repeat(9, minmax(0, 1fr));
}
.play-layout .live-battle {
top: 100px;
}

View file

@ -6221,7 +6221,34 @@ small {
@media (max-width: 600px) {
.game-shell .map-controls .map-view-toggle span { display: none; }
.game-shell .map-controls .map-view-toggle { width: 38px; padding: 8px; }
.game-shell .map-controls { max-width: calc(100% - 16px); flex-wrap: wrap; justify-content: flex-end; }
.game-shell .map-controls {
max-width: calc(100% - 16px);
flex-wrap: nowrap;
justify-content: flex-end;
height: 48px;
bottom: var(--mobile-bottom);
right: 8px;
}
.game-shell .map-controls > * { flex-shrink: 0; }
.game-shell .map-controls button,
.game-shell .map-controls .map-view-toggle {
width: clamp(27px, calc((100vw - 40px) / 10), 34px);
min-width: 0;
height: 40px;
padding: 5px;
}
.game-shell:not(.board-interacting) .table-tools {
bottom: calc(var(--mobile-bottom) + 56px);
right: 8px;
}
}
.map-tooltip .region-city-count strong { display: inline; white-space: nowrap; }
@media (max-width: 760px), (max-width: 1000px) and (max-height: 500px) {
.game-shell .player-list { left: 6px; }
.game-shell .play-layout .board-toolbar {
right: 6px;
max-width: calc(100% - clamp(118px, 35vw, 140px) - 22px);
}
}