Show resource gain icons for bartering and research rewards

This commit is contained in:
coyotte508 2026-10-14 22:30:05 +02:00
commit 1bad2d616a
9 changed files with 56 additions and 13 deletions

View file

@ -351,3 +351,5 @@ Viewer 0.1.115 / engine 0.4.84 separates the natural influence die roll from adv
Viewer 0.1.116 / engine 0.4.85 shortens influence roll bonuses to “rolls a 2 (+1)”.
Viewer 0.1.117 makes hover more audible, sustains action sounds longer, and adds battle-roll, unit-loss and ship-sinking cues. Action sounds wait for browser audio to resume and respect mute cancellation. Adds a local-only sound tester. Engine remains 0.4.85.
Viewer 0.1.118 shows floating resource icons for bartering, research rewards and other gains without a map origin. City and collection gains retain their map locations; other rewards identify the civilization without inventing a city. Storage waste is excluded. Engine remains 0.4.85.

View file

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

View file

@ -22,11 +22,13 @@
<div
class="resource-gain-badge"
class:global-gain={!markers[0].position}
class:rise={animate}
class:transient
role="img"
aria-label={`${civilization}: gained ${markers.map((m) => `${m.amount} ${resourceNames[m.resource].toLowerCase()}`).join(', ')} at ${markers[0].position}`}
aria-label={`${civilization}: gained ${markers.map((m) => `${m.amount} ${resourceNames[m.resource].toLowerCase()}`).join(', ')}${markers[0].position ? ` at ${markers[0].position}` : ''}`}
>
{#if !markers[0].position}<span class="gain-civilization">{civilization}</span>{/if}
{#each markers as marker}
{@const Icon = icons[marker.resource]}
<span class="gain {marker.resource}"

View file

@ -258,7 +258,7 @@ export function frameDetails(
}
}
const resources = frameResources(game, before.cursor, frame);
for (const marker of resources.markers) positions.add(marker.position);
for (const marker of resources.markers) if (marker.position) positions.add(marker.position);
for (const gain of resources.gains) {
const player = frame.players.find((p) => p.id === gain.player)?.civilization;
const gained = describeResources(gain.pile),

View file

@ -6,7 +6,7 @@ import { playerColor, type Session } from './types';
import type { ResourceMarker } from './resource-playback';
export class ResourceOverlay {
private nodes: { node: HTMLDivElement; at: THREE.Vector3; component: ReturnType<typeof mount> }[] = [];
private nodes: { node: HTMLDivElement; at: THREE.Vector3 | null; component: ReturnType<typeof mount> }[] = [];
private timer: ReturnType<typeof setTimeout> | undefined;
private host: HTMLDivElement;
constructor(parent: HTMLElement) {
@ -31,7 +31,7 @@ export class ResourceOverlay {
for (const group of groups.values()) {
const { player, position } = group[0];
const node = document.createElement('div');
node.dataset.position = position;
if (position) node.dataset.position = position;
Object.assign(node.style, { position: 'absolute', left: '0', top: '0', visibility: 'hidden' });
node.style.setProperty('--gain-player', playerColor(player, s.colorBlind, s.playerColors));
this.host.append(node);
@ -44,13 +44,19 @@ export class ResourceOverlay {
civilization: s.game?.players.find((p) => p.id === player)?.civilization ?? 'Player',
},
});
const [x, z] = positionXY(position);
this.nodes.push({ node, component, at: new THREE.Vector3(x, 1.3, z) });
const [x, z] = position ? positionXY(position) : [0, 0];
this.nodes.push({ node, component, at: position ? new THREE.Vector3(x, 1.3, z) : null });
}
if (!s.playback && markers.length) this.timer = setTimeout(() => this.clear(), 2300);
}
project(camera: THREE.Camera, width: number, height: number) {
let screenRow = 0;
for (const { node, at } of this.nodes) {
if (!at) {
node.style.transform = `translate(${width / 2}px,${Math.min(height * 0.45, 240) + screenRow++ * 55}px)`;
node.style.visibility = 'visible';
continue;
}
const p = at.clone().project(camera);
node.style.transform = `translate(${((p.x + 1) * width) / 2}px,${((1 - p.y) * height) / 2}px)`;
node.style.visibility = p.z < -1 || p.z > 1 ? 'hidden' : 'visible';

View file

@ -102,3 +102,13 @@
animation: none;
}
}
.resource-gain-badge.global-gain {
max-width: calc(100vw - 40px);
flex-wrap: wrap;
justify-content: center;
}
.gain-civilization {
font-size: 12px;
color: var(--muted);
}

View file

@ -192,7 +192,7 @@ test('a prior event trigger cannot anchor later event rewards to the initiating
]);
const result = frameResources(game, 1, game.board_history!.frames[2]);
assert.equal(describeResources(result.gains[0].pile), '1 food');
assert.deepEqual(result.markers, []);
assert.deepEqual(result.markers, [{ player: 1, resource: 'food', amount: 1 }]);
});
test('exploration orientation and ship landing are one move; unrelated movement responses stay separate', () => {
@ -301,3 +301,21 @@ test('phase confirmation and age bookkeeping without consequences do not offer r
assert.equal(sinceLastTurn(game, 0), null);
assert.equal(recapStart(game, 0), null);
});
test('bartering and research rewards show unanchored icons with actual gains, excluding payments and waste', () => {
const game = fixture([
{ player: 1, action: { Playing: { Custom: { action: 'Bartering' } } }, items: [
{ player: 1, Resources: { balance: 'Pay', resources: { food: 2 } } },
gain({ gold: 2 }, 'Bartering'),
{ player: 1, origin: { Ability: 'Waste' }, Resources: { balance: 'Loss', resources: { gold: 1 } } },
] },
{ player: 1, action: { Playing: { Advance: { advance: 'Arts' } } }, items: [
gain({ mood_tokens: 1, ideas: 1 }, 'Advance'),
] },
] as LoggedAction[]);
assert.deepEqual(frameResources(game, 0, game.board_history!.frames[1]).markers,
[{ player: 1, resource: 'gold', amount: 1 }]);
assert.deepEqual(frameResources(game, 1, game.board_history!.frames[2]).markers,
[{ player: 1, resource: 'ideas', amount: 1 }, { player: 1, resource: 'mood_tokens', amount: 1 }]);
});

View file

@ -3,7 +3,7 @@ import { resources, resourceNames, type BoardFrame, type Game, type Pile, type R
export interface ResourceMarker {
player: number;
position: string;
position?: string;
resource: Resource;
amount: number;
}
@ -65,14 +65,15 @@ export function frameResources(
totals.set(gain.player, total);
const pool = { ...gain.pile };
const cities = frame.players.find((p) => p.id === gain.player)?.cities ?? [];
if (action.items?.some((item) => item.origin?.Incident !== undefined)) continue;
const place = (position: string, resource: Resource, requested: number) => {
const amount = Math.min(requested, pool[resource] ?? 0);
if (amount <= 0 || !frame.tiles.some(([p]) => p === position)) return;
markers.push({ player: gain.player, position, resource, amount });
pool[resource] = pool[resource]! - amount;
};
const ownRoot = rootPlayer === undefined || rootPlayer === gain.player ? root : null;
const eventReward = interrupted || action.items?.some((item) => item.origin?.Incident !== undefined);
const ownRoot = !eventReward && (rootPlayer === undefined || rootPlayer === gain.player) ? root : null;
const custom = ownRoot?.Custom as { action?: string; city?: string } | undefined;
const taxes =
custom?.action === 'Taxes' ||
@ -101,6 +102,10 @@ export function frameResources(
(ownRoot?.Construct as { city_position?: string } | undefined)?.city_position;
if (city && cities.some((c) => c.position === city))
for (const r of resources) place(city, r, pool[r] ?? 0);
for (const resource of resources) {
const amount = pool[resource] ?? 0;
if (amount > 0) markers.push({ player: gain.player, resource, amount });
}
}
if (interrupted) root = null;
}