Group revealed hands by owner and show objective progress

This commit is contained in:
coyotte508 2026-10-13 03:44:37 +02:00
commit 686d30f485
8 changed files with 84 additions and 4 deletions

View file

@ -530,12 +530,28 @@ pub(super) fn describe(game: &Game, seat: usize) -> Option<Value> {
.join("\n"),
HandCard::Wonder(w) => w.info(game).description.clone(),
};
let owner = game.players.iter().find(|player| match card {
HandCard::ActionCard(id) => *id != 0 && player.action_cards.contains(id),
HandCard::ObjectiveCard(id) => *id != 0 && player.objective_cards.contains(id),
HandCard::Wonder(w) => *w != crate::wonder::Wonder::Hidden && player.wonder_cards.contains(w),
}).or_else(|| {
// Spies reveals choices, but the opponent's hand stays redacted.
if h.origin.name(game) != "Spy" { return None; }
if let PersistentEventType::ActionCard(info) = &game.current_event().event_type {
info.selected_player.map(|index| game.player(index))
} else { None }
});
let mut choice = option(card, card.name(game), text, None);
if let Some(owner) = owner {
choice["owner"] = json!({"player":owner.index,"civilization":owner.civilization.name,"you":owner.index == seat});
}
choice["card"] = match card {
HandCard::ObjectiveCard(id) => {
let info = game.cache.get_objective_card(*id);
json!({"kind":"objective", "objectives":info.objectives.iter().map(|o| json!({
"name":o.name, "description":o.description,
"progress":owner.and_then(|owner| o.progress.as_ref().map(|progress| progress(game, owner))).unwrap_or_default(),
"conditionMet":owner.is_some_and(|owner| o.status_phase_check.as_ref().is_some_and(|check| check(game, owner))),
"timing":match o.get_type() {
ObjectiveType::Instant => "Instant",
ObjectiveType::StatusPhase => "Status phase",

View file

@ -319,3 +319,5 @@ Viewer 0.1.99 / engine 0.4.78 fixes Revolution's independent sacrifices: the fir
Viewer 0.1.100 fixes mobile map controls wrapping into a tall block and overlapping activity controls. The map toolbar stays on one compact row, with journal/chat above it. Smaller outer margins and an explicit width cap preserve a gap between player panels and the action bar. Redo no longer adds a toolbar column: Undo's menu arrow, long press, context menu, or keyboard Down opens Redo. Verified layout at 320/360/393/430px in both map views, keyboard access, and long-press without accidental Undo. Engine remains 0.4.78.
Viewer 0.1.101 names publicly played action cards in Since your last turn summaries, retaining resource and other outcomes. It resolves the card from the frame's public Playing ActionCard log entry and the public catalog; drawn/hidden cards are never used to infer a name. Checked replay tests and existing public game-history examples. Engine remains 0.4.78.
Viewer 0.1.102 / engine 0.4.79 labels Spies hand choices by current owner, including the opponent whose hand remains redacted in public state. Mixed hands are grouped by civilization and card type while preserving original selection indices. Objective choices show progress for their current owner and end-of-age condition status. Checked ownership/progress against both owners' private views, lack of choice exposure to the opponent, and desktop/mobile layouts.

View file

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

View file

@ -2,12 +2,14 @@
import { printedCardName } from './card-names';
import { Hourglass, Zap, Layers, Swords } from 'lucide-svelte';
import type { Decision } from './types';
import CivilizationEmblem from './CivilizationEmblem.svelte';
import ObjectiveArt from './ObjectiveArt.svelte';
import ResourceText from './ResourceText.svelte';
let { option, id }: { option: Decision['options'][number]; id: string } = $props();
</script>
<span {id} class="decision-option-content">
{#if option.owner}<span class="decision-card-owner"><CivilizationEmblem civilization={option.owner.civilization} size={18}/>{option.owner.civilization}{option.owner.you ? ' · You' : ''}</span>{/if}
{#if option.card?.kind === 'objective'}
{#each option.card.objectives as objective, i}
{#if i}<span class="decision-alternative">or</span>{/if}
@ -24,6 +26,13 @@
</span>
</span>
<span class="decision-rule"><ResourceText text={objective.description} /></span>
{#if objective.conditionMet}<span class="objective-ready">Condition met · End of age</span>{/if}
{#if objective.progress?.length}<span class="objective-progress" aria-label="Owner’s current progress">
{#each objective.progress as progress}<span class="objective-progress-row" class:met={progress.current >= progress.target}>
<span>{progress.label}</span><strong>{progress.current}/{progress.target}</strong>
<meter min="0" max={Math.max(1,progress.target)} value={Math.min(progress.current,progress.target)} aria-label={progress.label}></meter>
</span>{/each}
</span>{/if}
</span>
{/each}
{:else if option.card?.kind === 'action'}
@ -47,3 +56,8 @@
{/if}
{/if}
</span>
<style>
.decision-card-owner { display:flex; align-items:center; gap:.4rem; padding-bottom:.5rem; margin-bottom:.6rem; border-bottom:1px solid var(--line); color:var(--muted); font-size:.8rem; }
.objective-progress { display:block; }
</style>

View file

@ -122,6 +122,20 @@
const count = $derived(
decision.min === decision.max ? `Choose ${decision.max}` : `Choose ${decision.min}–${decision.max}`,
);
const optionGroups = $derived.by(() => {
const indexed = decision.options.map((option, index) => ({option,index}));
if (new Set(indexed.map(({option})=>option.owner?.player).filter(p=>p!==undefined)).size < 2)
return [{label:'', options:indexed}];
const type = (option: typeof decision.options[number]) => option.card?.kind === 'action' ? 'Action cards' : option.card?.kind === 'objective' ? 'Objectives' : 'Wonders';
const groups = new Map<string, {label:string; options:typeof indexed; order:number}>();
for (const item of indexed) {
const owner=item.option.owner, kind=type(item.option);
const key=`${owner?.player}:${kind}`;
const group=groups.get(key) ?? {label:`${owner?.civilization ?? 'Cards'}${owner?.you ? ' · You' : ''} — ${kind}`, options:[], order:(owner?.you ? 0 : (owner?.player ?? 0)+1)*10+['Action cards','Objectives','Wonders'].indexOf(kind)};
group.options.push(item);groups.set(key,group);
}
return [...groups.values()].sort((a,b)=>a.order-b.order);
});
function toggle(i: number) {
controller.selectDecisionOption(i);
}
@ -130,7 +144,9 @@
{#snippet options()}
<div class="decision-options">
{#each decision.options as option, i}
{#each optionGroups as group}
{#if group.label}<h3 class="decision-card-group">{group.label} <small>({group.options.length})</small></h3>{/if}
{#each group.options as {option, index: i}}
{@const unit =
typeof option.value === 'string' && Object.hasOwn(unitInfo, option.value)
? unitInfo[option.value as UnitKind]
@ -169,6 +185,7 @@
>{#if selected.includes(i)}<Check size={13} />{/if}</span
>
</button>
{/each}
{/each}
</div>
{/snippet}
@ -452,3 +469,9 @@
{/if}
{#if $session.error}<p class="inline-error" role="alert">{$session.error}</p>{/if}
</section>
<style>
.decision-card-group { grid-column: 1 / -1; margin: 1rem 0 .25rem; font-size: .95rem; padding-bottom: .5rem; border-bottom: 1px solid var(--line); }
.decision-card-group:first-child { margin-top: 0; }
.decision-card-group small { font-weight: normal; color: var(--muted); }
</style>

View file

@ -0,0 +1,24 @@
import {test} from 'node:test';
import assert from 'node:assert/strict';
import {createRequire} from 'node:module';
import {readFileSync} from 'node:fs';
const engine=createRequire(import.meta.url)('../.engine/server.js');
test('Spies identifies each redacted-hand owner and uses that owner for objective progress',async()=>{
const game=JSON.parse(readFileSync(new URL('../../server/tests/test_games/action_cards/spy.json',import.meta.url),'utf8'));
game.players[0].objective_cards=[1];game.players[1].objective_cards=[2];
game.players.push(...JSON.parse(await engine.init(2,[],{},'spy',{})).players.slice(2));
let state=engine.tryMove(JSON.stringify(game),JSON.stringify({Playing:{ActionCard:7}}),0);
state=engine.tryMove(state,JSON.stringify({Response:{Payment:[{culture_tokens:1}]}}),0);
const view=JSON.parse(engine.webView(engine.stripSecret(state,0),0));
for(const option of view.decision.options){
const owner=option.value.ActionCard===1 || option.value.ObjectiveCard===1 ? 0 : 1;
assert.equal(option.owner.player,owner);assert.equal(option.owner.you,owner===0);
if(option.value.ObjectiveCard){
const ownView=JSON.parse(engine.webView(engine.stripSecret(state,owner),owner));
const card=ownView.objectiveCards.find((c:any)=>c.id===option.value.ObjectiveCard);
assert.deepEqual(option.card.objectives.map((o:any)=>o.progress),card.objectives.map((o:any)=>o.progress));
assert.deepEqual(option.card.objectives.map((o:any)=>o.conditionMet),card.objectives.map((o:any)=>o.conditionMet));
}
}
assert.equal(JSON.parse(engine.webView(engine.stripSecret(state,1),1)).decision,null,'opponent must not receive Spies choices');
});

View file

@ -709,6 +709,7 @@ export interface Decision {
| { kind: 'unit'; player: number; unit: number; unitType: UnitView['type'] }
| { kind: 'structure'; structure: string | { Building: string } | { Wonder: string } };
terrain?: Terrain;
owner?: { player: number; civilization: string; you: boolean };
card?:
| { kind: 'objective'; objectives: View['objectiveCards'][number]['objectives'] }
| { kind: 'action'; name: string; description: string; tactics: ActionCard['tactics'] }