diff --git a/.github/workflows/web-viewer.yml b/.github/workflows/web-viewer.yml index 32e0aa6d..0c8506d6 100644 --- a/.github/workflows/web-viewer.yml +++ b/.github/workflows/web-viewer.yml @@ -30,7 +30,7 @@ jobs: working-directory: web-client - run: node scripts/viking-cargo-smoke.mjs && node scripts/withdrawal-smoke.mjs && node scripts/horse-master-smoke.mjs && node scripts/carthage-recruit-smoke.mjs && node scripts/payment-defaults-smoke.mjs && node scripts/wonder-payment-perf.mjs working-directory: web-client - - run: node scripts/map-guide-smoke.mjs && node scripts/trade-routes-smoke.mjs && node scripts/raiders-smoke.mjs + - run: node scripts/map-guide-smoke.mjs && node scripts/trade-routes-smoke.mjs && node scripts/raiders-smoke.mjs && node scripts/influence-bubble-smoke.mjs working-directory: web-client - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 with: diff --git a/web-client/docs/viewer-publishing.md b/web-client/docs/viewer-publishing.md index 4c862fb2..f7904f1e 100644 --- a/web-client/docs/viewer-publishing.md +++ b/web-client/docs/viewer-publishing.md @@ -1878,3 +1878,22 @@ green before publishing the frozen viewer and engine together. Preserve catalog settings and preferences. Only the artwork manifest's lockfile integrity pin changes; no artwork is republished and no production moves, repairs, backfills or historical rewrites are performed. + +# Viewer 0.1.243 / engine 0.4.173 — Cultural influence thought bubbles and centered color-blind symbols + +Cities with foreign buildings now display a compact cultural-influence thought +bubble in both 3D and Strategy views showing each influencing civilization's +color-coded emblem medallion, a count pip when a civilization holds multiple +foreign buildings, and an accessible hover/screen-reader summary without placing +civilization text labels on the board. Color-blind ownership symbols (`●`, `▲`, +`■`, `◆`, `✚`, `✕`) now render via dead-center geometric paths/SVGs across 3D +flag badges, thought-bubble symbol pills, Strategy badges, and player cards +(with bounding-box centering fallback for custom symbols). + +Engine 0.4.173 is unchanged since 0.1.242 and publishes alongside viewer +0.1.243. Require exact-commit Check and Web viewer CI green before publishing +the frozen viewer and engine together. Preserve catalog 8 / 46 definitions, +artwork 4, all 60 named assets, gallery, Standard options, settings and +preferences. Only the artwork manifest's lockfile integrity pin changes; no +artwork is republished and no production moves, repairs, backfills or +historical rewrites are performed. diff --git a/web-client/package-lock.json b/web-client/package-lock.json index c71cbbdb..4cc9b4b1 100644 --- a/web-client/package-lock.json +++ b/web-client/package-lock.json @@ -1,12 +1,12 @@ { "name": "@boardgamers/clash-web-client", - "version": "0.1.242", + "version": "0.1.243", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@boardgamers/clash-web-client", - "version": "0.1.242", + "version": "0.1.243", "dependencies": { "@boardgamers/protocol": "0.11.0", "lucide-svelte": "^0.577.0", diff --git a/web-client/package.json b/web-client/package.json index c3832ccf..793a78df 100644 --- a/web-client/package.json +++ b/web-client/package.json @@ -1,6 +1,6 @@ { "name": "@boardgamers/clash-web-client", - "version": "0.1.242", + "version": "0.1.243", "private": true, "type": "module", "scripts": { diff --git a/web-client/release/achievement-assets.json b/web-client/release/achievement-assets.json index 02d03491..b33d5e5f 100644 --- a/web-client/release/achievement-assets.json +++ b/web-client/release/achievement-assets.json @@ -13,7 +13,7 @@ "web-client/src/civilization-emblems.ts": "01b0cbf3fa77a8466532ccd73d63c1a3ddc9bbc79fc06ce7224b425322a9c9f0", "web-client/src/civilization-flags.ts": "cd176076bfe05b3059093b80c88596b7ae46b77898695c6c7406cbe1a3a0f78b", "server/src/content/civilizations.rs": "73602f3db506f3dc2dbc6de43d01179440fd3bb034c997ff209336faaef2a332", - "web-client/package-lock.json": "ef90167f54b1fc2c4386da61388759467180dff77d5bdc2fe7c893a8f3c36d7b", + "web-client/package-lock.json": "991ba032023910ccfb0f0951ddf3a2568f2e9fd80c154d2d55c72ed5a38f3739", "web-client/node_modules/lucide-svelte/dist/Icon.svelte": "f7b49ab842c143fa680fa8bd9a54a9efdc48c2e2d49fa574bd5ccf8f6cfca5be", "web-client/node_modules/lucide-svelte/dist/defaultAttributes.js": "5b8981c6e3434ae6538716af9e0403554e7708c4087f18d060950a7bef00d96a", "web-client/node_modules/lucide-svelte/LICENSE": "668dcc52803480e0a026b31140a4cae668772663cd764e5991d252eef03f98db" diff --git a/web-client/scripts/influence-bubble-smoke.mjs b/web-client/scripts/influence-bubble-smoke.mjs new file mode 100644 index 00000000..cdc49893 --- /dev/null +++ b/web-client/scripts/influence-bubble-smoke.mjs @@ -0,0 +1,154 @@ +import assert from 'node:assert/strict'; +import { chromium } from 'playwright'; +import { startPreview } from './influence-preview.mjs'; + +const server = await startPreview(0); +const browser = await chromium.launch({ + headless: true, + args: ['--use-gl=angle', '--use-angle=swiftshader'], +}); + +function boxesOverlap(a, b) { + return a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y; +} + +try { + const baseUrl = `http://127.0.0.1:${server.address().port}`; + + // 1. Standard 3D view: uninfluenced, 1-building, multi-building count pip, multi-civ, click-to-select, no overlap. + { + const page = await browser.newPage({ viewport: { width: 1400, height: 900 } }); + const errors = []; + page.on('pageerror', (e) => errors.push(e.message)); + await page.goto(`${baseUrl}/`); + await page.locator('.city-influence-bubble').first().waitFor(); + await page.waitForTimeout(400); + + const bubbles = page.locator('.city-influence-bubble'); + assert.equal(await bubbles.count(), 3, 'Uninfluenced C3 has no bubble; F3, F5, C5 each have one'); + + const bubbleInfo = await page.evaluate(() => + [...document.querySelectorAll('.city-influence-bubble')].map((el) => ({ + title: el.getAttribute('title') ?? '', + ariaLabel: el.getAttribute('aria-label') ?? '', + text: (el.innerText ?? '').trim(), + medallions: el.querySelectorAll('.influence-medallion').length, + counts: [...el.querySelectorAll('.influence-count')].map((n) => n.textContent?.trim()), + symbols: el.querySelectorAll('.influence-symbol').length, + rect: el.getBoundingClientRect().toJSON(), + })), + ); + + const single = bubbleInfo.find((b) => b.title === 'Influenced by Greece'); + const multiCount = bubbleInfo.find((b) => b.title === 'Influenced by Greece (3)'); + const multiCiv = bubbleInfo.find((b) => b.title === 'Influenced by Greece, Egypt'); + assert.ok(single, 'F3 single-building influence bubble present'); + assert.equal(single.medallions, 1); + assert.deepEqual(single.counts, []); + assert.equal(single.symbols, 0); + + assert.ok(multiCount, 'F5 multi-building influence bubble present'); + assert.equal(multiCount.medallions, 1); + assert.deepEqual(multiCount.counts, ['3']); + + assert.ok(multiCiv, 'C5 multi-civ influence bubble present'); + assert.equal(multiCiv.medallions, 2); + assert.deepEqual(multiCiv.counts, []); + + for (const b of bubbleInfo) { + assert.doesNotMatch(b.text, /Greece|Egypt|Rome/i, 'No visible civilization text on board bubbles'); + } + + // Verify no overlap between any city mood badge and any influence bubble in 3D view. + const moodRects = await page.evaluate(() => + [...document.querySelectorAll('.city-map-label')].map((el) => ({ + label: el.getAttribute('aria-label') ?? '', + rect: el.getBoundingClientRect().toJSON(), + })), + ); + assert.equal(moodRects.length, 4, 'All 4 cities render mood badges'); + for (const bubble of bubbleInfo) { + for (const mood of moodRects) { + assert.equal( + boxesOverlap(bubble.rect, mood.rect), + false, + `Bubble "${bubble.title}" must not overlap mood badge "${mood.label}"`, + ); + } + } + + // Clicking a thought bubble selects its city without submitting any gameplay moves. + await page.locator('.city-influence-bubble[title="Influenced by Greece (3)"]').click(); + await page.getByRole('region', { name: /Tile F5/ }).waitFor(); + assert.deepEqual(await page.evaluate(() => window.sent), [], 'Clicking influence bubble must not send moves'); + assert.deepEqual(errors, []); + await page.close(); + } + + // 2. Strategy view (normal + color-blind): compact bubbles, zero civ text on board, color-blind symbols centered. + for (const colorBlind of [false, true]) { + const page = await browser.newPage({ viewport: { width: 1400, height: 900 } }); + const errors = []; + page.on('pageerror', (e) => errors.push(e.message)); + await page.goto(`${baseUrl}/?strategy=1${colorBlind ? '&colorblind=1' : ''}`); + await page.locator('.strategy-map-tile[data-position="F5"]').waitFor(); + + assert.equal( + await page.locator('.strategy-map-tile[data-position="C3"] .strategy-influence-bubble').count(), + 0, + 'Uninfluenced C3 has no Strategy influence bubble', + ); + const f3 = page.locator('.strategy-map-tile[data-position="F3"] .strategy-influence-bubble'); + const f5 = page.locator('.strategy-map-tile[data-position="F5"] .strategy-influence-bubble'); + const c5 = page.locator('.strategy-map-tile[data-position="C5"] .strategy-influence-bubble'); + assert.equal(await f3.getAttribute('title'), 'Influenced by Greece'); + assert.equal(await f5.getAttribute('title'), 'Influenced by Greece (3)'); + assert.equal(await c5.getAttribute('title'), 'Influenced by Greece, Egypt'); + assert.equal(await f3.locator('.influence-medallion').count(), 1); + assert.equal(await f3.locator('.influence-count').count(), 0); + assert.equal(await f5.locator('.influence-count').textContent(), '3'); + assert.equal(await c5.locator('.influence-medallion').count(), 2); + + for (const tilePos of ['C3', 'F3', 'F5', 'C5']) { + const tileText = await page.locator(`.strategy-map-tile[data-position="${tilePos}"]`).innerText(); + assert.doesNotMatch(tileText, /Greece|Egypt|Rome/i, `Strategy tile ${tilePos} has no visible civ text`); + } + + if (colorBlind) { + assert.equal(await f3.locator('.influence-symbol[data-symbol="▲"] svg.ownership-symbol-svg').count(), 1); + assert.equal(await c5.locator('.influence-symbol[data-symbol="▲"] svg.ownership-symbol-svg').count(), 1); + assert.equal(await c5.locator('.influence-symbol[data-symbol="■"] svg.ownership-symbol-svg').count(), 1); + assert.ok((await page.locator('.strategy-symbol svg.ownership-symbol-svg').count()) >= 4); + assert.equal(await page.locator('.ownership-symbol svg.ownership-symbol-svg').count(), 3); + } else { + assert.equal(await page.locator('.influence-symbol').count(), 0); + } + + assert.deepEqual(await page.evaluate(() => window.sent), []); + assert.deepEqual(errors, []); + await page.close(); + } + + // 3. 3D color-blind mode: centered SVG pills in thought bubbles + player cards, zero errors. + { + const page = await browser.newPage({ viewport: { width: 1400, height: 900 } }); + const errors = []; + page.on('pageerror', (e) => errors.push(e.message)); + await page.goto(`${baseUrl}/?colorblind=1`); + await page.locator('.city-influence-bubble').first().waitFor(); + await page.waitForTimeout(400); + + assert.equal(await page.locator('.city-influence-bubble .influence-symbol svg.ownership-symbol-svg').count(), 4); + assert.equal(await page.locator('.ownership-symbol svg.ownership-symbol-svg').count(), 3); + assert.deepEqual(await page.evaluate(() => window.sent), []); + assert.deepEqual(errors, []); + await page.close(); + } + + console.log( + 'Cultural influence bubbles & centered color-blind symbols: 3D/Strategy, single/counted/multi-civ, click-to-select, zero civ text, no mood overlap, and color-blind mode passed.', + ); +} finally { + await browser.close(); + await new Promise((resolve) => server.close(resolve)); +} diff --git a/web-client/scripts/influence-preview.mjs b/web-client/scripts/influence-preview.mjs new file mode 100644 index 00000000..a3b94c85 --- /dev/null +++ b/web-client/scripts/influence-preview.mjs @@ -0,0 +1,115 @@ +import { createServer } from 'node:http'; +import { readFile } from 'node:fs/promises'; +import { createRequire } from 'node:module'; +import { pathToFileURL } from 'node:url'; + +export async function influenceFixture(engine) { + let raw = await engine.init(3, [], { civilization: 'ChooseCivilization' }, 'influence-preview', {}); + for (const civ of ['Rome', 'Greece', 'Egypt']) { + raw = engine.tryMove(raw, JSON.stringify({ ChooseCivilization: civ }), engine.currentPlayer(raw)); + } + const game = JSON.parse(raw); + const cols = ['C', 'D', 'E', 'F', 'G']; + const terrainAt = (col, row) => { + if (col === 'G') return 'Water'; + if (col === 'D' && row === 2) return 'Mountain'; + if ((col === 'C' && row === 5) || (col === 'E' && row === 3) || (col === 'D' && row === 6)) return 'Forest'; + if (col === 'E' && row === 6) return 'Barren'; + return 'Fertile'; + }; + game.map.tiles = []; + for (const col of cols) { + for (let row = 2; row <= 6; row++) { + game.map.tiles.push([col + row, terrainAt(col, row)]); + } + } + if (game.map.unexplored_blocks) game.map.unexplored_blocks = []; + for (const player of game.players) { + player.cities = []; + player.units = []; + } + game.players[0].civilization = 'Rome'; + game.players[1].civilization = 'Greece'; + game.players[2].civilization = 'Egypt'; + // 4 nearby Roman cities demonstrating control, single-civ, counted single-civ, and multi-civ influence. + game.players[0].cities = [ + { + position: 'C3', + mood_state: 'Happy', + city_pieces: { temple: 0, fortress: 0 }, + }, + { + position: 'F3', + mood_state: 'Happy', + city_pieces: { temple: 1 }, + }, + { + position: 'F5', + mood_state: 'Neutral', + city_pieces: { academy: 1, port: 1, temple: 1, fortress: 0 }, + port_position: 'G5', + }, + { + position: 'C5', + mood_state: 'Angry', + city_pieces: { temple: 1, obelisk: 2 }, + }, + ]; + return game; +} + +const contentType = (path) => + path.endsWith('.wasm') + ? 'application/wasm' + : path.endsWith('.json') + ? 'application/json' + : path.endsWith('.woff2') + ? 'font/woff2' + : 'text/javascript'; + +export async function startPreview(port = 8646) { + const engine = createRequire(import.meta.url)('../.engine/server.js'); + const game = await influenceFixture(engine); + const raw = JSON.stringify(game); + const state = engine.stripSecret(raw, 0); + const server = createServer(async (req, res) => { + const url = new URL(req.url, 'http://localhost'); + const path = url.pathname; + if (path === '/') { + const dark = url.searchParams.get('dark') === '1'; + const colorBlind = url.searchParams.get('colorblind') === '1'; + const mapView = url.searchParams.get('strategy') === '1' ? 'strategy' : '3d'; + const locale = url.searchParams.get('locale') || 'en'; + res.setHeader('Content-Type', 'text/html'); + return res.end(`Clash · Cultural influence preview
`); + } + if (!/^\/(viewer\.js|server_bg\.wasm|[a-zA-Z-]+\.json|[a-zA-Z-]+\.woff2)$/.test(path)) { + res.statusCode = 404; + return res.end(); + } + try { + res.setHeader('Content-Type', contentType(path)); + res.end(await readFile(new URL('../dist' + path, import.meta.url))); + } catch { + res.statusCode = 404; + res.end(); + } + }); + await new Promise((resolve) => server.listen(port, '127.0.0.1', resolve)); + return server; +} + +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + await startPreview(); + console.log('Cultural influence preview: http://localhost:8646/ (normal viewer, 3D + Strategy)'); +} diff --git a/web-client/src/App.svelte b/web-client/src/App.svelte index a4ad86b9..d1d4bc0c 100644 --- a/web-client/src/App.svelte +++ b/web-client/src/App.svelte @@ -6,6 +6,7 @@ import UndoControl from './UndoControl.svelte'; import CollectionBonusHints from './CollectionBonusHints.svelte'; import BarbarianIcon from './BarbarianIcon.svelte'; + import OwnershipSymbol from './OwnershipSymbol.svelte'; import MapGuide from './MapGuide.svelte'; import UnitIcon from './UnitIcon.svelte'; import CitySiteIcon from './CitySiteIcon.svelte'; @@ -953,8 +954,10 @@ > {#if $session.colorBlind}{#if $session.colorBlind}{@const symbol = playerSymbol(player.index, $session.playerSymbols)}{:else} + import CivilizationEmblem from './CivilizationEmblem.svelte'; + import OwnershipSymbol from './OwnershipSymbol.svelte'; + import { emblemInkColor, type CityInfluencer } from './building-owner'; + import { playerColor, playerSymbol } from './types'; + + let { + influencers, + colorBlind = false, + playerColors = [], + playerSymbols = [], + compact = false, + }: { + influencers: readonly CityInfluencer[]; + colorBlind?: boolean; + playerColors?: readonly string[]; + playerSymbols?: readonly string[]; + compact?: boolean; + } = $props(); + + + diff --git a/web-client/src/OwnershipSymbol.svelte b/web-client/src/OwnershipSymbol.svelte new file mode 100644 index 00000000..3341ee86 --- /dev/null +++ b/web-client/src/OwnershipSymbol.svelte @@ -0,0 +1,37 @@ + + +{#if symbol === '●'} + +{:else if symbol === '▲'} + +{:else if symbol === '■'} + +{:else if symbol === '◆'} + +{:else if symbol === '✚'} + +{:else if symbol === '✕'} + +{:else} + {symbol} +{/if} diff --git a/web-client/src/StrategyMapTile.svelte b/web-client/src/StrategyMapTile.svelte index 8cf402c4..64dac76a 100644 --- a/web-client/src/StrategyMapTile.svelte +++ b/web-client/src/StrategyMapTile.svelte @@ -1,7 +1,9 @@