summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/cards/AbilityText.svelte
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2026-11-16 22:19:39 +0100
committerJoel Klinghed <the_jk@spawned.biz>2026-11-16 22:19:39 +0100
commit94e2850fb73005f3fb30af8489905e5cdfb6fac5 (patch)
tree1aea8e7e6683af770f0c57c0fb654003778c9f16 /web/src/lib/ui/cards/AbilityText.svelte
parent4f50f2008f4d7c2a635f7f26861fcfc7f7504423 (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/AbilityText.svelte')
-rw-r--r--web/src/lib/ui/cards/AbilityText.svelte200
1 files changed, 200 insertions, 0 deletions
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>