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/MonsterAbilityCard.svelte | |
| 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/MonsterAbilityCard.svelte')
| -rw-r--r-- | web/src/lib/ui/cards/MonsterAbilityCard.svelte | 157 |
1 files changed, 157 insertions, 0 deletions
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> |
