Show transported units as 3D pieces beside ships

This commit is contained in:
coyotte508 2026-10-19 11:20:27 +02:00
commit b82b1cb4dc
8 changed files with 58 additions and 18 deletions

View file

@ -423,3 +423,5 @@ Viewer 0.1.151 / engine 0.4.105 separates Carthage Draft payments from leader to
Replay and spectator hex inspection now show public units and buildings from the displayed frame. Transported units remain visible in ship-stack badges and are marked aboard in hex details. The mobile movement heading uses separate control and route rows. Shipping Routes was checked: its objective calculation considers ships independently of settler routes. No historical game data was edited.
Verified with 846 frontend/engine tests, 54 incident/tactics Rust tests, 16 locales, type checking, production build, and 390px browser checks for movement, spectator inspection and historical passenger counts. Printed sources: Carthage board https://boardgamegeek.com/image/7553246 (gold replaces Draft tokens only), Qin card https://boardgamegeek.com/image/9490518 (once per battle), Civil War event scan recorded in docs/card-text-audit.json.
Viewer 0.1.152 renders transported units as individual 3D pieces alongside their ships, with spacing for mixed stacks. Nested and flattened passenger records are deduplicated. Removed the forced passenger badge; normal badge preferences still apply. Verified in a browser with two ships and two passengers, plus 847 frontend tests, locale validation, type checking and production build. Engine remains 0.4.105.

View file

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

View file

@ -7,21 +7,16 @@
symbol,
pirate = false,
barbarian = false,
hasPassengers = false,
}: {
groups: { type: string | { Leader: string }; count: number }[];
symbol: string;
pirate?: boolean;
barbarian?: boolean;
hasPassengers?: boolean;
} = $props();
</script>
{#if symbol}<span class="unit-owner-symbol" aria-hidden="true">{symbol}</span>{/if}
<span class="unit-map-types" aria-hidden="true">
{#if hasPassengers}
{#each groups as group}<UnitIcon type={group.type} size={14} /><b>{group.count}</b>{/each}
{:else}
{#if pirate}<Skull size={14} />{:else if barbarian}<BarbarianIcon
size={14}
/>{:else if groups.length > 1}<Layers2 size={14} />{:else}<UnitIcon
@ -29,5 +24,4 @@
size={14}
/>{/if}
<b>{groups.reduce((sum, group) => sum + group.count, 0)}</b>
{/if}
</span>

View file

@ -1,3 +1,4 @@
import { boardUnits } from './tile-units';
import { RegionOverlay } from './region-overlay';
import { movementWaypoints } from './movement-animation';
import { boardContentSignature } from './board-content';
@ -1284,9 +1285,15 @@ export class World {
const harborDirections = new Map([...portSites.values()].map((port) => [port.water, port.rotation]));
const unitStacks = new Map<string, number>();
const unitsByTile = new Map<string, number>();
for (const player of s.game.players)
for (const unit of player.units ?? [])
const mixedShipTiles = new Set<string>();
const renderedUnits = new Map(s.game.players.map((player) => [player.id, boardUnits(player)]));
const shipTiles = new Set([...renderedUnits.values()].flat().filter((unit) => unit.unit_type === 'Ship').map((unit) => unit.position));
for (const units of renderedUnits.values()) {
for (const unit of units) {
unitsByTile.set(unit.position, (unitsByTile.get(unit.position) ?? 0) + 1);
if (unit.unit_type !== 'Ship' && shipTiles.has(unit.position)) mixedShipTiles.add(unit.position);
}
}
for (const player of s.game.players) {
for (const city of player.cities ?? []) {
const [x, z] = positionXY(city.position);
@ -1497,7 +1504,7 @@ export class World {
),
});
}
for (const unit of player.units ?? []) {
for (const unit of renderedUnits.get(player.id)!) {
const [x, z] = positionXY(unit.position);
const pawn = models.unit(
unit.unit_type,
@ -1542,11 +1549,16 @@ export class World {
ux = 0;
}
const ship = unit.unit_type === 'Ship';
if (ship && count > 1 && count <= 4) {
const mixed = mixedShipTiles.has(unit.position);
if (mixed && count === 2) {
ux = stackIndex ? 0.34 : -0.34;
uz = 0;
}
if (ship && !mixed && count > 1 && count <= 4) {
ux = stackIndex % 2 ? 0.27 : -0.27;
uz = stackIndex < 2 ? 0.36 : -0.36;
}
const harborDirection = ship ? harborDirections.get(unit.position) : undefined;
const harborDirection = ship && !mixed ? harborDirections.get(unit.position) : undefined;
const inHarbor = harborDirection !== undefined && count <= 4;
if (inHarbor) {
// Moor side by side facing away from the wharf, leaving its entrance clear.
@ -1557,6 +1569,8 @@ export class World {
pawn.scale.setScalar(
count > positions.length
? Math.min(0.65, 5.2 / count)
: mixed
? count <= 2 ? 0.75 : 0.6
: inHarbor
? count === 1
? 0.8
@ -1593,7 +1607,7 @@ export class World {
const carried = surfaceUnits.reduce((sum, unit) => sum + (unit.carried_units?.length ?? 0), 0);
const description = `${player.civilization} · ${position}: ${[...counts].map(([name, group]) => `${group.count} ${name}`).join(', ')}${carried ? ` · ${carried} aboard ships` : ''}`;
const label = document.createElement('button');
label.className = `unit-map-label${carried ? ' has-passengers' : ''}`;
label.className = 'unit-map-label';
label.style.setProperty('--player-color', playerColor(player.id, s.colorBlind, s.playerColors));
label.setAttribute('aria-label', `Inspect ${description}`);
this.unitBadges.push(
@ -1601,7 +1615,6 @@ export class World {
target: label,
props: {
groups: [...counts.values()],
hasPassengers: carried > 0,
symbol:
s.colorBlind && !['Pirates', 'Barbarians'].includes(player.civilization)
? playerSymbol(player.id, s.playerSymbols)

View file

@ -3709,7 +3709,7 @@ small {
gap: 3px;
}
.world-labels.hide-unit-badges .unit-map-label:not(.has-passengers) {
.world-labels.hide-unit-badges .unit-map-label {
display: none;
}

View file

@ -1,6 +1,6 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { tileUnitStacks } from './tile-units.ts';
import { boardUnits, tileUnitStacks } from './tile-units.ts';
import type { Player } from './types.ts';
test('tile summaries group units by owner and type, including leaders without internal identifiers', () => {
@ -98,3 +98,18 @@ test('pirate ships retain their identity without marking passengers as pirates',
);
assert.equal(stacks[1].groups[0].pirate, true);
});
test('3D pieces include nested passengers once at their carrier position', () => {
const player: Player = { id: 0, civilization: 'Rome', units: [
{ id: 0, position: 'C3', unit_type: 'Ship', carried_units: [
{ id: 1, unit_type: 'Infantry' }, { id: 2, unit_type: { Leader: 'Augustus' } },
] },
{ id: 1, position: 'B2', unit_type: 'Infantry', carrier_id: 0 },
{ id: 3, position: 'D4', unit_type: 'Settler' },
] };
const units = boardUnits(player);
assert.equal(units.length, 4);
assert.deepEqual(units.filter((unit) => unit.position === 'C3').map((unit) => unit.id).sort(), [0, 1, 2]);
assert.equal(units.find((unit) => unit.id === 2)?.carrier_id, 0);
assert.equal(player.units?.[1].position, 'B2');
});

View file

@ -31,3 +31,19 @@ export function tileUnitStacks(players: Player[], position: string) {
return groups.size ? [{ player, groups: [...groups.values()] }] : [];
});
}
/** Public snapshots may nest passengers, flatten them, or include both. */
export function boardUnits(player: Player): Unit[] {
const units = new Map((player.units ?? []).map((unit) => [unit.id, unit]));
for (const carrier of player.units ?? []) {
for (const passenger of carrier.carried_units ?? []) {
units.set(passenger.id, {
...units.get(passenger.id),
...passenger,
position: carrier.position,
carrier_id: carrier.id,
});
}
}
return [...units.values()];
}