Show clickable sources for shared effects
This commit is contained in:
parent
dbdd5ba4eb
commit
28aed113e8
10 changed files with 264 additions and 23 deletions
|
|
@ -21,6 +21,16 @@ pub(super) fn describe(game: &Game) -> Vec<Value> {
|
|||
PermanentEffect::GreatSeer(s) => ("Great Seer", s.assigned_objectives.iter().map(|o| o.player).collect()),
|
||||
PermanentEffect::PublicWonderCard(_) => ("Public wonder", vec![]),
|
||||
};
|
||||
let source = match effect {
|
||||
PermanentEffect::Pestilence => event_source(game, 1),
|
||||
PermanentEffect::TrojanHorse => event_source(game, 42),
|
||||
PermanentEffect::SolarEclipse => event_source(game, 41),
|
||||
PermanentEffect::DiplomaticRelations(_) => event_source(game, 57),
|
||||
PermanentEffect::RevolutionLoseAction(_) => event_source(game, 38),
|
||||
PermanentEffect::Anarchy(_) => event_source(game, 44),
|
||||
PermanentEffect::PublicWonderCard(_) => event_source(game, 40),
|
||||
_ => action_source(game, name, players.first().copied()),
|
||||
};
|
||||
let incident = match effect {
|
||||
PermanentEffect::Pestilence => Some(1),
|
||||
PermanentEffect::TrojanHorse => Some(42),
|
||||
|
|
@ -54,10 +64,54 @@ pub(super) fn describe(game: &Game) -> Vec<Value> {
|
|||
}
|
||||
let scope = if players.is_empty() { "All players".to_string() }
|
||||
else { players.iter().map(|p| game.player_name(*p)).collect::<Vec<_>>().join(" · ") };
|
||||
json!({"name": name, "scope": scope, "players": players, "rules": rules})
|
||||
json!({"name": name, "scope": scope, "players": players, "rules": rules,"source":source})
|
||||
}).collect()
|
||||
}
|
||||
|
||||
fn action_source(game: &Game, name: &str, player: Option<usize>) -> Value {
|
||||
let turns: Vec<_> = game
|
||||
.log
|
||||
.iter()
|
||||
.flat_map(|age| &age.rounds)
|
||||
.flat_map(|round| &round.turns)
|
||||
.collect();
|
||||
let id = turns.iter().enumerate().rev().find_map(|(index, turn)| {
|
||||
let end = if index + 1 == turns.len() {
|
||||
game.log_index.min(turn.actions.len())
|
||||
} else {
|
||||
turn.actions.len()
|
||||
};
|
||||
turn.actions[..end].iter().rev().find_map(|entry| {
|
||||
if player.is_some_and(|p| p != entry.player) {
|
||||
return None;
|
||||
}
|
||||
if let crate::action::Action::Playing(
|
||||
crate::playing_actions::PlayingAction::ActionCard(id),
|
||||
) = entry.action
|
||||
{
|
||||
game.cache
|
||||
.get_action_cards()
|
||||
.iter()
|
||||
.chain(
|
||||
game.cache
|
||||
.get_incidents()
|
||||
.iter()
|
||||
.filter_map(|i| i.action_card.as_ref()),
|
||||
)
|
||||
.find(|card| card.id == id && card.civil_card.name == name)
|
||||
.map(|card| card.id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
});
|
||||
json!({"kind":"Action card","name":name,"id":id})
|
||||
}
|
||||
|
||||
fn event_source(game: &Game, id: u8) -> Value {
|
||||
json!({"kind":"Event", "name":game.cache.get_incident(id).name,"id":id})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
@ -71,6 +125,11 @@ mod tests {
|
|||
];
|
||||
let effects = describe(&game);
|
||||
assert_eq!(effects[0]["scope"], "All players");
|
||||
assert_eq!(
|
||||
effects[0]["source"],
|
||||
json!({"kind":"Event","name":"Trojan Horse","id":42})
|
||||
);
|
||||
assert_eq!(effects[1]["source"]["id"], 57);
|
||||
assert!(effects[0]["rules"].to_string().contains("another player's"));
|
||||
assert_eq!(effects[1]["players"], json!([0, 1]));
|
||||
assert!(effects[1]["rules"].to_string().contains("2 culture tokens"));
|
||||
|
|
@ -87,6 +146,40 @@ mod tests {
|
|||
assert_eq!(seer[0]["players"], json!([1]));
|
||||
assert!(!seer[0]["rules"].to_string().contains("Mercantile"));
|
||||
assert!(!seer[0]["rules"].to_string().contains("Traders"));
|
||||
game.permanent_effects = vec![
|
||||
PermanentEffect::Collect(CollectEffect::MassProduction),
|
||||
PermanentEffect::PublicWonderCard(crate::wonder::Wonder::Colosseum),
|
||||
];
|
||||
let more = describe(&game);
|
||||
assert_eq!(more[0]["source"]["kind"], "Action card");
|
||||
assert_eq!(more[0]["source"]["name"], "Mass Production");
|
||||
assert_eq!(more[1]["source"]["id"], 40);
|
||||
let player = game.active_player();
|
||||
let entry = crate::log::ActionLogAction::new(
|
||||
crate::action::Action::Playing(crate::playing_actions::PlayingAction::ActionCard(30)),
|
||||
player,
|
||||
None,
|
||||
0,
|
||||
);
|
||||
crate::log::current_turn_log_mut(&mut game)
|
||||
.actions
|
||||
.push(entry);
|
||||
game.log_index = crate::log::current_turn_log(&game).actions.len();
|
||||
assert_eq!(describe(&game)[0]["source"]["id"], 30);
|
||||
let redo = crate::log::ActionLogAction::new(
|
||||
crate::action::Action::Playing(crate::playing_actions::PlayingAction::ActionCard(29)),
|
||||
player,
|
||||
None,
|
||||
0,
|
||||
);
|
||||
crate::log::current_turn_log_mut(&mut game)
|
||||
.actions
|
||||
.push(redo);
|
||||
assert_eq!(
|
||||
describe(&game)[0]["source"]["id"],
|
||||
30,
|
||||
"ignore undone card plays"
|
||||
);
|
||||
game.permanent_effects.clear();
|
||||
assert!(describe(&game).is_empty());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,3 +89,5 @@ Viewer 0.1.44 and engine 0.4.50 enforce Technology Trade’s 2-space range when
|
|||
Viewer 0.1.45 uses the printed English Monumental Edition names for Objectives, Actions, Tactics, Events and Wonders, verified against all 38 objective, 42 action, 58 event and 8 wonder card scans recorded in `docs/card-text-audit.json`. The Markets objective is Mercantile; the three-route objective is Trader. Names are corrected in hands, decisions, completed objectives, journal references, combat and replay, including Great Pyramids. Saved engine names, card IDs, commands, objective readiness and historical outcomes remain unchanged; Great Migration is distinguished from the Migration event. Existing locale keys remain available alongside printed-name aliases. Engine 0.4.50 is unchanged.
|
||||
|
||||
Viewer 0.1.46 and engine 0.4.51 add an Effects indicator with a count and a rules dialog for active public effects, including Trojan Horse, Great Diplomat agreements, Negotiations and public wonders. Scopes distinguish shared effects, affected players and the current player's temporary action effects. Great Seer assignments remain private. Public-wonder draw choices display the wonder's effect, construction cost, required advance and points; Great Mausoleum discard previews include event rules and both uses of action cards. Trojan Horse now requires another human player's defended city, as stated on printed E42, and is no longer offered against barbarians. Existing saved activation prompts remain valid: decline an already-pending barbarian activation to continue without paying. Publish the matching viewer and engine together; historical battle outcomes are preserved. Cultural influence warns before rolling when another eligible city has a lower range cost, offers a source switch with the culture saving, and requires an explicit second click to retain the more expensive source. Automatic movement-group selection and switching seats during movement now select the whole compatible group instead of only its first unit.
|
||||
|
||||
Viewer 0.1.47 and engine 0.4.52 label active effects with their source event or action card. Source names use the same quiet link style as advance references and open the full source rules without changing the game. Event sources include their printed E number; action-card sources use the played copy from public history, ignoring undone actions. Older effects without a recoverable copy show the common action rules without inventing a battle use. Each effect has its own padded block with spacing between blocks. Saved effect data and game outcomes are unchanged.
|
||||
|
|
|
|||
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.46",
|
||||
"version": "0.1.47",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.46",
|
||||
"version": "0.1.47",
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.9.0",
|
||||
"lucide-svelte": "^0.577.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.46",
|
||||
"version": "0.1.47",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,26 @@
|
|||
<script lang="ts">
|
||||
import { Sparkles, X } from 'lucide-svelte';
|
||||
import type { ActiveEffect, View } from './types';
|
||||
import { Sparkles, X, ScrollText, Layers } from 'lucide-svelte';
|
||||
import type { ActiveEffect, View, EventInfo } from './types';
|
||||
import { printedCardName } from './card-names';
|
||||
import ResourceText from './ResourceText.svelte';
|
||||
import CardReferenceDialog from './CardReferenceDialog.svelte';
|
||||
import EventReferenceDialog from './EventReferenceDialog.svelte';
|
||||
import { effectSourceReference } from './active-effects';
|
||||
import type { CardRule } from './card-reference';
|
||||
let {
|
||||
effects,
|
||||
players,
|
||||
events,
|
||||
cards,
|
||||
onClose,
|
||||
}: { effects: ActiveEffect[]; players: View['players']; onClose: () => void } = $props();
|
||||
}: {
|
||||
effects: ActiveEffect[];
|
||||
players: View['players'];
|
||||
events: EventInfo[];
|
||||
cards: CardRule[];
|
||||
onClose: () => void;
|
||||
} = $props();
|
||||
let reference = $state<ReturnType<typeof effectSourceReference>>(null);
|
||||
function show(node: HTMLDialogElement) {
|
||||
node.showModal();
|
||||
}
|
||||
|
|
@ -29,25 +42,64 @@
|
|||
><X size={20} /></button
|
||||
>
|
||||
<h2><Sparkles size={23} /> Active effects</h2>
|
||||
{#each effects as effect}
|
||||
<section class="active-effect-rule">
|
||||
<h3>{printedCardName(effect.name)}</h3>
|
||||
<small
|
||||
>{effect.players.length
|
||||
? effect.players
|
||||
.map((index) => players.find((player) => player.index === index)?.civilization ?? effect.scope)
|
||||
.join(' · ')
|
||||
: effect.scope}</small
|
||||
>
|
||||
{#each effect.rules as rule}<p><ResourceText text={rule} /></p>{/each}
|
||||
</section>
|
||||
{:else}<p>No active effects.</p>{/each}
|
||||
<div class="active-effects-list">
|
||||
{#each effects as effect}
|
||||
<section class="active-effect-rule">
|
||||
<h3>{printedCardName(effect.name)}</h3>
|
||||
{#if effect.source}{@const source = effectSourceReference(effect, events, cards)}
|
||||
<div class="effect-source">
|
||||
{#if effect.source.kind === 'Event'}<ScrollText size={14} />{:else}<Layers size={14} />{/if}
|
||||
<span>{effect.source.kind}</span><span aria-hidden="true">·</span>
|
||||
{#if source}<button
|
||||
class="journal-research-link"
|
||||
title={`View ${printedCardName(effect.source.name)} rules`}
|
||||
onclick={() => (reference = source)}
|
||||
>{printedCardName(
|
||||
effect.source.name,
|
||||
)}{#if effect.source.kind === 'Event' && effect.source.id != null}
|
||||
{' '}(E{effect.source.id}){/if}</button
|
||||
>{:else}<span>{printedCardName(effect.source.name)}</span>{/if}
|
||||
</div>{/if}
|
||||
<small
|
||||
>{effect.players.length
|
||||
? effect.players
|
||||
.map(
|
||||
(index) => players.find((player) => player.index === index)?.civilization ?? effect.scope,
|
||||
)
|
||||
.join(' · ')
|
||||
: effect.scope}</small
|
||||
>
|
||||
{#each effect.rules as rule}<p><ResourceText text={rule} /></p>{/each}
|
||||
</section>
|
||||
{:else}<p>No active effects.</p>{/each}
|
||||
</div>
|
||||
</dialog>
|
||||
{#if reference?.kind === 'event'}<EventReferenceDialog
|
||||
event={reference.event}
|
||||
onClose={() => (reference = null)}
|
||||
/>{:else if reference?.kind === 'card'}<CardReferenceDialog
|
||||
card={reference.card}
|
||||
onDismiss={() => (reference = null)}
|
||||
/>{/if}
|
||||
|
||||
<style>
|
||||
.active-effects-list {
|
||||
display: grid;
|
||||
gap: 1.25rem;
|
||||
}
|
||||
.active-effect-rule {
|
||||
padding: 1.1rem 0;
|
||||
border-top: 1px solid var(--border, #3b5564);
|
||||
padding: 1.1rem;
|
||||
border: 1px solid var(--border, #3b5564);
|
||||
border-radius: 8px;
|
||||
}
|
||||
.effect-source {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.35rem;
|
||||
margin: 0.4rem 0 0.55rem;
|
||||
color: var(--muted, #9ab8c7);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.active-effect-rule h3 {
|
||||
margin: 0 0 0.3rem;
|
||||
|
|
|
|||
|
|
@ -1764,7 +1764,7 @@
|
|||
{#if !$session.playback}<CardReveal {controller} />{/if}
|
||||
<PlaybackPanel {controller} />
|
||||
<PublicEffects {controller} />
|
||||
{#if effectsOpen}<ActiveEffectsDialog effects={$session.view?.activeEffects ?? []} players={$session.view?.players ?? []} onClose={() => effectsOpen = false} />{/if}
|
||||
{#if effectsOpen}<ActiveEffectsDialog effects={$session.view?.activeEffects ?? []} players={$session.view?.players ?? []} events={$session.view?.eventCatalog ?? []} cards={$session.view?.cardCatalog ?? []} onClose={() => effectsOpen = false} />{/if}
|
||||
{#if $session.toast}<div class="toast" role="status"><Check size={16} />{$session.toast}</div>{/if}
|
||||
{#if $session.objectivesOpen && $session.seat !== undefined}
|
||||
<dialog
|
||||
|
|
|
|||
30
web-client/src/EventReferenceDialog.svelte
Normal file
30
web-client/src/EventReferenceDialog.svelte
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<script lang="ts">
|
||||
import { ScrollText, X } from 'lucide-svelte';
|
||||
import { printedCardName } from './card-names';
|
||||
import type { EventInfo } from './types';
|
||||
import ResourceText from './ResourceText.svelte';
|
||||
let { event, onClose }: { event: EventInfo; onClose: () => void } = $props();
|
||||
function show(node: HTMLDialogElement) {
|
||||
node.showModal();
|
||||
}
|
||||
</script>
|
||||
|
||||
<dialog
|
||||
class="field-guide"
|
||||
aria-label={`${printedCardName(event.name)} rules`}
|
||||
use:show
|
||||
onclose={onClose}
|
||||
onclick={(e) => {
|
||||
if (e.target === e.currentTarget) onClose();
|
||||
}}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Escape') onClose();
|
||||
}}
|
||||
>
|
||||
<button class="close-guide icon-button" aria-label="Close card rules" onclick={onClose}
|
||||
><X size={20} /></button
|
||||
>
|
||||
<h2><ScrollText size={23} />{printedCardName(event.name)}</h2>
|
||||
<p class="tiny-label">Event · E{event.id}</p>
|
||||
{#each event.rules as rule}<p><ResourceText text={rule} /></p>{/each}
|
||||
</dialog>
|
||||
44
web-client/src/active-effects.test.ts
Normal file
44
web-client/src/active-effects.test.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { effectSourceReference } from './active-effects.ts';
|
||||
import type { ActiveEffect, EventInfo } from './types.ts';
|
||||
import type { CardRule } from './card-reference.ts';
|
||||
|
||||
test('effects open the actual source event or action card using stable references', () => {
|
||||
const trojan = { id: 42, name: 'Trojan Horse', rules: ['Printed rules'] } as EventInfo;
|
||||
const card = {
|
||||
id: 29,
|
||||
name: 'Mass Production',
|
||||
description: 'Two additional tiles',
|
||||
tactics: { name: 'Defensive Formation', description: 'Battle use' },
|
||||
} as CardRule;
|
||||
const effect = { source: { kind: 'Event', name: 'Trojan Horse', id: 42 } } as ActiveEffect;
|
||||
assert.deepEqual(effectSourceReference(effect, [trojan], [card]), { kind: 'event', event: trojan });
|
||||
assert.deepEqual(
|
||||
effectSourceReference(
|
||||
{ ...effect, source: { kind: 'Action card', name: 'Mass Production' } },
|
||||
[trojan],
|
||||
[card],
|
||||
),
|
||||
{ kind: 'card', card },
|
||||
);
|
||||
assert.equal(effectSourceReference(effect, [], [card]), null);
|
||||
assert.equal(effectSourceReference({ ...effect, source: undefined }, [trojan], [card]), null);
|
||||
});
|
||||
|
||||
test('action effect references distinguish copies with different battle uses', () => {
|
||||
const cards = [
|
||||
{ id: 29, name: 'Mass Production', tactics: { name: 'Defensive Formation' } },
|
||||
{ id: 30, name: 'Mass Production', tactics: { name: 'Encircled' } },
|
||||
] as CardRule[];
|
||||
const effect = { source: { kind: 'Action card', name: 'Mass Production', id: 30 } } as ActiveEffect;
|
||||
assert.equal(effectSourceReference(effect, [], cards)?.kind, 'card');
|
||||
const exact = effectSourceReference(effect, [], cards);
|
||||
assert.equal(exact?.kind === 'card' && exact.card.id, 30);
|
||||
const legacy = effectSourceReference(
|
||||
{ ...effect, source: { kind: 'Action card', name: 'Mass Production' } },
|
||||
[],
|
||||
cards,
|
||||
);
|
||||
assert.equal(legacy?.kind === 'card' && legacy.card.tactics, null);
|
||||
});
|
||||
19
web-client/src/active-effects.ts
Normal file
19
web-client/src/active-effects.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import type { ActiveEffect, EventInfo } from './types.ts';
|
||||
import type { CardRule } from './card-reference.ts';
|
||||
|
||||
export function effectSourceReference(effect: ActiveEffect, events: EventInfo[], cards: CardRule[]) {
|
||||
if (effect.source?.kind === 'Event') {
|
||||
const event = events.find((event) => event.id === effect.source?.id);
|
||||
return event ? { kind: 'event' as const, event } : null;
|
||||
}
|
||||
if (effect.source?.kind === 'Action card') {
|
||||
const matches = cards.filter((card) => card.name === effect.source?.name);
|
||||
const exact =
|
||||
effect.source.id == null ? undefined : matches.find((card) => card.id === effect.source?.id);
|
||||
// Legacy effects without an exact copy still expose the common action rules.
|
||||
// Never show another copy's different battle use.
|
||||
const card = exact ?? (matches.length > 1 ? { ...matches[0], tactics: null } : matches[0]);
|
||||
return card ? { kind: 'card' as const, card } : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -260,6 +260,7 @@ export interface InfluenceContext {
|
|||
threshold: number;
|
||||
}
|
||||
export interface ActiveEffect {
|
||||
source?: { kind: 'Event' | 'Action card'; name: string; id?: number | null };
|
||||
name: string;
|
||||
scope: string;
|
||||
players: number[];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue