Preserve exhausted terrain visual identity; release viewer 227

This commit is contained in:
coyotte508 2026-11-19 08:35:45 +00:00
commit e0a00fb9ed
14 changed files with 211 additions and 18 deletions

View file

@ -1630,3 +1630,17 @@ Verify installer-owned revision 7 in public and admin metadata against the exact
and all 58 existing named assets; upload no artwork. Preserve gallery, Standard
length default and unrelated metadata. No backfill, live-game changes, history repair
or Fossil refresh. Historical fixtures and activation receipts remain untouched.
# Viewer 0.1.227 / engine unchanged (0.4.159)
Exhausted terrain retains its underlying trees, mountains and terrain colors in
3D, with small foreground depletion hatches. Strategy tiles keep the original
terrain icon and prominence with corner hatches; inspection explicitly names the
exhausted terrain, including beneath cities. A real-engine local preview and
regression/smoke coverage distinguish visual identity from engine legality.
This is a visual-only release: the pending exhausted-terrain movement rules bug
is not fixed. Preserve the deployed engine bytes, revision-7 achievement catalog
(46 definitions), all artwork, gallery and unrelated metadata. Require main-branch
Check and Web viewer CI before publishing the tested viewer bundle. No live-game
moves, saved-game migration, history repair, achievement backfill or Fossil refresh.

View file

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

View file

@ -1,6 +1,6 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.226",
"version": "0.1.227",
"private": true,
"type": "module",
"scripts": {
@ -16,7 +16,8 @@
"test:locales": "node ../scripts/check-locales.mjs src/localization && node --test scripts/localization-source.test.mjs && npm run localization:check",
"localization:check": "node scripts/extract-localization.mjs --check",
"localization:extract": "node scripts/extract-localization.mjs",
"tutorial:fixtures": "node scripts/build-tutorial-fixtures.mjs"
"tutorial:fixtures": "node scripts/build-tutorial-fixtures.mjs",
"test:exhausted-terrain": "npm run build && node scripts/exhausted-terrain-smoke.mjs"
},
"dependencies": {
"@boardgamers/protocol": "0.11.0",

View file

@ -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": "3105337a05dc96f7ef1c1ffa8094c44ca12d18d4004bbafe834b11c024d5a29a",
"web-client/package-lock.json": "2cdcaffa337d237e0f0e281251f85ffc15d5f9bce0c12863f29ec46b1f37c719",
"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"

View file

@ -0,0 +1,27 @@
/** Real engine state for comparing normal and exhausted terrain in the normal viewer. */
export async function exhaustedTerrainFixture(engine) {
const game = JSON.parse(await engine.init(2, [], {}, 'exhausted-terrain-preview', {}));
const occupied = new Set(
game.players.flatMap((p) => [
...(p.cities ?? []).map((c) => c.position),
...(p.units ?? []).map((u) => u.position),
]),
);
const tiles = game.map.tiles.filter(([p]) => !occupied.has(p));
const kinds = ['Forest', 'Mountain', 'Fertile', 'Barren'];
game.map.unexplored_blocks = [];
for (const tile of game.map.tiles) if (tile[1] === 'Unexplored') tile[1] = 'Barren';
const examples = [];
for (let i = 0; i < kinds.length; i++) {
const normal = tiles[i * 2],
exhausted = tiles[i * 2 + 1];
normal[1] = kinds[i];
exhausted[1] = { Exhausted: kinds[i] };
examples.push({ kind: kinds[i], normal: normal[0], exhausted: exhausted[0] });
}
delete game.board_history;
const state = JSON.stringify(game),
seat = game.current_player_index;
engine.webView(engine.stripSecret(state, seat), seat);
return { state, seat, examples };
}

View file

@ -0,0 +1,89 @@
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import { readFile } from 'node:fs/promises';
import { chromium } from 'playwright';
import { exhaustedTerrainFixture } from './exhausted-terrain-fixture.mjs';
const engine = createRequire(import.meta.url)('../.engine/server.js');
const { state, seat, examples } = await exhaustedTerrainFixture(engine);
const raw = engine.stripSecret(state, seat);
const browser = await chromium.launch({
headless: true,
args: ['--use-gl=angle', '--use-angle=swiftshader'],
});
try {
for (const [width, height] of [
[1400, 1000],
[390, 780],
[320, 640],
]) {
const page = await browser.newPage({ viewport: { width, height } });
const errors = [],
sent = [];
page.on('pageerror', (error) => errors.push(error.message));
await page.exposeFunction('moveSent', (action) => sent.push(action));
await page.route('**/*', async (route) => {
const pathname = new URL(route.request().url()).pathname;
if (pathname === '/')
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(pathname)) return route.abort();
return route.fulfill({
contentType: pathname.endsWith('.wasm') ? 'application/wasm' : 'text/javascript',
body: await readFile(new URL('../dist' + pathname, import.meta.url)),
});
});
await page.goto('http://clash.test/');
assert.deepEqual(errors, []);
await page.evaluate(
({ raw, seat }) => {
const host = clash3d.launch('#app');
const preferences = { sound: false, mapView: '3d', homeAtBottom: false };
host.on('move', (action) => window.moveSent(action));
host.on('update:preference', ({ name, value }) => {
preferences[name] = value;
host.receive('preferences', preferences);
});
host.receive('player', { index: seat });
host.receive('preferences', preferences);
host.receive('theme', { dark: false });
host.receive('state', raw);
},
{ raw, seat },
);
const mode = page.getByRole('button', { name: 'Strategy map', exact: true });
await mode.waitFor();
await page.waitForTimeout(1500);
await page.screenshot({ path: `/tmp/clash-exhausted-3d-${width}.png` });
await mode.click();
await page.keyboard.press('Tab');
for (const example of examples) {
const tile = page.locator(`.strategy-map-tile[data-position="${example.exhausted}"]`);
await tile.waitFor();
assert.equal(await tile.getAttribute('aria-label'), `Exhausted ${example.kind.toLowerCase()}`);
const icon = tile.locator('.terrain-icon');
assert.equal(
await icon.getAttribute('width'),
['Forest', 'Mountain'].includes(example.kind) ? '30' : '18',
);
assert.equal(await icon.locator(':scope > path').count(), 1, 'exhaustion hatch remains visible');
assert.equal(await tile.locator('svg.lucide').count(), 1, 'underlying terrain icon remains');
// Keyboard focus inspects even map tiles visually behind floating mobile controls.
await tile.focus();
await page
.locator('.tile-hover-terrain')
.filter({ hasText: `Exhausted ${example.kind.toLowerCase()}` })
.waitFor();
}
await page.mouse.move(0, 0);
await page.screenshot({ path: `/tmp/clash-exhausted-strategy-${width}.png` });
assert.deepEqual(errors, []);
assert.deepEqual(sent, [], 'visual inspection must never submit moves');
assert(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
console.log('Exhausted terrain 3D/Strategy viewer smoke passed', { width, examples });
await page.close();
}
} finally {
await browser.close();
}

View file

@ -1,6 +1,8 @@
import { readFileSync } from 'node:fs';
import { exhaustedTerrainFixture } from './exhausted-terrain-fixture.mjs';
export const previewScenarios = [
{ id: 'exhausted-terrain', label: 'Exhausted terrain', note: 'Compare normal and exhausted Forest, Mountain, Fertile and Barren terrain in 3D and Strategy map.' },
{ id: 'tactics', label: 'Tactics · Steel Weapons', note: 'Local asynchronous sequence: attacker Steel Weapons and tactics, then defender Steel Weapons and tactics, then reveal.' },
{ id: 'advance', label: 'Free advance', note: 'Research lets you save an early choice.' },
{ id: 'raze', label: 'Raze city', note: 'Cities lets you save an early choice.' },
@ -12,6 +14,7 @@ export const previewScenarios = [
];
export async function createPreviewScenario(engine: any, id: string) {
if (id === 'exhausted-terrain') return exhaustedTerrainFixture(engine);
if (!previewScenarios.some(s => s.id === id)) throw Error('Unknown preview scenario');
const names: Record<string, string> = {
tactics: 'tactics_cards/peltasts', advance: 'status_phase/free_advance', raze: 'status_phase/raze_city_decline',

View file

@ -3,6 +3,7 @@
import { buildingInfo } from './city';
import BarbarianIcon from './BarbarianIcon.svelte';
import TerrainIcon from './TerrainIcon.svelte';
import { terrainDisplay } from './terrain-display';
import { playerColor, playerSymbol } from './types';
import type { StrategyTile } from './strategy';
let {
@ -11,12 +12,13 @@
playerColors,
playerSymbols,
}: { tile: StrategyTile; colorBlind: boolean; playerColors: string[]; playerSymbols: string[] } = $props();
const terrain = $derived(terrainDisplay(tile.terrain));
</script>
<span class="strategy-terrain" class:important={tile.terrain === 'Forest' || tile.terrain === 'Mountain'}
<span class="strategy-terrain" class:important={terrain.prominent}
><TerrainIcon
terrain={tile.terrain}
size={tile.terrain === 'Forest' || tile.terrain === 'Mountain' ? 30 : 18}
size={terrain.prominent ? 30 : 18}
/></span
>
{#each tile.occupants as occupant}

View file

@ -9,5 +9,5 @@
<title>{info.label}</title>
<polygon points="27,14 20.5,25.3 7.5,25.3 1,14 7.5,2.7 20.5,2.7" fill={info.color} />
<g transform="translate(6 6)"><info.Icon size={16} strokeWidth={2} color="#263f33" /></g>
{#if info.exhausted}<path d="M5 23 23 5" stroke="#263f33" stroke-width="2" />{/if}
{#if info.exhausted}<path d="m16 24 3-4 m1 4 3-4 m1 4 2-3" stroke="#263f33" stroke-width="2" />{/if}
</svg>

View file

@ -22,6 +22,9 @@
{:else}<strong class="tile-hover-terrain"
><TerrainIcon terrain={$data.terrain} size={15} />{terrainInfo($data.terrain).label}</strong
>{/if}
{#if $data.city && terrainInfo($data.terrain).exhausted}
<strong class="tile-hover-terrain"><TerrainIcon terrain={$data.terrain} size={15} />{terrainInfo($data.terrain).label}</strong>
{/if}
{#if $data.city}
<div class="tile-hover-buildings">
{#each $data.city.buildings as { name, civilization }}

View file

@ -27,6 +27,7 @@ import { playerColor, playerSymbol } from './types';
import { buildingCivilization } from './building-owner';
import { positionXY } from './model';
import { terrainInfo } from './terrain';
import { terrainDisplay } from './terrain-display';
import { PieceModels, type BuildingKind } from './piece-models';
import { MapGesture } from './map-gesture';
import { SeaOverlay } from './sea-overlay';
@ -1225,15 +1226,14 @@ export class World {
this.center.set((minX + maxX) / 2, 0, (minZ + maxZ) / 2);
}
for (const [position, terrain] of mapTiles) {
const exhausted = typeof terrain !== 'string';
const kind = exhausted ? terrain.Exhausted : terrain;
const { kind, exhausted } = terrainDisplay(terrain);
const [x, z] = positionXY(position);
const height = kind === 'Water' ? 0.13 : kind === 'Unexplored' ? 0.27 : 0.43;
const group = new THREE.Group();
group.position.set(x, height / 2 - 0.12, z);
const top = this.material(
exhausted
? `#${new THREE.Color(terrainColor[kind]).lerp(new THREE.Color('#8d7c7c'), 0.6).getHexString()}`
? `#${new THREE.Color(terrainColor[kind]).lerp(new THREE.Color('#8d7c7c'), 0.25).getHexString()}`
: terrainColor[kind],
);
const side = this.material(
@ -1247,17 +1247,17 @@ export class World {
const terrainGroup = new THREE.Group();
terrainGroup.position.y = height / 2;
if (exhausted) {
// Hatching distinguishes depletion from barren ground without implying normal terrain restrictions.
// A small foreground hatch marks depletion without hiding the original terrain.
const hatch = this.material('#5f5052');
for (let i = -1; i <= 1; i++) {
const line = this.mesh(new THREE.BoxGeometry(i === 0 ? 1.5 : 1.05, 0.016, 0.045), hatch);
line.position.set(i * 0.25, 0.03, i * 0.25);
const line = this.mesh(new THREE.BoxGeometry(0.3, 0.016, 0.045), hatch);
line.position.set(i * 0.16, height / 2 + 0.03, 0.68);
line.rotation.y = Math.PI / 4;
terrainGroup.add(line);
group.add(line);
}
}
// Keep the foreground clear for pieces instead of burying them in trees/peaks.
if (!exhausted && !s.strategyMap && !cityPositions.has(position)) {
if (!s.strategyMap && !cityPositions.has(position)) {
this.addTerrain(terrainGroup, kind, position.charCodeAt(0));
if (unitPositions.has(position) && (kind === 'Forest' || kind === 'Mountain')) {
terrainGroup.scale.set(0.8, 0.65, 0.6);

View file

@ -0,0 +1,46 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import { terrainDisplay } from './terrain-display.ts';
import { strategyTiles, strategyDescription } from './strategy.ts';
import type { Terrain } from './types.ts';
const engine = createRequire(import.meta.url)('../.engine/server.js');
for (const kind of ['Forest', 'Mountain', 'Fertile', 'Barren'] as const) {
test(`exhausted ${kind} keeps its visual identity and separate exhaustion state`, () => {
const terrain: Terrain = { Exhausted: kind };
const normal = terrainDisplay(kind);
assert.deepEqual(terrainDisplay(terrain), { ...normal, exhausted: true });
assert.equal(normal.prominent, kind === 'Forest' || kind === 'Mountain');
const [tile] = strategyTiles({ map: { tiles: [['A1', terrain]] }, players: [] });
assert.deepEqual(tile.terrain, terrain);
assert.equal(strategyDescription(tile), `Exhausted ${kind.toLowerCase()}`);
});
}
test('exhausted terrain stays wrapped in the engine projection and cannot collect or found', async () => {
const game = JSON.parse(await engine.init(2, [], {}, 'exhausted-display', {}));
const seat = game.current_player_index;
const project = () => {
const raw = engine.stripSecret(JSON.stringify(game), seat);
return { raw, view: JSON.parse(engine.webView(raw, seat)) };
};
const city = project().view.cities[0];
const choice = city.choices.find((c: any) => c.position !== city.position);
assert.ok(choice, 'fixture has a collectable neighboring terrain');
const tile = game.map.tiles.find(([p]: [string]) => p === choice.position);
const original = tile[1];
tile[1] = { Exhausted: original };
const settler = game.players[seat].units.find((u: any) => u.unit_type === 'Settler');
settler.position = tile[0];
const { raw, view } = project();
assert.deepEqual(JSON.parse(raw).map.tiles.find(([p]: [string]) => p === tile[0])[1], tile[1]);
assert.ok(view.cities.every((c: any) => c.choices.every((option: any) => option.position !== tile[0])));
const unit = view.settlers.find((u: any) => u.id === settler.id);
assert.ok(unit);
assert.equal(unit.foundAction, null);
assert.throws(() =>
engine.webCollectPreview(raw, seat, city.position, JSON.stringify([{ ...choice, times: 1 }])),
);
});

View file

@ -0,0 +1,8 @@
import type { Terrain } from './types.ts';
/** Visual identity only: never use the unwrapped kind for action legality. */
export function terrainDisplay(terrain: Terrain) {
const exhausted = typeof terrain !== 'string';
const kind = exhausted ? terrain.Exhausted : terrain;
return { kind, exhausted, prominent: kind === 'Forest' || kind === 'Mountain' };
}

View file

@ -1,5 +1,6 @@
import { Compass, LandPlot, Mountain, Trees, Waves, Wheat } from 'lucide-svelte';
import type { Terrain } from './types';
import { terrainDisplay } from './terrain-display';
const terrains = {
Forest: { Icon: Trees, color: '#82a67d' },
@ -11,8 +12,7 @@ const terrains = {
};
export function terrainInfo(terrain: Terrain) {
const exhausted = typeof terrain !== 'string';
const name = exhausted ? terrain.Exhausted : terrain;
const { kind: name, exhausted } = terrainDisplay(terrain);
return {
...(terrains[name as keyof typeof terrains] ?? terrains.Barren),
label: exhausted ? `Exhausted ${name.toLowerCase()}` : name,