Render buildings in their owner's civilization; release viewer 0.1.219
This commit is contained in:
parent
3f818d5b24
commit
a6436f3979
12 changed files with 440 additions and 13 deletions
|
|
@ -1441,3 +1441,33 @@ Integration also repairs the stale revision-2 achievement test on main to check
|
|||
the already-shipped revision-3 catalog and both artwork sets. The artwork input
|
||||
lockfile hash is refreshed solely for the viewer version bump; dependencies and
|
||||
artwork bytes are unchanged. No achievement publication is performed.
|
||||
|
||||
# Viewer 0.1.219 / engine unchanged (0.4.152)
|
||||
|
||||
Every city building, including waterfront Ports, uses its actual owner's normal
|
||||
civilization model and material palette, rather than the host city's architecture.
|
||||
City centers, city flags, same-owner buildings, ships and placement are unchanged.
|
||||
Strategy view shows foreign buildings using their owner-colored icons; no extra
|
||||
on-board civilization text, outlines or flags are added. City hover details name
|
||||
only foreign building owners (for example, “Temple · Greece”), including Ports;
|
||||
same-owner buildings remain uncluttered. Owner lookup uses player IDs, with a safe
|
||||
host-city fallback for missing owners. No prototype URL switches remain.
|
||||
|
||||
This is viewer-only: preserve the deployed 0.4.152 engine URL and bytes. Publish
|
||||
without `--engine`, preserving achievements, real-game gallery, preferences,
|
||||
settings, tutorial and game-length labels/order/default Standard. No live moves,
|
||||
history repairs, Fossil refresh, or unrelated rules changes are included. The
|
||||
artwork manifest's lockfile hash changes only for the viewer version bump.
|
||||
|
||||
Regression coverage includes owner lookup and malformed IDs, actual Temple,
|
||||
Academy and Port geometry/indices/material equality with normal Greek models
|
||||
(and inequality with Roman models), all six Port orientations, city and water-route
|
||||
picking, a four-ship harbor, plus built-viewer desktop/mobile 3D and Strategy hover
|
||||
ownership and same-owner controls. These fixtures are isolated from live games
|
||||
and do not replace the public gallery.
|
||||
|
||||
Verified locally: 1,081 frontend tests, four gallery tests, 19 achievement checks
|
||||
(two existing artifact-dependent skips), both clients' 17-locale catalogs and
|
||||
extraction, Svelte with zero errors/warnings, and production build. Ownership
|
||||
browser checks also verify every building kind and English/German hover names;
|
||||
existing tile-hover, structure-owner and split-WASM bundle checks pass.
|
||||
|
|
|
|||
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.218",
|
||||
"version": "0.1.219",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.218",
|
||||
"version": "0.1.219",
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.11.0",
|
||||
"lucide-svelte": "^0.577.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.218",
|
||||
"version": "0.1.219",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -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": "b0e8fd2588eb68322b9f06345b95f3ee0c5f6549cee0caee0d2c97dc622d84e5",
|
||||
"web-client/package-lock.json": "23509d56dafcaa64bd51adec9d0889b07c73b73699e114e14984d06f3dfcc628",
|
||||
"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"
|
||||
|
|
|
|||
128
web-client/scripts/building-owner-hover-smoke.mjs
Normal file
128
web-client/scripts/building-owner-hover-smoke.mjs
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { createRequire } from 'node:module';
|
||||
import { chromium } from 'playwright';
|
||||
|
||||
// Offline fixture only; optionally verify downloaded production viewer assets.
|
||||
const engine = createRequire(import.meta.url)('../.engine/server.js');
|
||||
let raw = await engine.init(2, [], { civilization: 'ChooseCivilization' }, 'foreign-owner-hover', {});
|
||||
for (const civ of ['Rome', 'Greece'])
|
||||
raw = engine.tryMove(raw, JSON.stringify({ ChooseCivilization: civ }), engine.currentPlayer(raw));
|
||||
const game = JSON.parse(raw);
|
||||
game.map.tiles = [];
|
||||
for (const col of ['C', 'D', 'E'])
|
||||
for (let row = 3; row <= 5; row++) game.map.tiles.push([col + row, col === 'E' ? 'Water' : 'Fertile']);
|
||||
for (const player of game.players) {
|
||||
player.cities = [];
|
||||
player.units = [];
|
||||
}
|
||||
game.players[0].civilization = 'Rome';
|
||||
game.players[1].civilization = 'Greece';
|
||||
game.players[0].cities = [
|
||||
{
|
||||
position: 'D4',
|
||||
mood_state: 'Happy',
|
||||
city_pieces: { academy: 1, fortress: 0, port: 1, temple: 1 },
|
||||
port_position: 'E4',
|
||||
},
|
||||
{ position: 'C3', mood_state: 'Happy', city_pieces: { temple: 0 } },
|
||||
];
|
||||
game.players[0].units = Array.from({ length: 4 }, (_, id) => ({ id, unit_type: 'Ship', position: 'E4' }));
|
||||
raw = engine.stripSecret(JSON.stringify(game), 0);
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
args: ['--use-gl=angle', '--use-angle=swiftshader'],
|
||||
});
|
||||
try {
|
||||
for (const width of [1400, 390]) {
|
||||
const page = await browser.newPage({ viewport: { width, height: 900 } });
|
||||
const errors = [],
|
||||
sent = [];
|
||||
page.on('pageerror', (e) => errors.push(e.message));
|
||||
await page.exposeFunction('moveSent', (a) => sent.push(a));
|
||||
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|[a-z-]+.json)$/.test(path)) return route.abort();
|
||||
const body = process.env.VIEWER_URL
|
||||
? Buffer.from(await (await fetch(new URL(path.slice(1), process.env.VIEWER_URL))).arrayBuffer())
|
||||
: await readFile(new URL('../dist' + path, import.meta.url));
|
||||
return route.fulfill({
|
||||
contentType: path.endsWith('.wasm')
|
||||
? 'application/wasm'
|
||||
: path.endsWith('.json')
|
||||
? 'application/json'
|
||||
: 'text/javascript',
|
||||
body,
|
||||
});
|
||||
});
|
||||
await page.goto('http://clash.test/'); // No prototype switches.
|
||||
await page.evaluate((raw) => {
|
||||
window.host = clash3d.launch('#app');
|
||||
window.prefs = { sound: false };
|
||||
host.on('move', (a) => window.moveSent(a));
|
||||
host.on('update:preference', ({ name, value }) => {
|
||||
prefs[name] = value;
|
||||
host.emit('preferences', prefs);
|
||||
});
|
||||
host.emit('player', { index: 1 }); // Foreign relative to city, not viewer.
|
||||
host.emit('preferences', prefs);
|
||||
host.emit('state', raw);
|
||||
}, raw);
|
||||
for (const strategy of [false, true]) {
|
||||
if (strategy) await page.getByRole('button', { name: 'Strategy map', exact: true }).click();
|
||||
const tile = strategy
|
||||
? page.locator('.strategy-map-tile[data-position="D4"]')
|
||||
: page.getByRole('button', { name: /Select Rome city D4/ });
|
||||
await page.keyboard.press('Tab');
|
||||
await tile.focus();
|
||||
const tooltip = page.locator('.tile-hover:visible');
|
||||
await tooltip.waitFor();
|
||||
const text = await tooltip.innerText();
|
||||
for (const name of ['Academy', 'Port', 'Temple'])
|
||||
assert.match(text, new RegExp(`${name}\\s*·\\s*Greece`));
|
||||
assert.match(text, /Rome city.*D4/s);
|
||||
assert.match(text, /Happy/);
|
||||
assert.doesNotMatch(text, /Fortress\s*·/);
|
||||
assert.doesNotMatch(await tile.innerText(), /Greece/, 'No on-board civilization labels');
|
||||
await page.screenshot({ path: `/tmp/clash-owner-hover-${strategy ? 'strategy' : '3d'}-${width}.png` });
|
||||
await page.evaluate(() => {
|
||||
prefs.locale = 'de';
|
||||
host.emit('preferences', prefs);
|
||||
});
|
||||
await page.waitForFunction(() =>
|
||||
/Griechenland/.test(document.querySelector('.tile-hover')?.textContent ?? ''),
|
||||
);
|
||||
assert.match(await tooltip.innerText(), /Tempel\s*·\s*Griechenland/);
|
||||
await page.evaluate(() => {
|
||||
prefs.locale = 'en';
|
||||
host.emit('preferences', prefs);
|
||||
});
|
||||
await page.waitForFunction(() =>
|
||||
/Temple/.test(document.querySelector('.tile-hover')?.textContent ?? ''),
|
||||
);
|
||||
await page.keyboard.press('Escape');
|
||||
const control = strategy
|
||||
? page.locator('.strategy-map-tile[data-position="C3"]')
|
||||
: page.getByRole('button', { name: /Select Rome city C3/ });
|
||||
await page.keyboard.press('Tab');
|
||||
await control.focus();
|
||||
await tooltip.waitFor();
|
||||
assert.match(await tooltip.innerText(), /Temple/);
|
||||
assert.doesNotMatch(await tooltip.innerText(), /Temple\s*·|Greece/);
|
||||
await page.keyboard.press('Escape');
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
assert.deepEqual(sent, [], 'Inspection must not send gameplay moves');
|
||||
await page.close();
|
||||
}
|
||||
console.log(
|
||||
'Foreign building hover: default production viewer, 3D/Strategy, desktop/mobile keyboard accessibility, foreign Temple/Academy/Port and same-owner control passed.',
|
||||
);
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
193
web-client/scripts/building-owner-smoke.mjs
Normal file
193
web-client/scripts/building-owner-smoke.mjs
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { createRequire } from 'node:module';
|
||||
import { createServer } from 'vite';
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
||||
import { chromium } from 'playwright';
|
||||
|
||||
// Isolated render/picking fixture: no preview saves, API, or live game mutations.
|
||||
const root = new URL('..', import.meta.url).pathname;
|
||||
const engine = createRequire(import.meta.url)('../.engine/server.js');
|
||||
const entry = `
|
||||
import {World} from '${root}/src/board.ts';
|
||||
import {Controller} from '${root}/src/controller.ts';
|
||||
import {get} from 'svelte/store';
|
||||
import * as THREE from 'three';
|
||||
import {PieceModels} from '${root}/src/piece-models.ts';
|
||||
import {playerColor} from '${root}/src/types.ts';
|
||||
import '${root}/src/style.css';
|
||||
let world, session;
|
||||
window.showHarbor=(game,view)=>{
|
||||
if(world)world.destroy();
|
||||
session={...get(new Controller({},new URL(location.href)).session),game,view,seat:0};
|
||||
world=new World(document.querySelector('#app'),(position,pick)=>window.lastPick={position,pick});
|
||||
world.update(session);
|
||||
};
|
||||
window.zoomHarbor=()=>{for(let i=0;i<4;i++)world.zoom(.75);};
|
||||
window.changeMode=(patch)=>{session={...session,...patch};world.update(session)};
|
||||
window.harbor=()=>{
|
||||
world.scene.updateMatrixWorld(true); world.camera.updateMatrixWorld();
|
||||
const dock=world.pieces.find(p=>p.userData.building==='port');
|
||||
const box=new THREE.Box3().setFromObject(dock);
|
||||
const point=dock.localToWorld(new THREE.Vector3(-.08,.19,-.05)).project(world.camera);
|
||||
const rect=world.renderer.domElement.getBoundingClientRect();
|
||||
const x=rect.left+(point.x+1)*rect.width/2,y=rect.top+(1-point.y)*rect.height/2;
|
||||
return {ports:world.pieces.filter(p=>p.userData.building==='port').length,
|
||||
position:dock.position.toArray(),rotation:dock.rotation.y,data:dock.userData,
|
||||
bounds:{min:box.min.toArray(),max:box.max.toArray()},point:{x,y},hit:world.hitTarget(x,y)};
|
||||
};
|
||||
window.shipCount=()=>world.pieces.filter(p=>p.userData.ship).length;
|
||||
window.modelProof=(kinds=['port','temple','academy'])=>{
|
||||
const models=new PieceModels(c=>new THREE.MeshStandardMaterial({color:c}),(g,m)=>new THREE.Mesh(g,m));
|
||||
const fingerprint=o=>{const result=[];o.traverse(n=>{if(n.isMesh)result.push({geometry:n.geometry.type,vertices:Array.from(n.geometry.attributes.position.array),indices:n.geometry.index?Array.from(n.geometry.index.array):null,color:n.material.color.getHexString(),position:n.position.toArray(),rotation:n.rotation.toArray(),scale:n.scale.toArray()});});return JSON.stringify(result)};
|
||||
return kinds.map(kind=>{
|
||||
const actual=kind==='port'?world.pieces.find(p=>p.userData.building==='port').children[0]:world.buildings.get('D4:building:'+kind);
|
||||
const cityModel=models.building(kind,playerColor(1,session.colorBlind,session.playerColors),'Rome');
|
||||
const normal=models.building(kind,playerColor(1,session.colorBlind,session.playerColors),'Greece');
|
||||
return {kind,name:actual.name,matchesNormalOwner:fingerprint(actual)===fingerprint(normal), differsFromCity:fingerprint(actual)!==fingerprint(cityModel)};
|
||||
});
|
||||
};
|
||||
window.ready=true;`;
|
||||
const server = await createServer({
|
||||
root,
|
||||
configFile: false,
|
||||
publicDir: false,
|
||||
plugins: [
|
||||
svelte(),
|
||||
{
|
||||
name: 'isolated-port-fixture',
|
||||
resolveId(id) {
|
||||
if (id === '/ports-smoke-entry.js') return '\0ports-entry';
|
||||
},
|
||||
load(id) {
|
||||
if (id === '\0ports-entry') return entry;
|
||||
},
|
||||
configureServer(server) {
|
||||
server.middlewares.use(async (req, res, next) => {
|
||||
if (req.url.split('?')[0] !== '/harbor' && req.url !== '/pirates') return next();
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
const script =
|
||||
req.url.split('?')[0] === '/harbor'
|
||||
? '<script type="module" src="/ports-smoke-entry.js"></script>'
|
||||
: '<script src="/dist/viewer.js"></script>';
|
||||
res.end(
|
||||
await server.transformIndexHtml(
|
||||
req.url,
|
||||
'<!doctype html><meta name="viewport" content="width=device-width,initial-scale=1"><style>body{margin:0}#app{height:100vh;width:100vw}</style><div class="play-layout"><div id="app"></div></div>' +
|
||||
script,
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
},
|
||||
],
|
||||
server: { host: '127.0.0.1', port: 0 },
|
||||
});
|
||||
await server.listen();
|
||||
const origin = server.resolvedUrls.local[0].replace(/\/$/, '');
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
args: ['--use-gl=angle', '--use-angle=swiftshader'],
|
||||
});
|
||||
try {
|
||||
const page = await browser.newPage({ viewport: { width: 1000, height: 800 } });
|
||||
const errors = [];
|
||||
page.on('pageerror', (e) => errors.push(e.message));
|
||||
await page.goto(origin + '/harbor');
|
||||
await page.waitForFunction(() => window.ready);
|
||||
let state = await engine.init(2, [], { civilization: 'ChooseCivilization' }, 'port-shoreline', {});
|
||||
for (const civ of ['Vikings', 'Rome'])
|
||||
state = engine.tryMove(state, JSON.stringify({ ChooseCivilization: civ }), engine.currentPlayer(state));
|
||||
const game = JSON.parse(state);
|
||||
game.map.tiles = [];
|
||||
for (const col of ['B', 'C', 'D', 'E', 'F'])
|
||||
for (let row = 2; row <= 6; row++) game.map.tiles.push([col + row, 'Water']);
|
||||
game.map.tiles.find(([p]) => p === 'D4')[1] = 'Fertile';
|
||||
for (const p of game.players) {
|
||||
p.cities = [];
|
||||
p.units = [];
|
||||
}
|
||||
game.players[0].civilization = 'Rome';
|
||||
game.players[1].civilization = 'Greece';
|
||||
const me = game.players[0];
|
||||
const city = {
|
||||
position: 'D4',
|
||||
mood_state: 'Happy',
|
||||
city_pieces: { port: 1, temple: 1, academy: 1, fortress: 0 },
|
||||
port_position: 'E4',
|
||||
};
|
||||
me.cities = [city];
|
||||
for (const water of ['C4', 'C5', 'D3', 'D5', 'E4', 'E5']) {
|
||||
city.port_position = water;
|
||||
me.units = [{ id: 0, unit_type: 'Ship', position: water }];
|
||||
await page.evaluate(({ game, view }) => window.showHarbor(game, view), {
|
||||
game,
|
||||
view: JSON.parse(engine.webView(engine.stripSecret(JSON.stringify(game), 0), 0)),
|
||||
});
|
||||
await page.waitForTimeout(200);
|
||||
const proof = await page.evaluate(() => window.modelProof());
|
||||
assert.ok(
|
||||
proof.every((p) => p.matchesNormalOwner && p.differsFromCity),
|
||||
JSON.stringify(proof),
|
||||
);
|
||||
const info = await page.evaluate(() => window.harbor());
|
||||
assert.equal(info.ports, 1);
|
||||
assert.equal(info.data.position, water);
|
||||
assert.equal(info.data.cityPosition, 'D4');
|
||||
assert.equal(info.position[1], 0.01, 'Wharf sits on the water surface');
|
||||
assert.equal(info.hit.position, 'D4', 'Dock opens the owning city');
|
||||
assert.equal(info.hit.pick.kind, 'city');
|
||||
await page.mouse.click(info.point.x, info.point.y);
|
||||
assert.equal((await page.evaluate(() => window.lastPick)).position, 'D4');
|
||||
await page.evaluate(() => window.changeMode({ tilePanel: true, focus: 'D4' }));
|
||||
assert.equal(
|
||||
(await page.evaluate(() => window.harbor())).hit.position,
|
||||
'D4',
|
||||
'Open inspection still opens the city',
|
||||
);
|
||||
await page.evaluate(() => window.changeMode({ tilePanel: false, seaRoutes: true }));
|
||||
assert.equal(
|
||||
(await page.evaluate(() => window.harbor())).hit.position,
|
||||
water,
|
||||
'Sea guide picks the water under the wharf',
|
||||
);
|
||||
await page.evaluate(() => window.changeMode({ seaRoutes: false, topDown: true }));
|
||||
await page.waitForTimeout(100);
|
||||
await page.screenshot({ path: `/tmp/clash-port-${water}.png` });
|
||||
}
|
||||
city.port_position = 'E4';
|
||||
me.units = Array.from({ length: 4 }, (_, id) => ({ id, unit_type: 'Ship', position: 'E4' }));
|
||||
await page.evaluate(({ game, view }) => window.showHarbor(game, view), {
|
||||
game,
|
||||
view: JSON.parse(engine.webView(engine.stripSecret(JSON.stringify(game), 0), 0)),
|
||||
});
|
||||
await page.waitForTimeout(200);
|
||||
await page.evaluate(() => window.zoomHarbor());
|
||||
await page.waitForTimeout(100);
|
||||
await page.screenshot({ path: '/tmp/clash-port-fleet.png' });
|
||||
await page.evaluate(() => window.changeMode({ topDown: true }));
|
||||
await page.waitForTimeout(200);
|
||||
await page.evaluate(() => window.zoomHarbor());
|
||||
await page.waitForTimeout(100);
|
||||
await page.screenshot({ path: '/tmp/clash-port-fleet-overhead.png' });
|
||||
assert.equal(await page.evaluate(() => window.shipCount()), 4);
|
||||
for (const kind of ['academy', 'market', 'obelisk', 'observatory', 'fortress', 'temple']) {
|
||||
city.city_pieces = { port: 1, [kind]: 1 };
|
||||
await page.evaluate(({ game, view }) => window.showHarbor(game, view), {
|
||||
game,
|
||||
view: JSON.parse(engine.webView(engine.stripSecret(JSON.stringify(game), 0), 0)),
|
||||
});
|
||||
const proof = await page.evaluate((kind) => window.modelProof([kind, 'port']), kind);
|
||||
assert.ok(
|
||||
proof.every((p) => p.matchesNormalOwner),
|
||||
JSON.stringify(proof),
|
||||
);
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
await page.close();
|
||||
console.log(
|
||||
'Owner-model equality (Port/Temple/Academy): passed. Foreign Port: all six shores, city picking, sea-route picking and four-ship fleet passed.',
|
||||
);
|
||||
} finally {
|
||||
await browser.close();
|
||||
await server.close();
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
<script lang="ts">
|
||||
import { Swords, Ship, Footprints, Landmark, Shield, Skull, Smile, Meh, Frown } from 'lucide-svelte';
|
||||
import { buildingInfo } from './city';
|
||||
import BarbarianIcon from './BarbarianIcon.svelte';
|
||||
import TerrainIcon from './TerrainIcon.svelte';
|
||||
import { playerColor, playerSymbol } from './types';
|
||||
|
|
@ -39,6 +40,16 @@
|
|||
title={occupant.city.mood_state}><Mood size={17} aria-hidden="true" /></span
|
||||
>{/if}</span
|
||||
>{/if}
|
||||
{#if occupant.city}
|
||||
{#each Object.entries(occupant.city.city_pieces ?? {}) as [building, owner]}
|
||||
{@const info = buildingInfo[building[0].toUpperCase() + building.slice(1)]}
|
||||
{#if typeof owner === 'number' && owner !== occupant.player.id && info}
|
||||
<span class="foreign-building-icon" style={`color:${playerColor(owner, colorBlind, playerColors)}`}>
|
||||
<info.icon size={17} />
|
||||
</span>
|
||||
{/if}
|
||||
{/each}
|
||||
{/if}
|
||||
{#if occupant.army || occupant.ships || occupant.settlers}<span class="strategy-forces">
|
||||
{#if occupant.army - occupant.aboard > 0}<span
|
||||
>{#if occupant.player.civilization === 'Barbarians'}<BarbarianIcon size={18} />{:else}<Swords
|
||||
|
|
|
|||
|
|
@ -24,9 +24,12 @@
|
|||
>{/if}
|
||||
{#if $data.city}
|
||||
<div class="tile-hover-buildings">
|
||||
{#each $data.city.buildings as name}
|
||||
{#each $data.city.buildings as { name, civilization }}
|
||||
{@const Icon = buildingInfo[name]?.icon ?? Landmark}
|
||||
<span><Icon size={14} />{name}</span>
|
||||
<span
|
||||
><Icon size={14} />{name}{#if civilization}
|
||||
· {civilization}{/if}</span
|
||||
>
|
||||
{/each}
|
||||
{#each $data.city.wonders as name}<span><Star size={14} />{name}</span>{/each}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { explorationPreview } from './exploration-preview';
|
|||
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
||||
import type { Session, Terrain } from './types';
|
||||
import { playerColor, playerSymbol } from './types';
|
||||
import { buildingCivilization } from './building-owner';
|
||||
import { positionXY } from './model';
|
||||
import { terrainInfo } from './terrain';
|
||||
import { PieceModels, type BuildingKind } from './piece-models';
|
||||
|
|
@ -1394,7 +1395,7 @@ export class World {
|
|||
const annex = models.building(
|
||||
name,
|
||||
playerColor(buildingOwner, s.colorBlind, s.playerColors),
|
||||
player.civilization,
|
||||
buildingCivilization(buildingOwner, player, s.game.players),
|
||||
);
|
||||
const place = layout.buildings[j];
|
||||
annex.scale.setScalar(place.scale);
|
||||
|
|
@ -1423,7 +1424,7 @@ export class World {
|
|||
const port = models.building(
|
||||
'port',
|
||||
playerColor(city.city_pieces.port, s.colorBlind, s.playerColors),
|
||||
player.civilization,
|
||||
buildingCivilization(city.city_pieces.port, player, s.game.players),
|
||||
);
|
||||
port.scale.setScalar(portDock.scale);
|
||||
dock.add(port);
|
||||
|
|
|
|||
21
web-client/src/building-owner.test.ts
Normal file
21
web-client/src/building-owner.test.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { buildingCivilization, foreignBuildingCivilization } from './building-owner.ts';
|
||||
|
||||
const rome = { id: 4, civilization: 'Rome' };
|
||||
const greece = { id: 7, civilization: 'Greece' };
|
||||
const barbarians = { id: 12, civilization: 'Barbarians' };
|
||||
const players = [rome, greece, barbarians];
|
||||
test('piece ownership uses player IDs, not viewer seat or array index', () => {
|
||||
assert.equal(buildingCivilization(7, rome, players), 'Greece');
|
||||
assert.equal(buildingCivilization(4, rome, players), 'Rome');
|
||||
assert.equal(buildingCivilization(12, rome, players), 'Barbarians');
|
||||
assert.equal(foreignBuildingCivilization(7, rome, players), 'Greece');
|
||||
assert.equal(foreignBuildingCivilization(4, rome, players), undefined);
|
||||
});
|
||||
test('missing and invalid owners safely retain host architecture without invented hover ownership', () => {
|
||||
for (const owner of [undefined, null, -1, 99, '7', NaN]) {
|
||||
assert.equal(buildingCivilization(owner, rome, players), 'Rome');
|
||||
assert.equal(foreignBuildingCivilization(owner, rome, players), undefined);
|
||||
}
|
||||
});
|
||||
21
web-client/src/building-owner.ts
Normal file
21
web-client/src/building-owner.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import type { Player } from './types';
|
||||
|
||||
type CivilizationOwner = Pick<Player, 'id' | 'civilization'>;
|
||||
|
||||
/** Use the piece owner's normal architecture, including NPCs; tolerate stale owner IDs. */
|
||||
export function buildingCivilization(
|
||||
owner: unknown,
|
||||
cityOwner: CivilizationOwner,
|
||||
players: readonly CivilizationOwner[],
|
||||
): string {
|
||||
return players.find((player) => player.id === owner)?.civilization ?? cityOwner.civilization;
|
||||
}
|
||||
|
||||
/** Only foreign pieces need an owner suffix in city hover details. */
|
||||
export function foreignBuildingCivilization(
|
||||
owner: unknown,
|
||||
cityOwner: CivilizationOwner,
|
||||
players: readonly CivilizationOwner[],
|
||||
): string | undefined {
|
||||
return owner === cityOwner.id ? undefined : players.find((player) => player.id === owner)?.civilization;
|
||||
}
|
||||
|
|
@ -4,12 +4,19 @@ import type { Session, Terrain } from './types';
|
|||
import { tileUnitStacks } from './tile-units';
|
||||
import TileHover from './TileHover.svelte';
|
||||
import { pirateBlockade } from './pirate-blockade';
|
||||
import { foreignBuildingCivilization } from './building-owner';
|
||||
|
||||
export interface TileHoverData {
|
||||
position: string;
|
||||
terrain: Terrain;
|
||||
pirateBlockade: boolean;
|
||||
city?: { owner: number; civilization: string; mood: string; buildings: string[]; wonders: string[] };
|
||||
city?: {
|
||||
owner: number;
|
||||
civilization: string;
|
||||
mood: string;
|
||||
buildings: { name: string; civilization?: string }[];
|
||||
wonders: string[];
|
||||
};
|
||||
stacks: ReturnType<typeof tileUnitStacks>;
|
||||
colorBlind: boolean;
|
||||
playerColors?: string[];
|
||||
|
|
@ -87,10 +94,22 @@ export class TileTooltip {
|
|||
: session.game.players.flatMap((player) => {
|
||||
const city = player.cities?.find((city) => city.position === this.position);
|
||||
return city
|
||||
? [{ owner: player.id, civilization: player.civilization, mood: city.mood_state,
|
||||
buildings: Object.entries(city.city_pieces ?? {}).filter(([key, owner]) => key !== 'wonders' && typeof owner === 'number').map(([key]) => key[0].toUpperCase() + key.slice(1)),
|
||||
wonders: (city.city_pieces?.wonders ?? []).map((id) => session.view?.wonderCatalog?.find((w) => w.id === id)?.name ?? id),
|
||||
}]
|
||||
? [
|
||||
{
|
||||
owner: player.id,
|
||||
civilization: player.civilization,
|
||||
mood: city.mood_state,
|
||||
buildings: Object.entries(city.city_pieces ?? {})
|
||||
.filter(([key, owner]) => key !== 'wonders' && typeof owner === 'number')
|
||||
.map(([key, owner]) => ({
|
||||
name: key[0].toUpperCase() + key.slice(1),
|
||||
civilization: foreignBuildingCivilization(owner, player, session.game!.players),
|
||||
})),
|
||||
wonders: (city.city_pieces?.wonders ?? []).map(
|
||||
(id) => session.view?.wonderCatalog?.find((w) => w.id === id)?.name ?? id,
|
||||
),
|
||||
},
|
||||
]
|
||||
: [];
|
||||
})[0],
|
||||
stacks: terrain === 'Unexplored' ? [] : tileUnitStacks(session.game.players, this.position),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue