Make map guides collapsible without hiding overlays
This commit is contained in:
parent
cfe63f6ea9
commit
51ceddc75b
7 changed files with 114 additions and 17 deletions
|
|
@ -383,3 +383,5 @@ Viewer 0.1.131 / engine 0.4.94 allows New Colonies to disembark into adjacent un
|
|||
Viewer 0.1.132 / engine 0.4.95 treats undefended city captures as battles for Captivi, Embalming, Heroic General and battle objectives. Fast War separately requires opposing Army units; defended-city and casualty objective requirements remain intact.
|
||||
|
||||
Viewer 0.1.133 shortens the Barbarian map guide and removes its two trailing caveats to leave more map visible on mobile.
|
||||
|
||||
Viewer 0.1.134 lets the Barbarian, Pirate, Trade Routes and Regions guides collapse to a title bar while keeping their map overlays visible.
|
||||
|
|
|
|||
4
web-client/package-lock.json
generated
4
web-client/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.133",
|
||||
"version": "0.1.134",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.133",
|
||||
"version": "0.1.134",
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.9.0",
|
||||
"lucide-svelte": "^0.577.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.133",
|
||||
"version": "0.1.134",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
|||
73
web-client/scripts/map-guide-smoke.mjs
Normal file
73
web-client/scripts/map-guide-smoke.mjs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
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 initial = await engine.init(2, [], { civilization: 'Random' }, 'map-guide-smoke', {});
|
||||
const seat = engine.currentPlayer(initial);
|
||||
const game = JSON.parse(engine.stripSecret(initial, seat));
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
args: ['--use-gl=angle', '--use-angle=swiftshader'],
|
||||
});
|
||||
try {
|
||||
for (const [width, height] of [
|
||||
[1400, 900],
|
||||
[390, 780],
|
||||
[320, 640],
|
||||
]) {
|
||||
const page = await browser.newPage({ viewport: { width, height } }),
|
||||
errors = [],
|
||||
sent = [];
|
||||
let state = initial;
|
||||
page.on('pageerror', (e) => errors.push(e.message));
|
||||
await page.exposeFunction('applyMove', async (action) => {
|
||||
sent.push(JSON.parse(action));
|
||||
state = engine.tryMove(state, action, seat);
|
||||
await page.evaluate((raw) => host.emit('state', raw), engine.stripSecret(state, seat));
|
||||
});
|
||||
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(
|
||||
({ seat, state }) => {
|
||||
window.host = clash3d.launch('#app');
|
||||
host.on('move', (action) => window.applyMove(action));
|
||||
host.emit('player', { index: seat });
|
||||
host.emit('theme', { dark: true });
|
||||
host.emit('preferences', { sound: false, unitBadges: true });
|
||||
host.emit('state', state);
|
||||
},
|
||||
{ seat, state: JSON.stringify(game) },
|
||||
);
|
||||
for (const name of ['Show regions', 'Show trade routes', 'Show pirate spawn positions', 'Show barbarian spawn and movement']) {
|
||||
const button = page.getByRole('button', {name, exact:true});
|
||||
await button.click();
|
||||
const guide = page.locator('.collapsible-map-guide');
|
||||
await guide.waitFor();
|
||||
const expanded = (await guide.boundingBox()).height;
|
||||
await guide.locator('summary').click();
|
||||
assert.equal(await guide.getAttribute('open'), null);
|
||||
const collapsed = (await guide.boundingBox()).height;
|
||||
assert(collapsed < expanded, `${name}: collapse reduces height`);
|
||||
assert.equal(await button.getAttribute('aria-pressed'), 'true');
|
||||
await guide.locator('summary').press('Enter');
|
||||
assert.notEqual(await guide.getAttribute('open'), null);
|
||||
await button.click();
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
console.log(`${width}px: all four guides collapse, retain overlays and expand by keyboard`);
|
||||
await page.close();
|
||||
}
|
||||
} finally { await browser.close(); }
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
import UndoControl from './UndoControl.svelte';
|
||||
import CollectionBonusHints from './CollectionBonusHints.svelte';
|
||||
import BarbarianIcon from './BarbarianIcon.svelte';
|
||||
import MapGuide from './MapGuide.svelte';
|
||||
import CitySiteIcon from './CitySiteIcon.svelte';
|
||||
import PlaybackPanel from './PlaybackPanel.svelte';
|
||||
import CardReferenceDialog from './CardReferenceDialog.svelte';
|
||||
|
|
@ -78,7 +79,7 @@
|
|||
import { chatPlayerColor, chatPlayerIndex } from './chat-presentation';
|
||||
import { World } from './board';
|
||||
import { militarySummary } from './strategy';
|
||||
import { positionStrategyKey, positionMapGuide } from './strategy-key';
|
||||
import { positionStrategyKey } from './strategy-key';
|
||||
import ResearchTree from './ResearchTree.svelte';
|
||||
import { researchDecision, mapDecisionOptions } from './decision-controls';
|
||||
import CityPanel from './CityPanel.svelte';
|
||||
|
|
@ -989,8 +990,7 @@
|
|||
{@const regionCivilization = $session.view?.players.find(player => player.index === regionPlayer)?.civilization}
|
||||
{@const allOccupied = ($session.view?.regions ?? []).filter(r=>cities.some(c=>r.tiles.includes(c.position)))}
|
||||
{@const occupied = ($session.view?.regions ?? []).filter(r=>r.homePlayer !== regionPlayer && cities.some(c=>r.tiles.includes(c.position)))}
|
||||
<div class="map-tooltip pirate-spawn-key" role="status" use:positionMapGuide>
|
||||
<strong>Regions</strong>
|
||||
<MapGuide title="Regions">
|
||||
<label>Civilization<select aria-label="Region player" value={regionPlayer} onchange={event=>controller.patch({regionPlayer:Number(event.currentTarget.value)})}>
|
||||
{#each $session.view?.players ?? [] as player}<option value={player.index}>{player.civilization}</option>{/each}
|
||||
</select></label>
|
||||
|
|
@ -1002,7 +1002,7 @@
|
|||
<p class="region-city-count">Regions containing cities: <strong>{allOccupied.length}</strong></p>
|
||||
<p>King of Persia: As an action, activate Cyrus’ city. Gain 1 mood or culture token per region containing your cities, up to the size of Cyrus’ city. Includes the starting region.</p>
|
||||
{/if}
|
||||
</div>
|
||||
</MapGuide>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="sr-only" id="sea-route-help" aria-live="polite">
|
||||
|
|
@ -1049,8 +1049,7 @@
|
|||
><Route size={18} /></button>
|
||||
{#if $session.tradeRoutes && $session.mode === 'overview' && !$session.playback && !$session.view?.decision && !choiceDecision && !objectiveDecision && !$session.view?.explorationDecision}
|
||||
{@const guide = $session.view?.tradeRoutes?.find(p => p.player === ($session.tradeRoutePlayer ?? $session.seat ?? $session.view?.activePlayer))}
|
||||
<div class="map-tooltip pirate-spawn-key" role="status" use:positionMapGuide>
|
||||
<strong>Trade Routes</strong>
|
||||
<MapGuide title="Trade Routes">
|
||||
<label>Civilization
|
||||
<select aria-label="Trade route player" value={$session.tradeRoutePlayer ?? $session.seat ?? $session.view?.activePlayer}
|
||||
onchange={(event) => controller.patch({ tradeRoutePlayer: Number(event.currentTarget.value) })}>
|
||||
|
|
@ -1067,7 +1066,7 @@
|
|||
{/each}
|
||||
<p>Routes are recalculated at the start of your turn.</p>
|
||||
{/if}
|
||||
</div>
|
||||
</MapGuide>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="map-control-help">
|
||||
|
|
@ -1110,12 +1109,7 @@
|
|||
)}><BarbarianIcon /></button
|
||||
>
|
||||
{#if $session.pirateSpawns && $session.mode === 'overview' && !$session.view?.decision && !$session.view?.choiceDecision && !$session.view?.objectiveDecision && !$session.view?.explorationDecision && !$session.abilitiesOpen && !$session.playback}
|
||||
<div class="map-tooltip pirate-spawn-key" role="status" use:positionMapGuide>
|
||||
<strong
|
||||
>{$session.threatGuide === 'barbarians'
|
||||
? 'Barbarians'
|
||||
: 'Pirate spawn positions'}</strong
|
||||
>
|
||||
<MapGuide title={$session.threatGuide === 'barbarians' ? 'Barbarians' : 'Pirate spawn positions'}>
|
||||
<label
|
||||
>Incident player
|
||||
<select
|
||||
|
|
@ -1150,7 +1144,7 @@
|
|||
</p>{/if}
|
||||
{/if}
|
||||
{#if $session.threatGuide !== 'barbarians'}<small>Shows current positions. They may change before the event.</small>{/if}
|
||||
</div>
|
||||
</MapGuide>
|
||||
{/if}
|
||||
</div>
|
||||
<span></span>
|
||||
|
|
|
|||
11
web-client/src/MapGuide.svelte
Normal file
11
web-client/src/MapGuide.svelte
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte';
|
||||
import { ChevronDown } from 'lucide-svelte';
|
||||
import { positionMapGuide } from './strategy-key';
|
||||
let { title, children }: { title: string; children: Snippet } = $props();
|
||||
</script>
|
||||
|
||||
<details open class="map-tooltip pirate-spawn-key collapsible-map-guide" use:positionMapGuide>
|
||||
<summary><strong>{title}</strong><ChevronDown size={18} /></summary>
|
||||
{@render children()}
|
||||
</details>
|
||||
|
|
@ -6262,3 +6262,20 @@ small {
|
|||
color: var(--ink);
|
||||
border-color: var(--line);
|
||||
}
|
||||
|
||||
/* Collapse only the legend; its map overlay remains enabled. */
|
||||
.collapsible-map-guide > summary {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
min-height: 32px;
|
||||
cursor: pointer;
|
||||
list-style: none;
|
||||
}
|
||||
.collapsible-map-guide > summary::-webkit-details-marker { display: none; }
|
||||
.collapsible-map-guide > summary strong { margin: 0; }
|
||||
.collapsible-map-guide > summary svg { flex-shrink: 0; }
|
||||
.collapsible-map-guide:not([open]) > summary svg { transform: rotate(180deg); }
|
||||
.collapsible-map-guide[open] > summary { margin-bottom: 8px; }
|
||||
.collapsible-map-guide > summary:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue