Skip to content

fix(client): count mana shards serialized as engine variant names#5065

Open
jeffrey701 wants to merge 1 commit into
phase-rs:mainfrom
jeffrey701:fix/dominant-color-shard-format
Open

fix(client): count mana shards serialized as engine variant names#5065
jeffrey701 wants to merge 1 commit into
phase-rs:mainfrom
jeffrey701:fix/dominant-color-shard-format

Conversation

@jeffrey701

Copy link
Copy Markdown
Contributor

Problem

getDominantManaColor / getDeckDominantColor (client/src/viewmodel/dominantColor.ts) key SHARD_TO_COLOR by Scryfall symbols (W/U/B/R/G), but the engine serializes mana_cost.shards as Rust variant names"White", "WhiteBlue", "TwoWhite", "PhyrexianWhite", … (see SHARD_ABBREVIATION in costLabel.ts, manaValueOfShard in manaValue.ts, and the fixtures used across the client). So every non-land spell shard misses the map: colored pips are silently dropped and the auto-WUBRG BattlefieldBackground (the sole consumer) ignores spell colors entirely. Hybrid/gold spells are doubly broken — the split("/") half-counting never fires because the engine emits "WhiteBlue", not "W/U".

Fix

Bridge each shard through the canonical SHARD_ABBREVIATION map (the same map manaCostToShards / manaAvailability already use) before splitting hybrids, with a ?? shard fallback that still accepts an already-symbolic shard. Now White→W, WhiteBlue→W/U (both halves), TwoWhite→2/W (W), PhyrexianWhite→W/P (W); X/Colorless correctly contribute no color.

Tests

Adds discriminating tests using the real variant-name wire format — they fail on the current code (the shard misses the map → null) and pass after the fix. The existing symbol-format test still passes via the ?? shard fallback (no regression). tsc -b --noEmit and eslint clean; vitest 12/12.

Self-contained: only dominantColor.ts + its test; no engine/Rust/protocol changes.

Model: claude-opus-4-8

getDominantManaColor / getDeckDominantColor keyed SHARD_TO_COLOR by Scryfall
symbols (W/U/B/R/G), but the engine serializes mana_cost.shards as Rust variant
names ("White", "WhiteBlue", "TwoWhite", "PhyrexianWhite"…), so every
non-land spell's colored pips were silently dropped and the auto-WUBRG
BattlefieldBackground ignored spell colors entirely.

Bridge each shard through the canonical SHARD_ABBREVIATION map (the same one
manaCostToShards/manaAvailability use) before splitting hybrids, with a
`?? shard` fallback that still accepts an already-symbolic shard. Hybrid
("WhiteBlue"→W/U), monocolored-hybrid ("TwoWhite"→2/W → W), and Phyrexian
("PhyrexianWhite"→W/P → W) shards now contribute their colors; X/Colorless
correctly contribute none.

Adds discriminating tests using the real variant-name wire format (they fail
without the fix); the existing symbol-format test still passes via the fallback.
@jeffrey701 jeffrey701 requested a review from matthewevans as a code owner July 4, 2026 05:03
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@matthewevans matthewevans added the defer-fe Frontend/client/UI PR deferred to Matt's direct review label Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

defer-fe Frontend/client/UI PR deferred to Matt's direct review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants