Link played action cards in journal and simplify hand counts
This commit is contained in:
parent
4b02540ff1
commit
fc48b95cdf
10 changed files with 65 additions and 42 deletions
|
|
@ -305,3 +305,5 @@ Viewer 0.1.92 omits empty optional payments from journal prose, including older
|
|||
Viewer 0.1.93 shows public action-card hand counts with a card icon on civilization panels and in civilization details. Counts use the already-redacted public hand arrays; no card identities are exposed. Replay frames without historical hand counts omit the number instead of showing current information. Engine remains 0.4.75.
|
||||
|
||||
Viewer 0.1.94 extends public hand counts to objective cards still in hand and unbuilt wonder cards. Each type has its own icon and tooltip on the player panel and an explicit label in civilization details. These counts exclude completed objectives and built wonders; historical frames without counts do not substitute current hands. Engine remains 0.4.75.
|
||||
|
||||
Viewer 0.1.95 preserves played civil action-card identities in journal payments and results, with an explicit action-card label and an exact-card rules link. Public hand sizes are removed from player tiles and grouped under a compact Cards in hand row in civilization details. Engine remains 0.4.75. Validated with 756 tests, Svelte checks, production build, and desktop/mobile browser checks including opening the played card from the journal.
|
||||
|
|
|
|||
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.94",
|
||||
"version": "0.1.95",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.94",
|
||||
"version": "0.1.95",
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.9.0",
|
||||
"lucide-svelte": "^0.577.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.94",
|
||||
"version": "0.1.95",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -566,7 +566,11 @@
|
|||
<div class="journal-heading">
|
||||
{#if entry.civilization}<strong>{entry.civilization}</strong>{/if}
|
||||
{#if !outcome}<span class:journal-event-title={!!entry.event}
|
||||
>{#if !entry.event}<EntryIcon size={13} aria-hidden="true" />{/if}<ResourceText
|
||||
>{#if !entry.event}<EntryIcon size={13} aria-hidden="true" />{/if}{#if entry.card}<span>Action card · <button
|
||||
class="journal-research-link"
|
||||
title={`View ${printedCardName(entry.card.name)} rules`}
|
||||
onclick={() => showJournalCard({ name: entry.card!.name, card: entry.card! })}
|
||||
>{printedCardName(entry.card.name)}</button></span>{:else}<ResourceText
|
||||
text={entry.event || entry.kind === 'event' ? printedCardName(entry.title) : entry.title}
|
||||
{research}
|
||||
onResearch={showJournalResearch}
|
||||
|
|
@ -574,7 +578,7 @@
|
|||
onCard={showJournalCard}
|
||||
positions={mapPositions}
|
||||
{...coordinateInteraction}
|
||||
/></span
|
||||
/>{/if}</span
|
||||
>{/if}
|
||||
</div>
|
||||
{#if entry.combat}<CombatJournal
|
||||
|
|
@ -899,10 +903,6 @@
|
|||
: null}
|
||||
{@const progressLabel =
|
||||
status === 'current' ? 'Turn in progress' : status === 'left' ? 'Left game' : null}
|
||||
{@const hand = ($session.playback?.frame?.players ?? $session.game?.players ?? []).find(p => p.id === player.index)}
|
||||
{@const handCount = hand?.action_cards?.length ?? (!$session.playback && hand ? 0 : undefined)}
|
||||
{@const objectiveCount = hand?.objective_cards?.length ?? (!$session.playback && hand ? 0 : undefined)}
|
||||
{@const wonderCount = hand?.wonder_cards?.length ?? (!$session.playback && hand ? 0 : undefined)}
|
||||
<button
|
||||
class="player-card"
|
||||
class:active={!!turnLabel}
|
||||
|
|
@ -911,9 +911,6 @@
|
|||
aria-label={[
|
||||
`${translate(player.civilization)}: ${formatPoints(player.score)} ${translate('victory points')}`,
|
||||
player.index === $session.seat ? translate('You') : player.name,
|
||||
handCount !== undefined ? `${translate('Action cards')}: ${handCount}` : '',
|
||||
objectiveCount !== undefined ? `Objective cards in hand: ${objectiveCount}` : '',
|
||||
wonderCount !== undefined ? `Wonder cards in hand: ${wonderCount}` : '',
|
||||
order ? translate(`Turn order ${order}.`).replace(/\.$/u, '') : '',
|
||||
turnLabel ? translate(turnLabel) : '',
|
||||
progressLabel ? translate(progressLabel) : '',
|
||||
|
|
@ -957,11 +954,6 @@
|
|||
title={$session.playerBadges[player.index]!.label}
|
||||
/>{/if}</small
|
||||
><span class="player-events"><EventMarkers remaining={player.eventTokens} /></span>
|
||||
<span class="player-hands">
|
||||
{#if handCount !== undefined}<span class="player-hand-count" title={`Action cards: ${handCount}`} aria-hidden="true"><Layers size={12} />{handCount}</span>{/if}
|
||||
{#if objectiveCount !== undefined}<span class="player-hand-count" title={`Objective cards in hand: ${objectiveCount}`} aria-hidden="true"><Target size={12} />{objectiveCount}</span>{/if}
|
||||
{#if wonderCount !== undefined}<span class="player-hand-count" title={`Wonder cards in hand: ${wonderCount}`} aria-hidden="true"><Landmark size={12} />{wonderCount}</span>{/if}
|
||||
</span>
|
||||
{#if turnLabel || progressLabel}<span class="player-turn" class:round-inactive={!turnLabel}
|
||||
>{#if turnLabel || status === 'current'}<ArrowRight
|
||||
size={12}
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@
|
|||
const hand = $derived(($session.playback?.frame?.players ?? $session.game?.players ?? []).find(p => p.id === player?.index));
|
||||
const handCounts = $derived([
|
||||
{ label: 'Action cards', icon: Layers, count: hand?.action_cards?.length ?? (!$session.playback && hand ? 0 : undefined) },
|
||||
{ label: 'Objective cards in hand', icon: Target, count: hand?.objective_cards?.length ?? (!$session.playback && hand ? 0 : undefined) },
|
||||
{ label: 'Wonder cards in hand', icon: Landmark, count: hand?.wonder_cards?.length ?? (!$session.playback && hand ? 0 : undefined) },
|
||||
{ label: 'Objectives', icon: Target, count: hand?.objective_cards?.length ?? (!$session.playback && hand ? 0 : undefined) },
|
||||
{ label: 'Wonders', icon: Landmark, count: hand?.wonder_cards?.length ?? (!$session.playback && hand ? 0 : undefined) },
|
||||
]);
|
||||
const resources = $derived(
|
||||
Object.fromEntries(
|
||||
|
|
@ -116,7 +116,7 @@
|
|||
<div class="civilization-resources" role="group" aria-label={`${player.civilization} resources`}>
|
||||
<ResourceAmount pile={resources} showZero />
|
||||
</div>
|
||||
<div class="civilization-hands">{#each handCounts as item}{#if item.count !== undefined}<p class="civilization-hand-count"><item.icon size={17} /> {item.label} <strong>{item.count}</strong></p>{/if}{/each}</div>
|
||||
<div class="civilization-hand-summary"><span class="civilization-hand-label">Cards in hand</span><div class="civilization-hands">{#each handCounts as item}{#if item.count !== undefined}<p class="civilization-hand-count"><item.icon size={17} /> {item.label} <strong>{item.count}</strong></p>{/if}{/each}</div></div>
|
||||
<nav class="civilization-tabs" aria-label="Civilization details">
|
||||
<button class:active={tab === 'score'} aria-pressed={tab === 'score'} onclick={() => setTab('score')}
|
||||
><Trophy size={16} /> Score</button
|
||||
|
|
|
|||
|
|
@ -1263,23 +1263,13 @@
|
|||
margin: 0 0 8px;
|
||||
}
|
||||
|
||||
.player-hand-count, .civilization-hand-count {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
.player-hand-count {
|
||||
font-size: 0.75rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
/* Private card identities stay hidden; these are public hand sizes. */
|
||||
.civilization-hand-summary { margin: .25rem 0 1.25rem; }
|
||||
.civilization-hand-label { display: block; color: var(--muted); font-size: .75rem; margin-bottom: .5rem; }
|
||||
.civilization-hands { display: flex; flex-wrap: wrap; gap: .5rem; }
|
||||
.civilization-hand-count {
|
||||
margin: 0 0 1rem;
|
||||
display: flex; align-items: center; gap: .4rem; flex: 1 1 135px;
|
||||
margin: 0; padding: .5rem .65rem; font-size: .8rem;
|
||||
border: 1px solid var(--line); border-radius: 6px; color: var(--muted);
|
||||
}
|
||||
|
||||
.player-hands, .civilization-hands {
|
||||
display: flex;
|
||||
gap: 0.65rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.player-info .player-hands { grid-area: 3 / 1 / 4 / 4; }
|
||||
.player-card .player-info .player-turn { grid-area: 4 / 1 / 5 / 4; }
|
||||
.civilization-hand-count strong { margin-left: auto; color: var(--ink); font-size: .95rem; }
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ function addClause(entry: JournalEntry, clause: string, payments: PaymentLog[]):
|
|||
|
||||
export function journal(
|
||||
game: Game,
|
||||
view?: Pick<View, 'eventCatalog' | 'pendingEvent' | 'players' | 'logOriginNames'>,
|
||||
view?: Pick<View, 'eventCatalog' | 'pendingEvent' | 'players' | 'logOriginNames' | 'cardCatalog'>,
|
||||
): JournalEntry[] {
|
||||
game = readableHistory(game, view);
|
||||
const historicalCities = collectionCities(game);
|
||||
|
|
@ -354,7 +354,8 @@ export function journal(
|
|||
let entry = entries.at(-1);
|
||||
const sameSource =
|
||||
entry &&
|
||||
(entry.title.split(' · ')[0].toLowerCase() === origin?.toLowerCase() ||
|
||||
(entry.title.toLowerCase() === origin?.toLowerCase() ||
|
||||
entry.title.split(' · ')[0].toLowerCase() === origin?.toLowerCase() ||
|
||||
(entry.title === 'Research' &&
|
||||
(origin === 'Advance' ||
|
||||
entry.tokens.some((token) => token.icon === 'research' && token.label === origin))));
|
||||
|
|
@ -387,6 +388,18 @@ export function journal(
|
|||
for (const clause of match[3].split(/,(?!\s*(?:\d|and\b))\s*/))
|
||||
addClause(entry, factionText(game, clause), payments);
|
||||
}
|
||||
for (const entry of entries) {
|
||||
if (!entry.title.startsWith('Action card · ')) continue;
|
||||
const name = entry.title.slice('Action card · '.length);
|
||||
const cardIds = (action.items ?? []).filter(item => item.player === entry.player).flatMap(item => {
|
||||
if (typeof item.origin?.CivilCard === 'number') return [item.origin.CivilCard];
|
||||
const hand = item.HandCard;
|
||||
return hand?.to === 'PlayToDiscard' && hand.card && typeof hand.card === 'object' &&
|
||||
'ActionCard' in hand.card && typeof hand.card.ActionCard === 'number' ? [hand.card.ActionCard] : [];
|
||||
});
|
||||
entry.card = view?.cardCatalog?.find(card => cardIds.includes(card.id) && card.name === name);
|
||||
entry.kind = 'card';
|
||||
}
|
||||
confirmPayments(action, payments, entries);
|
||||
// Nomads and Move log the same city relocation under different origins.
|
||||
// Fold only matching routes within this action and actor; retain gains,
|
||||
|
|
|
|||
|
|
@ -51,3 +51,19 @@ test('declining government change omits the empty payment from the journal', ()
|
|||
assert.doesNotMatch(JSON.stringify(entry), /Pay ,|Pay /);
|
||||
assert.equal(JSON.stringify(game), before);
|
||||
});
|
||||
|
||||
test('played action cards and their research results link to the exact public card', () => {
|
||||
const game = fixture('action_cards/advance.outcome2');
|
||||
const before = JSON.stringify(game);
|
||||
const card = { id: 2, name: 'Advance', description: 'Gain an advance.', free: true, tactics: null };
|
||||
const entries = journal(game, { players: [], cardCatalog: [
|
||||
{ ...card, id: 99 }, card,
|
||||
], logOriginNames: { '{"CivilCard":2}': 'Advance' } });
|
||||
const played = entries.filter(entry => entry.title === 'Action card · Advance');
|
||||
assert.equal(played.length, 3);
|
||||
assert.ok(played.every(entry => entry.kind === 'card' && entry.card?.id === 2));
|
||||
assert.ok(played.some(entry => entry.tokens.some(token => token.value === '−1')));
|
||||
assert.ok(played.some(entry => /Storage/.test(entry.text)));
|
||||
assert.ok(!entries.some(entry => entry.title === 'Action Card'));
|
||||
assert.equal(JSON.stringify(game), before);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { officialWonderText } from './wonder-names.ts';
|
|||
|
||||
type Units = Record<string, number | string>;
|
||||
type Item = NonNullable<LoggedAction['items']>[number];
|
||||
type Context = Pick<View, 'eventCatalog' | 'logOriginNames'>;
|
||||
type Context = Pick<View, 'eventCatalog' | 'logOriginNames' | 'cardCatalog'>;
|
||||
const words = (name: unknown): string =>
|
||||
typeof name === 'string'
|
||||
? name.replace(/([a-z])([A-Z])/g, '$1 $2').replaceAll('_', ' ')
|
||||
|
|
@ -25,6 +25,10 @@ const actor = (game: Game, player: number): string =>
|
|||
function source(item: Item, context?: Context): string {
|
||||
const origin = item.origin ?? {};
|
||||
const label = context?.logOriginNames?.[JSON.stringify(origin)];
|
||||
if (origin.CivilCard !== undefined) {
|
||||
const card = context?.cardCatalog?.find(card => card.id === origin.CivilCard);
|
||||
return `Action card · ${card?.name ?? label ?? `Card ${origin.CivilCard}`}`;
|
||||
}
|
||||
if (label) return label;
|
||||
if (origin.Incident !== undefined)
|
||||
return (
|
||||
|
|
@ -55,7 +59,12 @@ function lines(game: Game, action: LoggedAction, context?: Context): string[] {
|
|||
if (collect && action.items?.length)
|
||||
add(action.player ?? action.items[0].player, 'Collect', `Use city ${collect.city_position}`);
|
||||
for (const item of action.items ?? []) {
|
||||
const origin = source(item, context);
|
||||
const played = item.HandCard?.to === 'PlayToDiscard' && item.HandCard.card &&
|
||||
typeof item.HandCard.card === 'object' && 'ActionCard' in item.HandCard.card
|
||||
? item.HandCard.card.ActionCard : undefined;
|
||||
const origin = typeof played === 'number'
|
||||
? source({ ...item, origin: { CivilCard: played } }, context)
|
||||
: source(item, context);
|
||||
const write = (text: string) => add(item.player, origin, text);
|
||||
if (item.Text !== undefined && !offeredDiscount(item.Text)) {
|
||||
const event = item.Text.match(/^triggers the event (.+)$/);
|
||||
|
|
|
|||
|
|
@ -500,6 +500,7 @@ export interface JournalEntry {
|
|||
title: string;
|
||||
tokens: JournalToken[];
|
||||
notes: string[];
|
||||
card?: import('./card-reference').CardRule;
|
||||
combat?: import('./combat-journal').CombatRound;
|
||||
collection?: {
|
||||
city?: { size: number; mood: string; structures: string[] };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue