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/decks/AbilityCardsMenu.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/decks/AbilityCardsMenu.svelte')
| -rw-r--r-- | web/src/lib/ui/decks/AbilityCardsMenu.svelte | 307 |
1 files changed, 307 insertions, 0 deletions
diff --git a/web/src/lib/ui/decks/AbilityCardsMenu.svelte b/web/src/lib/ui/decks/AbilityCardsMenu.svelte new file mode 100644 index 0000000..0cf416c --- /dev/null +++ b/web/src/lib/ui/decks/AbilityCardsMenu.svelte @@ -0,0 +1,307 @@ +<!-- + The monster ability-card deck menu (the reference `AbilityCardsMenu`): + "Reveal cards:" buttons (local flip of the top draw-pile cards, 1-8 / + All), Draw extra card, Extra Shuffle, Activate/Inactivate Monster, then + the two card columns — the draw pile (face down unless revealed, + drag-reorderable, tap to remove) and the discard pile (face up, tap to + remove). +--> +<script lang="ts"> + import type { GameSession } from '$lib/state/session'; + import type { + MonsterAbilityCard as AbilityCard, + MonsterAbilityCardRef, + MonsterAbilityState, + MonsterItem + } from '$lib/protocol/types'; + import type { CampaignData } from '$lib/data/gameData'; + import { t } from '$lib/i18n'; + import MonsterAbilityCard from '../cards/MonsterAbilityCard.svelte'; + import AbilityCardBack from '../cards/AbilityCardBack.svelte'; + import Menu from '../Menu.svelte'; + + const LIST_CARD_SCALE = 0.55; + const MAX_REVEAL_BUTTONS = 8; + + let { + session, + item, + deck, + campaignData, + fh, + open = $bindable(true) + }: { + session: GameSession; + item: MonsterItem; + deck: MonsterAbilityState; + campaignData: CampaignData | null; + fh: boolean; + open?: boolean; + } = $props(); + + const gameState = session.state; + const player = session.player; + + const model = $derived( + campaignData?.monsters.find( + (m) => m.name === item.type || m.display === item.type + ) ?? null + ); + + // Top-first lists (the reference reverses the bottom-first draw pile). + const drawTopFirst = $derived([...deck.drawPile].reverse()); + const discardList = $derived(deck.discardPile); + + // The locally-revealed top cards (menu-only, not a deck command). + let revealedCount = $state(0); + // Reset the local reveal whenever the draw pile changes. + const drawSignature = $derived( + deck.drawPile.map((c) => `${c.nr}`).join(',') + ); + $effect(() => { + void drawSignature; + revealedCount = 0; + }); + + const revealButtons = $derived( + Math.min(drawTopFirst.length, MAX_REVEAL_BUTTONS) + ); + + function fullCard(ref: MonsterAbilityCardRef): AbilityCard | null { + const list = campaignData?.abilityDecks[ref.deck] ?? []; + return list.find((c) => c.nr === ref.nr) ?? null; + } + + function cmd(name: string, args: Record<string, unknown> = {}) { + if ($player) session.command(name, args); + } + + // --- remove-card confirmation ------------------------------------------- + + let removeTarget = $state<MonsterAbilityCardRef | null>(null); + + // --- draw-pile reordering (HTML5 drag & drop) ---------------------------- + + let dragIndex = $state<number | null>(null); + let dropIndex = $state<number | null>(null); + + function onDragStart(i: number) { + dragIndex = i; + } + function onDragOver(e: DragEvent, i: number) { + e.preventDefault(); + dropIndex = i; + } + function onDrop() { + if (dragIndex != null && dropIndex != null && dragIndex !== dropIndex) { + // The list is top-first; the wire pile is bottom-first. + const n = deck.drawPile.length; + const oldIndex = n - 1 - dragIndex; + const newIndex = n - 1 - dropIndex; + cmd('reorderAbilityList', { + deck: deck.name, + oldIndex, + newIndex + }); + } + dragIndex = null; + dropIndex = null; + } +</script> + +<Menu {open} title={item.id}> + {#if $gameState && $player} + <div class="bar"> + <span class="bar__label">{t('revealCards')}</span> + {#each Array(revealButtons) as _, i} + <button + class="pill" + class:pill--wide={i + 1 >= drawTopFirst.length} + onclick={() => (revealedCount = i + 1 >= drawTopFirst.length ? drawTopFirst.length : i + 1)} + > + {i + 1 >= drawTopFirst.length ? t('revealAll') : i + 1} + </button> + {/each} + <button class="pill pill--text" onclick={() => cmd('drawAbilityCard', { ownerId: item.type })}> + {t('drawExtraCard')} + </button> + <button + class="pill pill--text" + onclick={() => { + revealedCount = 0; + cmd('shuffleAbilityCard', { ownerId: item.type }); + }} + > + {t('extraShuffle')} + </button> + <button + class="pill pill--text" + onclick={() => + cmd('activateMonsterType', { + name: item.type, + activate: !item.isActive + })} + > + {item.isActive ? t('inactivateMonster') : t('activateMonster')} + </button> + </div> + + <div class="columns"> + <div class="col" ondragend={() => (dragIndex = null)} ondrop={onDrop}> + {#each drawTopFirst as ref, i} + {@const c = fullCard(ref)} + <div + class="cardwrap" + draggable + ondragstart={() => onDragStart(i)} + ondragover={(e) => onDragOver(e, i)} + onclick={() => (removeTarget = ref)} + role="button" + tabindex="0" + onkeydown={(e) => { + if (e.key === 'Enter' || e.key === ' ') + removeTarget = ref; + }} + > + {#if c != null && i < revealedCount} + <MonsterAbilityCard + card={c} + stat={null} + {fh} + scale={LIST_CARD_SCALE} + applyAll + /> + {:else} + <AbilityCardBack {fh} scale={LIST_CARD_SCALE} /> + {/if} + </div> + {/each} + </div> + + <div class="col"> + {#each discardList as ref} + {@const c = fullCard(ref)} + {#if c != null} + <div + class="cardwrap" + onclick={() => (removeTarget = ref)} + role="button" + tabindex="0" + onkeydown={(e) => { + if (e.key === 'Enter' || e.key === ' ') + removeTarget = ref; + }} + > + <MonsterAbilityCard + card={c} + stat={null} + {fh} + scale={LIST_CARD_SCALE} + applyAll + /> + </div> + {/if} + {/each} + </div> + </div> + {:else if $gameState} + <p class="spectate">{t('web:spectator')}</p> + {/if} + + {#if removeTarget} + {@const rt = removeTarget} + {@const card = fullCard(rt)} + <div class="confirm" role="dialog" aria-modal="true"> + {#if card != null} + <MonsterAbilityCard + card={card} + stat={null} + {fh} + scale={0.8} + applyAll + /> + {/if} + <div class="confirm__btns"> + <button + class="pill pill--text" + onclick={() => { + cmd('removeCard', { deck: rt.deck, nr: rt.nr }); + removeTarget = null; + }} + > + {t('removeCardQuestion')} + </button> + </div> + </div> + {/if} +</Menu> + +<style> + .bar { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 4px; + margin-bottom: 10px; + } + .bar__label { + font-size: 13px; + font-weight: 600; + white-space: pre; + } + .pill { + min-width: 32px; + padding: 4px 8px; + font-size: 13px; + border: none; + border-radius: 4px; + background: rgba(255, 255, 255, 0.12); + color: inherit; + cursor: pointer; + white-space: pre; + } + .pill:hover { + background: rgba(255, 255, 255, 0.25); + } + .pill--text { + min-width: 0; + } + .columns { + display: flex; + gap: 12px; + align-items: flex-start; + } + .col { + flex: 1; + display: flex; + flex-direction: column; + gap: 6px; + max-height: 60vh; + overflow-y: auto; + } + .cardwrap { + cursor: pointer; + border-radius: 6px; + } + .cardwrap:focus-visible { + outline: 2px solid #7ec8ff; + } + .confirm { + display: flex; + flex-direction: column; + align-items: center; + gap: 10px; + margin-top: 10px; + padding: 10px; + border-radius: 8px; + background: rgba(0, 0, 0, 0.35); + } + .confirm__btns { + display: flex; + gap: 8px; + } + .spectate { + font-size: 13px; + opacity: 0.7; + } +</style> |
