diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2026-11-16 22:19:39 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2026-11-16 22:19:39 +0100 |
| commit | 94e2850fb73005f3fb30af8489905e5cdfb6fac5 (patch) | |
| tree | 1aea8e7e6683af770f0c57c0fb654003778c9f16 /web/src/lib/ui/cards | |
| parent | 4f50f2008f4d7c2a635f7f26861fcfc7f7504423 (diff) | |
Phase 4: cards and decks (M4)
Full card play in the browser: ability-line rendering, monster ability
decks, the full modifier-deck (AMD) suite, and the loot deck — all
server commands, faithful to the reference flows and layout.
Web (Svelte 5):
- Line renderer + in-game translations: $lib/game/line/ renders the
reference line_builder output (emphasis, range markers, element
styling); gameI18n.ts loads the /i18n/ in-game ability-text tables
(the client-side TranslationService equivalent)
- Card components: stat cards, monster ability cards (OG + FH styles,
rendered lines, element/flying tokens), modifier cards (gfx resolver
incl. P<n> perk graphics), loot cards (party-size value rules,
owner, enhancements)
- Monster ability decks: AbilityCardSlot in each monster row (front of
the current card while active in playTurns, else the back with the
draw-pile count); AbilityCardsMenu (reveal top cards, draw extra,
extra shuffle, activate/inactivate, drag-reorder, remove); card zoom
- Modifier decks: ModifierDeckWidget (tap to draw, face-up revealed top
card, empty-box class icon for the current character's own deck,
discard stack); ModifierDeckHeader (bad omen, corrosive spew,
±1/−2/+0, imbue 1/2, reveal with the Cassandra 8-button cap,
save/don't-save revealed cards, removed count, Hail perk, CS
sanctuary/party cards, faction icons, bless/curse and the
empower/enfeeble counters); ModifierDeckMenu (draw-pile
drag-reorder + send-to-bottom/shuffle/remove, discard
remove/return-top, removed pile with return, faction grid with
gray-out, perks menu with the Frosthaven opt-in); card zoom
- Loot deck: LootDeckWidget (player-gated draw, current-character
icon, discard stack, hidden when both piles empty); LootCardsMenu
(set owner, per-character loot totals, add card, enhance with the
reference material/herb/coin splits, special cards 1418/1419,
return top/bottom)
- Bottom DeckArea: loot deck left; the Character Decks toggle with the
reference open-state cycling (oneOpen/allOpen/noOpen per round
state; one-deck view for the current character during playTurns);
ally deck behind shouldShowAlliesDeck; global deck
- Pure helper modules ported from the reference: rules.ts (FH card
styling, inactive-for-rule, ally-deck gate, deck resolution),
modifierDeck.ts (pile derivations, faction cards), perks.ts (active
perk set, card-text tokens, descriptions, add/remove gating),
cards/lootCard.ts (values + per-character totals)
- App wiring: campaign data loaded on currentCampaign change (guarded
against out-of-order fetches); ability/AMD/loot menus and zooms
driven by live-derived state so open menus track pile changes;
Escape closes every dialog
Server:
- /i18n/ static mount: the in-game ability-text translation files the
card renderer resolves (the reference TranslationService data)
- Loot deck JSON gains pools (pool card ids per pool — the client
derives card gfx from pool key + index and reads the enhancements
map; ids only, since pool cards are the same live instances that
mutate in the piles)
- Modifier deck JSON gains removables (the counter totals the header
reads) plus load-time round-trip for saves written before the field
existed
Docs:
- PLAN.md: Phase 3 and Phase 4 marked complete (corrected the
'character ability decks' mislabel — ability decks are monster-only),
progress log entries for M3 and M4
svelte-check 0 errors; web tests 177/177; build OK; dart analyze
0 errors; dart test 592/592; scripts/ci.sh green.
Diffstat (limited to 'web/src/lib/ui/cards')
| -rw-r--r-- | web/src/lib/ui/cards/AbilityCardBack.svelte | 60 | ||||
| -rw-r--r-- | web/src/lib/ui/cards/AbilityText.svelte | 200 | ||||
| -rw-r--r-- | web/src/lib/ui/cards/LootCard.svelte | 114 | ||||
| -rw-r--r-- | web/src/lib/ui/cards/ModifierCard.svelte | 124 | ||||
| -rw-r--r-- | web/src/lib/ui/cards/MonsterAbilityCard.svelte | 157 |
5 files changed, 655 insertions, 0 deletions
diff --git a/web/src/lib/ui/cards/AbilityCardBack.svelte b/web/src/lib/ui/cards/AbilityCardBack.svelte new file mode 100644 index 0000000..362ced1 --- /dev/null +++ b/web/src/lib/ui/cards/AbilityCardBack.svelte @@ -0,0 +1,60 @@ +<!-- + The back of a monster ability card (the reference + `MonsterAbilityCardRear`): the card artwork with the draw-pile size in + the bottom-right corner (hidden when `size` is negative). +--> +<script lang="ts"> + let { + fh = true, + size = -1, + scale = 1 + }: { + fh?: boolean; + /** The draw-pile count shown bottom-right; negative hides it. */ + size?: number; + scale?: number; + } = $props(); + + const width = 142.4 * scale; + const height = 94.4 * scale; +</script> + +<div + class="acback" + style="width: {width}px; height: {height}px" +> + <img + class="acback__bg" + src={fh ? '/images/psd/MonsterAbility-back_fh.png' : '/images/psd/MonsterAbility-back.png'} + alt="" + draggable="false" + /> + {#if size >= 0} + <div class="acback__size" style="font-size: {12.8 * scale}px">{size}</div> + {/if} +</div> + +<style> + .acback { + position: relative; + border-radius: 4px; + flex-shrink: 0; + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); + } + .acback__bg { + position: absolute; + inset: 0; + width: 100%; + height: 100%; + border-radius: 4px; + object-fit: fill; + } + .acback__size { + position: absolute; + right: 4.8px; + bottom: 0; + font-family: system-ui, sans-serif; + color: #fff; + text-shadow: 0.8px 0.8px 1px #000; + } +</style> diff --git a/web/src/lib/ui/cards/AbilityText.svelte b/web/src/lib/ui/cards/AbilityText.svelte new file mode 100644 index 0000000..51fe672 --- /dev/null +++ b/web/src/lib/ui/cards/AbilityText.svelte @@ -0,0 +1,200 @@ +<!-- + The ability-line renderer (the web counterpart of the reference + `LineBuilder.createLines` output, PORTING.md §8b). Walks the structured + tree produced by `parseLines` and renders it: rows of text / icons / + element-use, gray sub-line boxes, dotted conditional boxes, columns, + row-groups, element images and dividers. Font metrics come from + `resolveStyle` (the reference `LineStyles`); icons come from the served + `/images/abilities/` assets. +--> +<script lang="ts"> + import type { LineStyle, Node } from '$lib/game/line/types'; + import { resolveStyle } from '$lib/game/line/lineStyle'; + import { abilityImage, dividerImage } from '$lib/game/line/images'; + + let { + node, + fh = true, + left = false, + scale = 1 + }: { + node: Node; + fh?: boolean; + left?: boolean; + scale?: number; + } = $props(); + + /** The resolved font metrics for a style. */ + function r(style: LineStyle) { + return resolveStyle(style, fh, left); + } +</script> + +{#if node.kind === 'column'} + <div class="at-col" style="align-items: {node.align === 'left' ? 'flex-start' : node.align === 'right' ? 'flex-end' : 'center'}"> + {#each node.children as child} + <svelte:self node={child} {fh} {left} {scale} /> + {/each} + </div> +{:else if node.kind === 'row' || node.kind === 'rowgroup'} + <div + class="at-row" + class:at-row--group={node.kind === 'rowgroup'} + style="justify-content: {node.align === 'left' ? 'flex-start' : node.align === 'right' ? 'flex-end' : 'center'}" + > + {#each node.children as child} + <svelte:self node={child} {fh} {left} {scale} /> + {/each} + </div> +{:else if node.kind === 'subline'} + <div class="at-subline" class:at-subline--boss={node.boss}> + {#each node.children as child} + <svelte:self node={child} {fh} {left} {scale} /> + {/each} + </div> +{:else if node.kind === 'conditional'} + <div class="at-conditional" class:at-conditional--boss={node.boss} class:at-conditional--banner={node.belongs}> + {#if node.belongs} + <img class="at-conditional__banner" src="/images/abilities/element_top.png" alt="" /> + {/if} + <div class="at-conditional__inner"> + {#each node.children as child} + <svelte:self node={child} {fh} {left} {scale} /> + {/each} + </div> + </div> +{:else if node.kind === 'text'} + {@const m = r(node.style)} + {#if m.color !== 'transparent'} + <span + class="at-text" + style="font-size: {m.size * scale}px; line-height: {m.height}; color: {m.color}" + >{node.text}</span> + {:else} + <span style="display: inline-block; width: {m.size * scale}px"></span> + {/if} +{:else if node.kind === 'token'} + {@const h = r(node.style).size * scale} + <img + class="at-token" + src={abilityImage(node.gfx, node.token, fh)} + alt={node.token} + style="height: {h}px; width: {h}px" + draggable="false" + /> +{:else if node.kind === 'elementUse'} + {@const h = r(node.style).size * scale} + <span class="at-use" style="height: {h}px; width: {h}px"> + <img src={abilityImage(node.element, node.element, fh)} alt={node.element} style="height: {h}px; width: {h}px" draggable="false" /> + <img + class="at-use__use" + src={abilityImage('use', 'use', fh)} + alt="use" + style="height: {h * 0.5}px" + draggable="false" + /> + </span> +{:else if node.kind === 'image'} + {@const h = r('normal').size * scale * (node.element ? 0.6 : 1)} + <img + class="at-image" + src={abilityImage(node.gfx, node.gfx, fh)} + alt={node.gfx} + style="height: {h}px" + draggable="false" + /> +{:else if node.kind === 'divider'} + <img + class="at-divider" + src={dividerImage(node.boss)} + alt="" + style="height: {node.thin ? 2 * scale : 6 * scale}px; width: {55 * scale}px" + draggable="false" + /> +{/if} + +<style> + .at-col { + display: flex; + flex-direction: column; + justify-content: center; + width: 100%; + } + .at-row { + display: flex; + flex-direction: row; + align-items: center; + width: 100%; + } + .at-row--group { + gap: 2px; + } + .at-text { + font-family: 'Markazi', 'Majalla', system-ui, sans-serif; + white-space: pre-wrap; + text-shadow: 0.4px 0.4px 1px rgba(0, 0, 0, 0.87); + } + .at-token { + display: inline-block; + vertical-align: middle; + flex-shrink: 0; + } + .at-image { + display: block; + margin: 0 auto; + } + .at-divider { + display: block; + margin: 0 auto; + opacity: 0.9; + } + .at-use { + position: relative; + display: inline-block; + vertical-align: middle; + flex-shrink: 0; + } + .at-use__use { + position: absolute; + bottom: 0; + left: 20%; + } + .at-subline { + display: flex; + flex-direction: column; + background: rgba(128, 128, 128, 0.6); + border-radius: 6px; + padding: 0.5px 2.5px 0.3px 2px; + margin: 0 2px; + } + .at-subline--boss { + background: rgba(210, 210, 210, 0.27); + } + .at-subline .at-row { + justify-content: flex-start; + } + .at-conditional { + position: relative; + display: inline-block; + margin: 2px; + } + .at-conditional__inner { + display: flex; + flex-direction: column; + background: rgba(128, 128, 128, 0.6); + border: 1.5px dotted rgba(255, 255, 255, 0.85); + border-radius: 10px; + padding: 2px 2px 0.5px 2px; + } + .at-conditional--boss .at-conditional__inner { + background: rgba(210, 210, 210, 0.27); + } + .at-conditional__banner { + position: absolute; + top: -3px; + left: 50%; + transform: translateX(-50%); + width: 20px; + z-index: 1; + } +</style> diff --git a/web/src/lib/ui/cards/LootCard.svelte b/web/src/lib/ui/cards/LootCard.svelte new file mode 100644 index 0000000..49ddb2b --- /dev/null +++ b/web/src/lib/ui/cards/LootCard.svelte @@ -0,0 +1,114 @@ +<!-- + One loot card (the reference `LootCardFront` / `LootCardRear`): the loot + `gfx` image with its value (`+n`), the 1418/1419 special text, the + enhancement level, and the owning character's class icon. +--> +<script lang="ts"> + import type { LootCard as Card } from '$lib/protocol/types'; + import { lootValue } from '$lib/game/cards/lootCard'; + import { t } from '$lib/i18n'; + + let { + card, + revealed, + ownerName = '', + characterCount = 4, + scale = 1 + }: { + card: Card; + revealed: boolean; + /** The owning character's class name (for the corner icon). */ + ownerName?: string; + /** Party size (the value table depends on it). */ + characterCount?: number; + scale?: number; + } = $props(); + + const width = 39 * scale; + const height = 58.6666 * scale; + + const value = $derived(revealed ? lootValue(card, characterCount) : null); + const special = $derived( + revealed + ? card.gfx.includes('1418') + ? '1418' + : card.gfx.includes('1419') + ? '1419' + : '' + : '' + ); + const showOwner = $derived(revealed && card.owner.length > 0); +</script> + +<div class="lootcard" style="width: {width}px; height: {height}px"> + <img + class="lootcard__bg" + src={revealed ? `/images/loot/${card.gfx}.png` : '/images/loot/back.png'} + alt={card.gfx} + draggable="false" + /> + {#if value !== null} + <div class="lootcard__value" style="font-size: {30 * scale}px">+{value}</div> + {/if} + {#if special} + <div class="lootcard__value" style="font-size: {25 * scale}px">{special}</div> + {/if} + {#if revealed && card.enhanced > 0} + <div class="lootcard__enhanced" style="font-size: {9 * scale}px"> + {t('enhancedLevel', { level: card.enhanced })} + </div> + {/if} + {#if showOwner} + <img + class="lootcard__owner" + src="/images/class-icons/{ownerName}.png" + alt={ownerName} + style="width: {15 * scale}px; height: {15 * scale}px" + draggable="false" + /> + {/if} +</div> + +<style> + .lootcard { + position: relative; + border-radius: 4px; + flex-shrink: 0; + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); + } + .lootcard__bg { + position: absolute; + inset: 0; + width: 100%; + height: 100%; + border-radius: 4px; + object-fit: fill; + } + .lootcard__value { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + font-family: system-ui, sans-serif; + font-weight: 700; + color: #fff; + text-shadow: 0.6px 0.6px 1px rgba(0, 0, 0, 0.87); + pointer-events: none; + } + .lootcard__enhanced { + position: absolute; + bottom: 5px; + left: 0; + right: 0; + text-align: center; + color: #fff; + text-shadow: 0.3px 0.3px 0.8px rgba(0, 0, 0, 0.87); + pointer-events: none; + } + .lootcard__owner { + position: absolute; + top: 2px; + right: 2px; + filter: brightness(0) invert(1); + } +</style> diff --git a/web/src/lib/ui/cards/ModifierCard.svelte b/web/src/lib/ui/cards/ModifierCard.svelte new file mode 100644 index 0000000..e5e7bf7 --- /dev/null +++ b/web/src/lib/ui/cards/ModifierCard.svelte @@ -0,0 +1,124 @@ +<!-- + One modifier (AMD) card (the reference `ModifierCardFront` / + `ModifierCardRear`): the `gfx` image with an optional corner marker + (imbue / faction / perk / class icon). `name` is the owning deck — the + shared party deck (""), "allies", or a character-class name. Pass + `perks` for a character deck so `P<n>` graphics resolve. +--> +<script lang="ts"> + import type { ModifierCard as Card } from '$lib/protocol/types'; + import { + extraGfxUrl, + gfxUrl, + hasExtra, + rearMarker + } from '$lib/game/cards/modifierCardGfx'; + + let { + card, + name, + revealed, + perks = null, + scale = 1 + }: { + card: Card; + name: string; + revealed: boolean; + perks?: string[][] | null; + scale?: number; + } = $props(); + + const width = 58.6666 * scale; + const height = 39 * scale; + + const frontGfx = $derived(gfxUrl(card, name, perks)); + const frontExtra = $derived(extraGfxUrl(card, name)); + const showExtra = $derived(hasExtra(card, name)); + const rear = $derived(rearMarker(name)); +</script> + +<div + class="modcard" + style="width: {width}px; height: {height}px; --scale: {scale}" +> + {#if revealed} + <img + class="modcard__bg" + src={frontGfx} + alt={card.gfx} + draggable="false" + /> + {#if showExtra} + <img + class="modcard__marker-bg" + src="/images/attack/class-marker-background.png" + alt="" + draggable="false" + /> + <img class="modcard__marker-icon" src={frontExtra} alt="" draggable="false" /> + {/if} + {:else} + <img + class="modcard__bg" + src="/images/attack/back.png" + alt="" + draggable="false" + /> + {#if rear.has} + <img + class="modcard__rear-bg" + src="/images/attack/class-marker-background.png" + alt="" + draggable="false" + /> + <img class="modcard__rear-icon" src={rear.gfx} alt="" draggable="false" /> + {/if} + {/if} +</div> + +<style> + .modcard { + position: relative; + border-radius: 4px; + flex-shrink: 0; + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); + } + .modcard__bg { + position: absolute; + inset: 0; + width: 100%; + height: 100%; + border-radius: 4px; + object-fit: fill; + } + .modcard__marker-bg { + position: absolute; + top: calc(26.5 * var(--scale) * 1px); + left: calc(3 * var(--scale) * 1px); + width: calc(10 * var(--scale) * 1px); + height: calc(10 * var(--scale) * 1px); + } + .modcard__marker-icon { + position: absolute; + top: calc(27.75 * var(--scale) * 1px); + left: calc(4.2 * var(--scale) * 1px); + width: calc(7.5 * var(--scale) * 1px); + height: calc(7.5 * var(--scale) * 1px); + filter: brightness(0) invert(1); + } + .modcard__rear-bg { + position: absolute; + top: calc(5.5 * var(--scale) * 1px); + left: calc(15.7 * var(--scale) * 1px); + width: calc(27 * var(--scale) * 1px); + height: calc(27 * var(--scale) * 1px); + } + .modcard__rear-icon { + position: absolute; + top: calc(9 * var(--scale) * 1px); + left: calc(19 * var(--scale) * 1px); + width: calc(20 * var(--scale) * 1px); + height: calc(20 * var(--scale) * 1px); + filter: brightness(0) invert(1); + } +</style> diff --git a/web/src/lib/ui/cards/MonsterAbilityCard.svelte b/web/src/lib/ui/cards/MonsterAbilityCard.svelte new file mode 100644 index 0000000..5310874 --- /dev/null +++ b/web/src/lib/ui/cards/MonsterAbilityCard.svelte @@ -0,0 +1,157 @@ +<!-- + A monster ability card (the reference `MonsterAbilityCardFront`): the card + back with title, initiative, card number, shuffle badge, positioned + graphics, and the ability lines rendered by {@link AbilityText} from the + `parseLines` tree. +--> +<script lang="ts"> + import type { MonsterAbilityCard } from '$lib/protocol/types'; + import type { StatMonster } from '$lib/game/line/statApplier'; + import type { ColumnNode } from '$lib/game/line/types'; + import { buildAbilityCardTree } from '$lib/game/line/buildAbility'; + import { gt, gameTable } from '$lib/i18n/gameI18n'; + import { isElement } from '$lib/game/line/tokens'; + import AbilityText from './AbilityText.svelte'; + + let { + card, + stat, + fh = true, + flying = false, + scale = 1, + applyStats = true, + applyAll = false + }: { + card: MonsterAbilityCard; + stat: StatMonster | null; + fh?: boolean; + flying?: boolean; + scale?: number; + applyStats?: boolean; + applyAll?: boolean; + } = $props(); + + // The tree re-resolves when the in-game locale table changes. + const tree = $derived.by(() => { + void $gameTable; + return buildAbilityCardTree(card, stat, { + fh, + flying, + scale, + applyStats, + applyAll + }) as ColumnNode; + }); + + const width = 142.4 * scale; + const height = 94.4 * scale; + + const initText = $derived( + card.initiative.toString().length === 1 + ? `0${card.initiative}` + : card.initiative.toString() + ); +</script> + +<div + class="mac" + style="width: {width}px; height: {height}px; --scale: {scale}" +> + <img + class="mac__bg" + src={fh ? '/images/psd/monsterAbility-front_fh.png' : '/images/psd/monsterAbility-front.png'} + alt="" + draggable="false" + /> + + {#each card.graphics.slice(0, 4) as g} + <img + class="mac__gfx" + src={`/images/abilities/${g.gfx}.png`} + alt="" + draggable="false" + style="left: {g.x * width}px; top: {g.y * height}px; transform: rotate({g.angle}deg) scale({g.scale * scale * (isElement(g.gfx) ? 0.264 : 0.44)}); transform-origin: top left" + /> + {/each} + + <div class="mac__title" style="font-size: {fh ? 10 * scale : 11.2 * scale}px"> + {gt(card.title)} + </div> + <div class="mac__init" style="font-size: {fh ? 15 * scale : 16 * scale}px"> + {initText} + </div> + <div class="mac__nr" style="font-size: {6.4 * scale}px">{card.nr}</div> + + {#if card.shuffle} + <img class="mac__shuffle" src="/images/abilities/shuffle.png" alt="shuffle" draggable="false" style="height: {12.8 * scale}px" /> + {/if} + + <div class="mac__lines"> + <AbilityText node={tree} {fh} {scale} /> + </div> +</div> + +<style> + .mac { + position: relative; + border-radius: 8px; + flex-shrink: 0; + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); + } + .mac__bg { + position: absolute; + inset: 0; + width: 100%; + height: 100%; + border-radius: 8px; + object-fit: fill; + } + .mac__gfx { + position: absolute; + } + .mac__title { + position: absolute; + top: 2px; + left: 0; + right: 0; + text-align: center; + font-family: 'Markazi', 'Majalla', system-ui, sans-serif; + color: #fff; + text-shadow: 0.6px 0.6px 1px rgba(0, 0, 0, 0.87); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + .mac__init { + position: absolute; + left: 4px; + top: 12.8px; + font-family: 'Markazi', 'Majalla', system-ui, sans-serif; + color: #fff; + text-shadow: 0.6px 0.6px 1px rgba(0, 0, 0, 0.87); + } + .mac__nr { + position: absolute; + left: 4.8px; + bottom: 0.4px; + font-family: system-ui, sans-serif; + color: #fff; + text-shadow: 0.6px 0.6px 1px rgba(0, 0, 0, 0.87); + } + .mac__shuffle { + position: absolute; + right: 6px; + bottom: 3.2px; + } + .mac__lines { + position: absolute; + top: 11px; + left: 0; + right: 0; + bottom: 0; + display: flex; + align-items: center; + justify-content: center; + padding: 0 4px; + } +</style> |
