Describe recorded choice outcomes in turn recaps
This commit is contained in:
parent
dd23158535
commit
3a3c027487
5 changed files with 162 additions and 10 deletions
|
|
@ -187,3 +187,8 @@ Prediction and server-acknowledgement fingerprints now canonicalize nested objec
|
|||
Wonders shows a Great Architect suggestion when the player holds that card, explaining its culture discount and advance waiver while retaining Engineering. Its button uses the engine-provided card action and remains disabled with the normal reason when unavailable. Undo's retained-action comparison also uses canonical object ordering, so equivalent host serialization cannot discard a valid prior snapshot. Undo also handles historic turns with no action array, which previously threw and forced a server wait. Browser coverage exercises undoing Theaters without a server acknowledgement, and confirms Advance skips its already-quoted culture payment and opens research.
|
||||
|
||||
Separation of Power protects only its owner as defender. Wonders no longer make a city count as foreign-influenced, restoring those cities as cultural influence sources, including India’s Proselytism range from settlers. Influence reserves the Arts fee after including interchangeable mood from Great Arena, avoiding unsigned underflow when culture is empty.
|
||||
|
||||
|
||||
# Viewer 0.1.67 / engine unchanged (0.4.62)
|
||||
|
||||
Recap captions replace generic choice/payment labels with recorded outcomes: unit placements and losses by player and location, research, gained buildings, payments, happiness changes, and public card-draw effects. Existing saved frames use only their public historical interval, never current hands. Existing action grouping retains follow-up payments without merging different players or combat/event boundaries.
|
||||
|
|
|
|||
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.66",
|
||||
"version": "0.1.67",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.66",
|
||||
"version": "0.1.67",
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.9.0",
|
||||
"lucide-svelte": "^0.577.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.66",
|
||||
"version": "0.1.67",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -388,3 +388,68 @@ test('legacy ability captions fall back safely when the start entry is unavailab
|
|||
} as unknown as Game;
|
||||
assert.equal(frameDetails(before, after, game).caption, 'Civilization ability');
|
||||
});
|
||||
|
||||
function choiceRecap(items: NonNullable<LoggedAction['items']>, effects: BoardFrame['effects'] = []) {
|
||||
const before = {
|
||||
cursor: 0,
|
||||
actor: 0,
|
||||
title: 'Earlier position',
|
||||
tiles: [],
|
||||
players: [
|
||||
{ id: 0, civilization: 'India', cities: [], units: [] },
|
||||
{ id: 4, civilization: 'Pirates', cities: [], units: [] },
|
||||
],
|
||||
} as unknown as BoardFrame;
|
||||
const after = { ...before, cursor: 1, title: 'Resolve choice', effects };
|
||||
const game = {
|
||||
log_index: 1,
|
||||
log: [
|
||||
{
|
||||
age: 1,
|
||||
rounds: [
|
||||
{
|
||||
round: 1,
|
||||
turns: [{ turn_type: { Player: 0 }, actions: [{ action: { Response: { Bool: true } }, items }] }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
} as unknown as Game;
|
||||
return { before, after, game };
|
||||
}
|
||||
|
||||
test('choice recaps name research and payments without generic engine labels', () => {
|
||||
const { before, after, game } = choiceRecap([
|
||||
{ player: 0, Advance: { advance: 'SteelWeapons', balance: 'Gain' } },
|
||||
{ player: 0, Resources: { balance: 'Pay', resources: { culture_tokens: 1 } } },
|
||||
]);
|
||||
assert.equal(
|
||||
frameDetails(before, after, game).caption,
|
||||
'India · researched Steel Weapons · paid 1 culture',
|
||||
);
|
||||
});
|
||||
|
||||
test('choice recaps name pirate placements and card draws without revealing card identities', () => {
|
||||
const { before, after, game } = choiceRecap(
|
||||
[{ player: 0, HandCard: { card: { ActionCard: 156 }, to: { Hand: 0 } } }],
|
||||
[{ player: 0, kind: 'action', label: 'Drew an action card' }],
|
||||
);
|
||||
after.players = structuredClone(before.players);
|
||||
after.players[1].units = [{ id: 10, position: 'C4', unit_type: 'Ship' }];
|
||||
const caption = frameDetails(before, after, game).caption;
|
||||
assert.equal(caption, 'India · Pirates: placed 1 ship at C4 · Drew an action card');
|
||||
assert.doesNotMatch(caption, /156|Resolve choice/);
|
||||
assert.equal(frameDetails(before, { ...after, title: 'Pay for action' }, game).caption, caption);
|
||||
});
|
||||
|
||||
test('choice recaps use public decisions and happiness outcomes', () => {
|
||||
const { before, after, game } = choiceRecap([{ player: 0, MoodChange: { city: 'B7', mood: 'Happy' } }]);
|
||||
assert.equal(frameDetails(before, after, game).caption, 'India · B7 is now happy');
|
||||
game.log![0].rounds[0].turns[0].actions![0].items = [
|
||||
{ player: 0, Text: 'Decided to convert mood to culture tokens' },
|
||||
];
|
||||
assert.equal(
|
||||
frameDetails(before, after, game).caption,
|
||||
'India · Decided to convert mood to culture tokens',
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { BoardFrame, Game, View } from './types.ts';
|
||||
import type { BoardFrame, Game, View, Pile } from './types.ts';
|
||||
import { frameResources, describeResources } from './resource-playback.ts';
|
||||
import { frameHasContent } from './replay-actions.ts';
|
||||
import { activeHistory } from './active-history.ts';
|
||||
|
|
@ -118,6 +118,30 @@ export function frameDetails(
|
|||
let description = ['Explore Resolution', 'Finish ship exploration'].includes(frame.title)
|
||||
? 'Explore'
|
||||
: frame.title;
|
||||
const generic = ['Resolve choice', 'Pay for action', 'Action'].includes(
|
||||
frame.title,
|
||||
);
|
||||
const outcomes: string[] = [];
|
||||
if (before && generic) {
|
||||
for (const player of frame.players) {
|
||||
for (const [from, to, verb] of [
|
||||
[oldUnits, newUnits, 'placed'],
|
||||
[newUnits, oldUnits, 'lost'],
|
||||
] as const) {
|
||||
const counts = new Map<string, number>();
|
||||
for (const [id, unit] of to) {
|
||||
if (from.has(id) || !id.startsWith(`${player.id}:`)) continue;
|
||||
const name = typeof unit.unit_type === 'string' ? unit.unit_type.toLowerCase() : 'leader';
|
||||
const key = `${name} at ${unit.position}`;
|
||||
counts.set(key, (counts.get(key) ?? 0) + 1);
|
||||
}
|
||||
for (const [unit, count] of counts)
|
||||
outcomes.push(
|
||||
`${player.id === frame.actor ? '' : player.civilization + ': '}${verb} ${count} ${count > 1 ? unit.replace(/^(ship|settler|elephant|leader) at /, '$1s at ') : unit}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (before && frame.title === 'Recruit') {
|
||||
const counts = new Map<string, number>();
|
||||
for (const [id, unit] of newUnits) {
|
||||
|
|
@ -170,7 +194,7 @@ export function frameDetails(
|
|||
}
|
||||
}
|
||||
}
|
||||
const details: string[] = [];
|
||||
const details: string[] = [...outcomes];
|
||||
const readable = wonderName;
|
||||
for (const player of frame.players) {
|
||||
const own = items.filter((item) => item.player === player.id);
|
||||
|
|
@ -186,7 +210,7 @@ export function frameDetails(
|
|||
.join(', ')}`,
|
||||
);
|
||||
if (player.id !== frame.actor) continue;
|
||||
if (frame.title === 'Build' || frame.title === 'Build wonder') {
|
||||
if (generic || frame.title === 'Build' || frame.title === 'Build wonder') {
|
||||
const built = own.flatMap((item) => {
|
||||
const structure = item.Structure;
|
||||
if (
|
||||
|
|
@ -198,7 +222,29 @@ export function frameDetails(
|
|||
const value = Object.values(structure.structure)[0];
|
||||
return typeof value === 'string' ? [readable(value)] : [];
|
||||
});
|
||||
if (built.length) details.push('built ' + [...new Set(built)].join(', '));
|
||||
if (built.length) details.push((generic ? 'gained ' : 'built ') + [...new Set(built)].join(', '));
|
||||
}
|
||||
}
|
||||
if (generic) {
|
||||
for (const player of frame.players) {
|
||||
const prefix = player.id === frame.actor ? '' : player.civilization + ': ';
|
||||
const paid: Pile = {};
|
||||
for (const item of items.filter((item) => item.player === player.id)) {
|
||||
if (item.Resources?.balance === 'Pay')
|
||||
for (const [resource, amount] of Object.entries(item.Resources.resources))
|
||||
paid[resource as keyof typeof paid] =
|
||||
(paid[resource as keyof typeof paid] ?? 0) + (amount ?? 0);
|
||||
if (item.MoodChange)
|
||||
details.push(`${prefix}${item.MoodChange.city} is now ${item.MoodChange.mood.toLowerCase()}`);
|
||||
}
|
||||
const payment = describeResources(paid);
|
||||
if (payment) details.push(`${prefix}paid ${payment}`);
|
||||
}
|
||||
// Public effect labels identify card types without exposing private cards.
|
||||
for (const effect of frame.effects ?? []) {
|
||||
const player = frame.players.find((p) => p.id === effect.player);
|
||||
const label = `${effect.player === frame.actor ? '' : (player?.civilization ?? 'Player') + ': '}${effect.label}`;
|
||||
if (!details.includes(label)) details.push(label);
|
||||
}
|
||||
}
|
||||
const resources = frameResources(game, before.cursor, frame);
|
||||
|
|
@ -211,10 +257,46 @@ export function frameDetails(
|
|||
if (gained) details.push(`${prefix}${frame.title === 'Collect' ? 'collected' : 'gained'} ${gained}`);
|
||||
if (waste) details.push(`${prefix}${waste} not stored`);
|
||||
}
|
||||
if (generic && !details.length) {
|
||||
const result = items
|
||||
.map((item) => item.Text)
|
||||
.find(
|
||||
(text) =>
|
||||
text &&
|
||||
/^(Decided to |Declined |Removed |Completed |Selected |Chose |Kept |Discarded |Passed)/i.test(
|
||||
text,
|
||||
),
|
||||
);
|
||||
if (result) details.push(result);
|
||||
}
|
||||
if (details.length)
|
||||
description = ['Research', 'Build', 'Build wonder', 'Collect'].includes(frame.title)
|
||||
? details.join(' · ')
|
||||
: [description, ...details].join(' · ');
|
||||
description =
|
||||
(generic && description === frame.title) ||
|
||||
['Research', 'Build', 'Build wonder', 'Collect'].includes(frame.title)
|
||||
? details.join(' · ')
|
||||
: [description, ...details].join(' · ');
|
||||
}
|
||||
if (generic && description === frame.title) {
|
||||
const action =
|
||||
game &&
|
||||
activeHistory(game)
|
||||
.flatMap((a) => a.rounds.flatMap((r) => r.turns.flatMap((t) => t.actions ?? [])))
|
||||
.slice(before?.cursor ?? frame.cursor, frame.cursor)
|
||||
.at(-1)?.action;
|
||||
const response = action && typeof action === 'object' ? action.Response : null;
|
||||
const kind = response && typeof response === 'object' ? Object.keys(response)[0] : '';
|
||||
description =
|
||||
(
|
||||
{
|
||||
SelectAdvance: 'Research',
|
||||
SelectUnits: 'Selected units',
|
||||
SelectPositions: 'Selected a location',
|
||||
Payment: 'Payment',
|
||||
ResourceReward: 'Resource reward',
|
||||
ExploreResolution: 'Explore',
|
||||
Bool: 'Event decision',
|
||||
} as Record<string, string>
|
||||
)[kind] ?? 'Turn update';
|
||||
}
|
||||
return {
|
||||
caption: officialWonderText(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue