Show public Subterfuge card rules and exact card details

This commit is contained in:
coyotte508 2026-11-06 00:18:42 +00:00
commit 781ec693c9
9 changed files with 206 additions and 4 deletions

View file

@ -669,6 +669,16 @@ pub(super) fn describe(game: &Game, seat: usize) -> Option<Value> {
"advanceSelection":matches!(h.request,PersistentEventRequest::SelectAdvance(_)),
"advanceMode":matches!(h.request,PersistentEventRequest::SelectAdvance(_)).then(|| advance_mode(game, h)),
"endOfAge":crate::status_phase::get_status_phase(game).is_some()});
// The declaration is public; identify only that card, never the player's hand.
// Use its id rather than its title (civil titles can have different battle uses).
if matches!(
h.origin,
EventOrigin::SpecialAdvance(crate::special_advance::SpecialAdvance::Subterfuge)
) && let PersistentEventType::DeclareActionCard(announcement) =
&game.current_event().event_type
{
decision["pendingActionCard"] = json!(announcement.card);
}
if let Some((player, round)) = tactics_context {
decision["opponentTactics"] = json!(crate::tactics_card::opponent_tactics_status(
game, player, round,

View file

@ -983,3 +983,31 @@ Verified with 1,029 frontend tests, locale checks, Svelte checks, production bui
and the focused battle-dice browser smoke. The older `combat-smoke.mjs` still
fails its unrelated map-label expectation (`Battle · C1` versus the existing
`Battle · Round 1`); this release does not change that label or suppress the test.
# Viewer 0.1.205 / engine 0.4.138
Subterfuge shows the publicly declared action card’s complete civil rules and
opens its exact printed copy, including the correct battle use. The read-only
`pendingActionCard` decision field comes exclusively from the public
DeclareActionCard event; opponent hands remain redacted. Scoped header spacing
keeps the title, action cost and rules readable at desktop and narrow widths.
No game rules, historical outcomes or saved games change.
Publish the matching engine and viewer together. Build with
`npm run build:bridge`, package the generated Node bridge as
`@boardgamers/clash-server` 0.4.138 (server.js and server_bg.wasm), then run
`npm run build` and `npm run publish:bgs -- --engine=/absolute/path/to/package.tgz`
(first with `--dry-run`). Preserve all creation options, including exact
game-length labels/order and the Standard default. No live game mutations or
smaller-city experiment are included.
Regression coverage checks both Inspiration IDs, cancel/allow resolution,
hidden-hand privacy, and exact battle-side lookup; the Subterfuge browser smoke
checks full rules, card dialog and spacing at 1400, 390 and 320px.
Verified with the full native workspace tests, pinned Rust 1.94.1 build/format/
Clippy checks, 1,031 frontend tests, locales, Svelte checks and production build.
The packed-engine civilization suite passes 226 tests, including both Inspiration
copies and privacy/cancel/allow coverage. Both copies pass the browser smoke at
all three widths; battle-dice smoke also passes. The pre-existing combat smoke
still expects `Battle · C1` instead of `Battle · Round 1`; it remains unchanged.

View file

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

View file

@ -0,0 +1,75 @@
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { chromium } from 'playwright';
const engine = createRequire(import.meta.url)('../.engine/server.js');
const move = (state, action) => engine.tryMove(state, JSON.stringify(action), engine.currentPlayer(state));
let state = await engine.init(2, [], { civilization: 'ChooseCivilization' }, 'subterfuge-ui', {});
for (const civ of ['Greece', 'Japan']) state = move(state, { ChooseCivilization: civ });
const game = JSON.parse(state), player = engine.currentPlayer(state), japan = 1 - player;
game.players[player].civilization = 'Greece';
game.players[japan].civilization = 'Japan';
game.players[japan].advances.push('Tactics', 'Writing', 'Husbandry');
game.players[japan].units[0].position = game.players[player].cities[0].position;
game.players[japan].units[0].unit_type = 'Infantry';
game.players[player].action_cards = [4, 27, 11];
game.players[japan].action_cards = [9];
const beforeDeclaration = JSON.stringify(game);
const browser = await chromium.launch({ headless: true, args: ['--use-gl=angle', '--use-angle=swiftshader'] });
try {
for (const id of [3, 4]) for (const width of [1400, 390, 320]) {
const fixture = JSON.parse(beforeDeclaration);
fixture.players[player].action_cards = [id, 27, 11];
state = move(JSON.stringify(fixture), { Playing: { ActionCard: id } });
const page = await browser.newPage({ viewport: { width, height: 900 } });
const errors = [];
page.on('pageerror', (error) => errors.push(error.message));
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'].includes(path)) return route.abort();
return route.fulfill({ contentType: path.endsWith('.wasm') ? 'application/wasm' : 'text/javascript', body: await readFile(new URL('../dist' + path, import.meta.url)) });
});
await page.goto('http://clash.test/');
await page.evaluate(({ state, seat }) => {
window.host = clash3d.launch('#app');
host.emit('player', { index: seat });
host.emit('preferences', { sound: false });
host.emit('state', state);
}, { state: engine.stripSecret(state, japan), seat: japan });
const panel = page.getByRole('region', { name: 'Subterfuge', exact: true });
await panel.waitFor();
assert.match(await panel.innerText(), /Gain 1 advance for free/);
assert.match(await panel.innerText(), /Normal advance prerequisites apply/);
assert.doesNotMatch(await panel.innerText(), /Assassination|Great Ideas/);
const spacing = await panel.locator('.announced-card').evaluate((card) => {
const header = card.querySelector('.play-card-header').getBoundingClientRect();
const button = card.querySelector('button').getBoundingClientRect();
const cost = card.querySelector('.card-use-rule').getBoundingClientRect();
const effect = card.querySelector('.announced-card-effect').getBoundingClientRect();
return {
sameRow: Math.abs((button.top + button.bottom) / 2 - (cost.top + cost.bottom) / 2) < 1,
horizontalGap: cost.left - button.right,
effectGap: effect.top - header.bottom,
};
});
assert.ok(spacing.sameRow, 'Title and action cost fit on one centered row');
assert.ok(spacing.horizontalGap >= 8, 'Title and action cost have a deliberate gap');
assert.equal(spacing.effectGap, 8, 'Effect text has a compact gap below the header');
await panel.getByRole('button', { name: 'Inspiration', exact: true }).click();
const rules = page.getByRole('dialog', { name: 'Inspiration rules' });
await rules.waitFor();
// The printed name for the engine's Encircled tactic is Routing.
assert.match(await rules.innerText(), id === 3 ? /Routing/ : /Peltasts/);
assert.doesNotMatch(await rules.innerText(), id === 3 ? /Peltasts/ : /Routing/);
await rules.getByRole('button', { name: 'Close card rules' }).click();
assert.ok(await panel.isVisible());
assert.ok(await panel.evaluate((el) => el.scrollWidth <= el.clientWidth + 1));
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
assert.deepEqual(errors, []);
console.log(`${width}px: public Inspiration ${id} rules and exact battle side visible; hidden hand absent; dialog closes back to decision.`);
await page.close();
}
} finally {
await browser.close();
}

View file

@ -1,6 +1,8 @@
<script lang="ts">
import { handCardDescription } from './card-text';
import GreatPersonEffect from './GreatPersonEffect.svelte';
import CardReferenceDialog from './CardReferenceDialog.svelte';
import { pendingActionCard } from './card-reference';
import CalendarEventPreview from './CalendarEventPreview.svelte';
import GreatPersonAcquisition from './GreatPersonAcquisition.svelte';
import RazeActions from './RazeActions.svelte';
@ -34,6 +36,8 @@
}: { controller: Controller; decision: Decision; onHighlight: (position: string | null) => void } =
$props();
const session = $derived(controller.session);
const announcedCard = $derived(pendingActionCard($session.view, decision));
let announcedRulesOpen = $state(false);
const panelId = $props.id();
const selected = $derived($session.decisionSelection);
const opponentTactics = $derived(opponentTacticsLabel(decision));
@ -290,6 +294,20 @@
text={description.replaceAll('Status Phase', 'End of age').replaceAll('status phase', 'end of age')}
/>
</p>{/if}
{#if announcedCard}
<article class="play-card announced-card">
<header class="play-card-header">
<button class="secondary" onclick={() => (announcedRulesOpen = true)}>
<BookOpen size={16} />{printedCardName(announcedCard.name)}
</button>
<p class="card-use-rule"><Zap size={14} />{announcedCard.free ? 'Free action' : 'Costs 1 action'}</p>
</header>
<p class="announced-card-effect"><ResourceText text={handCardDescription(announcedCard.description)} /></p>
</article>
{#if announcedRulesOpen}
<CardReferenceDialog card={announcedCard} onDismiss={() => (announcedRulesOpen = false)} />
{/if}
{/if}
{#if opponentTactics}<p class="tactics-opponent-status" role="status">
<Layers size={16} aria-hidden="true" /><span>{opponentTactics}</span>
</p>{/if}
@ -548,6 +566,19 @@
flex-shrink: 0;
}
.announced-card .play-card-header {
flex-wrap: wrap;
gap: 8px 12px;
}
.announced-card .card-use-rule {
display: inline-flex;
align-items: center;
gap: 4px;
margin: 0;
}
.announced-card .card-use-rule :global(svg) { flex-shrink: 0; }
.announced-card .announced-card-effect { margin: 8px 0 0; }
.tactics-opponent-status {
display: flex;
align-items: center;

View file

@ -1,4 +1,4 @@
import type { ActionCard, View } from './types.ts';
import type { ActionCard, Decision, View } from './types.ts';
export type CardRule = Pick<ActionCard, 'id' | 'name' | 'description' | 'free' | 'tactics'>;
export interface CardReference {
name: string;
@ -14,3 +14,8 @@ export function cardReferences(view: View | null | undefined): CardReference[] {
}
return [...refs.values()];
}
/** Resolve only the public declaration, never infer a card from an opponent's hand or title. */
export function pendingActionCard(view: View | null | undefined, decision: Decision): CardRule | null {
return view?.cardCatalog?.find((card) => card.id === decision.pendingActionCard) ?? null;
}

View file

@ -2,6 +2,7 @@ import { test } from 'node:test';
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import { readFileSync } from 'node:fs';
import { pendingActionCard } from './card-reference.ts';
import { frameDetails } from './playback.ts';
import { journal } from './journal.ts';
import { manGodAbility } from './research-links.ts';
@ -579,6 +580,56 @@ test('Subterfuge discards both cards while leaving the cancelled card costs unpa
assert.equal((after.players[1 - index].action_cards ?? []).length, 0);
assert.ok(!JSON.stringify(after.permanent_effects ?? []).includes('Assassination'));
});
for (const id of [3, 4]) test(`Subterfuge exposes exact Inspiration ${id} rules, not the opponent hand, and can cancel or allow`, async () => {
const g = await setup('Greece');
const index = seat(g), opponentIndex = 1 - index;
const p = g.players[index], opponent = g.players[opponentIndex];
opponent.civilization = 'Japan';
addAdvance(opponent, 'Tactics', 'Writing', 'Husbandry');
opponent.units[0].position = p.cities[0].position;
opponent.units[0].unit_type = 'Infantry';
p.action_cards = [id, 27, 11];
opponent.action_cards = [9];
const declared = move(g, { Playing: { ActionCard: id } });
const stripped = JSON.parse(engine.stripSecret(serialize(declared), opponentIndex));
const reaction = view(declared, opponentIndex);
assert.equal(reaction.decision.pendingActionCard, id);
const card = pendingActionCard(reaction, reaction.decision)!;
assert.equal(card.id, id);
assert.equal(card.name, 'Inspiration');
assert.match(card.description, /Gain 1 advance for free/);
assert.match(card.description, /Normal advance prerequisites apply/);
assert.equal(card.tactics!.name, id === 3 ? 'Encircled' : 'Peltasts');
assert.ok(stripped.events.some((event: any) => event.event_type?.DeclareActionCard?.card === id));
assert.ok(!stripped.players[index].action_cards.some((c: number) => [id, 27, 11].includes(c)));
assert.deepEqual(reaction.actionCards.map((c: any) => c.id), [9]);
assert.deepEqual(reaction.decision.options.map((o: any) => o.value), [{ ActionCard: 9 }]);
assert.equal(pendingActionCard(reaction, { ...reaction.decision, pendingActionCard: undefined }), null);
assert.equal(pendingActionCard(reaction, { ...reaction.decision, pendingActionCard: 255 }), null);
const cancelled = move(declared, { Response: { SelectHandCards: [{ ActionCard: 9 }] } });
assert.deepEqual(cancelled.players[index].action_cards, [27, 11]);
assert.deepEqual(cancelled.players[index].advances, p.advances);
assert.deepEqual(cancelled.players[index].resources, p.resources);
assert.equal(cancelled.actions_left, g.actions_left);
assert.ok(cancelled.action_cards_discarded.includes(id));
assert.ok(cancelled.action_cards_discarded.includes(9));
assert.equal(view(cancelled).decision?.pendingActionCard, undefined);
const allowed = move(declared, { Response: { SelectHandCards: [] } });
assert.equal(seat(allowed), index);
assert.equal(view(allowed).decision.pendingActionCard, undefined);
assert.ok(view(allowed).decision.advanceSelection);
const advance = view(allowed).decision.options[0].value;
const resolved = move(allowed, { Response: { SelectAdvance: advance } });
assert.ok(resolved.players[index].advances.includes(advance));
assert.deepEqual(resolved.players[index].action_cards, [27, 11]);
assert.deepEqual(resolved.players[opponentIndex].action_cards, [9]);
// Acquiring an advance may grant its printed token bonus, but Inspiration costs nothing.
for (const [resource, amount] of Object.entries(p.resources))
assert.ok(resolved.players[index].resources[resource] >= (amount as number));
assert.equal(resolved.actions_left, g.actions_left);
});
test('Shogunate offers an optional free action and uses the allowance only after the card is accepted', async () => {
const g = await setup('Japan'),
p = g.players[seat(g)];

View file

@ -717,6 +717,8 @@ export interface ActionCard {
action: Move | null;
}
export interface Decision {
/** Publicly declared card being considered for Subterfuge, not an opponent hand. */
pendingActionCard?: number;
origin?: Record<string, unknown>;
/** Private Calendar preview, structured from the owner's visible payment request. */
calendarPreview?: {