summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/decks
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/lib/ui/decks')
-rw-r--r--web/src/lib/ui/decks/AbilityCardSlot.svelte121
-rw-r--r--web/src/lib/ui/decks/AbilityCardZoom.svelte71
-rw-r--r--web/src/lib/ui/decks/AbilityCardsMenu.svelte307
-rw-r--r--web/src/lib/ui/decks/DeckArea.svelte222
-rw-r--r--web/src/lib/ui/decks/LootCardsMenu.svelte492
-rw-r--r--web/src/lib/ui/decks/LootDeckWidget.svelte163
-rw-r--r--web/src/lib/ui/decks/LootEnhancementCounter.svelte77
-rw-r--r--web/src/lib/ui/decks/ModifierCardZoom.svelte56
-rw-r--r--web/src/lib/ui/decks/ModifierDeckHeader.svelte460
-rw-r--r--web/src/lib/ui/decks/ModifierDeckMenu.svelte570
-rw-r--r--web/src/lib/ui/decks/ModifierDeckWidget.svelte185
11 files changed, 2724 insertions, 0 deletions
diff --git a/web/src/lib/ui/decks/AbilityCardSlot.svelte b/web/src/lib/ui/decks/AbilityCardSlot.svelte
new file mode 100644
index 0000000..8b5250c
--- /dev/null
+++ b/web/src/lib/ui/decks/AbilityCardSlot.svelte
@@ -0,0 +1,121 @@
+<!--
+ One monster's ability card in its row (the reference
+ `MonsterAbilityCardWidget`): the front of the current (top discard)
+ card while the round is playing turns and the monster is active,
+ else the card back with the draw-pile size. Tap opens the deck
+ menu; double-tap (front only) zooms the card.
+-->
+<script lang="ts">
+ import type {
+ GameState,
+ MonsterAbilityCard as AbilityCard,
+ MonsterAbilityState,
+ MonsterItem
+ } from '$lib/protocol/types';
+ import type { CampaignData } from '$lib/data/gameData';
+ import type { StatMonster } from '$lib/game/line/statApplier';
+ import { statMonsterFor } from '$lib/game/line/buildAbility';
+ import { isInactiveForRule } from '$lib/game/rules';
+ import MonsterAbilityCard from '../cards/MonsterAbilityCard.svelte';
+ import AbilityCardBack from '../cards/AbilityCardBack.svelte';
+
+ const ROW_CARD_SCALE = 0.72;
+
+ let {
+ state,
+ item,
+ deck,
+ campaignData,
+ fh,
+ onOpen,
+ onZoom
+ }: {
+ state: GameState;
+ item: MonsterItem;
+ /** This monster's ability deck (matched by model deck name), if any. */
+ deck: MonsterAbilityState | null;
+ campaignData: CampaignData | null;
+ fh: boolean;
+ onOpen: () => void;
+ onZoom: () => void;
+ } = $props();
+
+ const model = $derived(
+ campaignData?.monsters.find(
+ (m) => m.name === item.type || m.display === item.type
+ ) ?? null
+ );
+
+ const showFront = $derived(
+ state.roundState === 1 &&
+ item.isActive &&
+ !isInactiveForRule(state, item.type) &&
+ deck != null &&
+ deck.discardPile.length > 0
+ );
+
+ const cardRef = $derived(
+ showFront && deck != null
+ ? deck.discardPile[deck.discardPile.length - 1]
+ : null
+ );
+ const card = $derived.by((): AbilityCard | null => {
+ if (cardRef == null) return null;
+ const list = campaignData?.abilityDecks[cardRef.deck] ?? [];
+ return list.find((c) => c.nr === cardRef.nr) ?? null;
+ });
+
+ const stat = $derived.by((): StatMonster | null => {
+ if (model == null) return null;
+ return statMonsterFor(
+ model,
+ item.level,
+ item.monsterInstances.map((s) => s.type),
+ item.isActive
+ );
+ });
+
+ function onKeydown(e: KeyboardEvent) {
+ if (e.key === 'Enter' || e.key === ' ') {
+ e.preventDefault();
+ onOpen();
+ }
+ }
+</script>
+
+<div
+ class="slot"
+ role="button"
+ tabindex="0"
+ aria-label="ability cards"
+ onclick={onOpen}
+ ondblclick={() => {
+ if (showFront) onZoom();
+ }}
+ onkeydown={onKeydown}
+>
+ {#if showFront && card != null}
+ <MonsterAbilityCard
+ {card}
+ {stat}
+ {fh}
+ flying={model?.flying ?? false}
+ scale={ROW_CARD_SCALE}
+ applyStats={false}
+ />
+ {:else}
+ <AbilityCardBack
+ {fh}
+ size={deck ? deck.drawPile.length : -1}
+ scale={ROW_CARD_SCALE}
+ />
+ {/if}
+</div>
+
+<style>
+ .slot {
+ flex-shrink: 0;
+ margin-left: 4px;
+ cursor: pointer;
+ }
+</style>
diff --git a/web/src/lib/ui/decks/AbilityCardZoom.svelte b/web/src/lib/ui/decks/AbilityCardZoom.svelte
new file mode 100644
index 0000000..dc5e258
--- /dev/null
+++ b/web/src/lib/ui/decks/AbilityCardZoom.svelte
@@ -0,0 +1,71 @@
+<!--
+ The ability-card zoom (the reference `AbilityCardZoom`): the current
+ card at ~2.5x scale, tap (or Escape) to close.
+-->
+<script lang="ts">
+ import type { MonsterAbilityCard as AbilityCard } from '$lib/protocol/types';
+ import type { StatMonster } from '$lib/game/line/statApplier';
+ import MonsterAbilityCard from '../cards/MonsterAbilityCard.svelte';
+
+ const DEFAULT_ZOOM = 2.5;
+
+ let {
+ card,
+ stat,
+ fh,
+ flying = false,
+ open = $bindable(true)
+ }: {
+ card: AbilityCard;
+ stat: StatMonster | null;
+ fh: boolean;
+ flying?: boolean;
+ open?: boolean;
+ } = $props();
+
+ // Fit the card into the viewport (the reference shrinks the zoom to fit).
+ function scaleFor(): number {
+ if (typeof window === 'undefined') return DEFAULT_ZOOM;
+ const w = window.innerWidth;
+ const h = window.innerHeight;
+ let zoom = Math.min(
+ DEFAULT_ZOOM,
+ (w - 80) / 142.4,
+ (h - 120) / 94.4
+ );
+ return Math.max(zoom, 0.5);
+ }
+ const scale = $state(scaleFor());
+</script>
+
+{#if open}
+ <div
+ class="zoom"
+ role="dialog"
+ aria-modal="true"
+ onclick={() => (open = false)}
+ onkeydown={(e) => e.key === 'Escape' && (open = false)}
+ >
+ <MonsterAbilityCard
+ {card}
+ {stat}
+ {fh}
+ {flying}
+ scale={scale}
+ applyStats={false}
+ />
+ </div>
+{/if}
+
+<style>
+ .zoom {
+ position: fixed;
+ inset: 0;
+ z-index: 40;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ background: rgba(0, 0, 0, 0.75);
+ cursor: pointer;
+ }
+</style>
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>
diff --git a/web/src/lib/ui/decks/DeckArea.svelte b/web/src/lib/ui/decks/DeckArea.svelte
new file mode 100644
index 0000000..6e32dea
--- /dev/null
+++ b/web/src/lib/ui/decks/DeckArea.svelte
@@ -0,0 +1,222 @@
+<!--
+ The bottom deck area (the reference `main_scaffold` bottom row): the loot
+ deck on the left, and on the right the character AMD decks (behind the
+ "Character Decks" toggle, the reference `CharacterAmdsWidget` open-state
+ cycling), the ally deck (when `shouldShowAlliesDeck`), and the global
+ deck. Tapping a deck opens its menu; double-tapping zooms its top
+ discard card.
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import type {
+ CharacterItem,
+ ModifierCard as Card
+ } from '$lib/protocol/types';
+ import { isCharacter } from '$lib/protocol/types';
+ import type { CampaignData, ClassData } from '$lib/data/gameData';
+ import { t } from '$lib/i18n';
+ import {
+ currentCharacterId,
+ modifierDeckByName,
+ shouldShowAlliesDeck
+ } from '$lib/game/rules';
+ import LootDeckWidget from './LootDeckWidget.svelte';
+ import ModifierDeckWidget from './ModifierDeckWidget.svelte';
+
+ type OpenState = 'noOpen' | 'oneOpen' | 'allOpen';
+
+ let {
+ session,
+ campaignData,
+ onOpenAmd,
+ onAmdZoom,
+ onOpenLoot
+ }: {
+ session: GameSession;
+ campaignData: CampaignData | null;
+ onOpenAmd: (name: string) => void;
+ onAmdZoom: (card: Card, name: string, perks: string[][] | null) => void;
+ onOpenLoot: () => void;
+ } = $props();
+
+ const gameState = session.state;
+
+ // The class data for a character item (null until the campaign loads).
+ function classFor(char: CharacterItem): ClassData | null {
+ return (
+ campaignData?.classes.find(
+ (c) => c.name === char.characterClass || c.id === char.characterClass
+ ) ?? null
+ );
+ }
+
+ // Characters whose class has perks (the reference `charsWithPerks`).
+ const charsWithPerks = $derived.by((): CharacterItem[] => {
+ const gs = $gameState;
+ if (!gs || campaignData == null) return [];
+ return gs.currentList
+ .filter((i): i is CharacterItem => isCharacter(i))
+ .filter((c) => (classFor(c)?.perkDetails.length ?? 0) > 0);
+ });
+
+ const currentCharacter = $derived.by((): CharacterItem | null => {
+ const gs = $gameState;
+ if (!gs) return null;
+ const id = currentCharacterId(gs);
+ if (id == null) return null;
+ return (
+ gs.currentList.find((i): i is CharacterItem => isCharacter(i) && i.id === id) ??
+ null
+ );
+ });
+
+ const canShowOneDeck = $derived(
+ ($gameState?.roundState ?? 0) === 1 &&
+ currentCharacter != null &&
+ charsWithPerks.some((c) => c.id === currentCharacter.id)
+ );
+
+ // The reference keeps the user intent per round state; the toggle cycles
+ // between them (chooseInitiative: noOpen <-> allOpen; playTurns:
+ // oneOpen <-> allOpen when the current character can show one deck).
+ let playTurnsIntent = $state<OpenState>('oneOpen');
+ let chooseInitIntent = $state<OpenState>('allOpen');
+
+ const visible = $derived.by((): OpenState => {
+ const roundState = $gameState?.roundState ?? 0;
+ if (roundState !== 1) return chooseInitIntent;
+ if (playTurnsIntent === 'oneOpen' && canShowOneDeck) return 'oneOpen';
+ return playTurnsIntent;
+ });
+
+ function toggle() {
+ const roundState = $gameState?.roundState ?? 0;
+ if (roundState !== 1) {
+ chooseInitIntent = chooseInitIntent === 'noOpen' ? 'allOpen' : 'noOpen';
+ return;
+ }
+ if (canShowOneDeck) {
+ playTurnsIntent =
+ playTurnsIntent === 'oneOpen'
+ ? 'allOpen'
+ : playTurnsIntent === 'allOpen'
+ ? 'oneOpen'
+ : 'oneOpen';
+ } else {
+ playTurnsIntent =
+ playTurnsIntent === 'noOpen'
+ ? 'allOpen'
+ : playTurnsIntent === 'allOpen'
+ ? 'oneOpen'
+ : 'allOpen';
+ }
+ }
+
+ function perksFor(char: CharacterItem): string[][] | null {
+ return classFor(char)?.perkDetails.map((p) => p.adds) ?? null;
+ }
+
+ function onZoom(name: string, char: CharacterItem | null) {
+ const gs = $gameState;
+ if (!gs) return;
+ const deck = modifierDeckByName(gs, name);
+ if (!deck || deck.discardPile.length === 0) return;
+ const card = deck.discardPile[deck.discardPile.length - 1];
+ onAmdZoom(card, name, char ? perksFor(char) : null);
+ }
+
+ const showAmds = $derived(campaignData != null && charsWithPerks.length > 0);
+</script>
+
+<div class="deckarea">
+ <div class="deckarea__loot">
+ {#if $gameState}
+ <LootDeckWidget {session} deck={$gameState.lootDeck} onOpenMenu={onOpenLoot} />
+ {/if}
+ </div>
+
+ <div class="deckarea__decks">
+ {#if showAmds}
+ <button class="toggle" onclick={toggle}>{t('characterDecks')}</button>
+ {#if visible !== 'noOpen'}
+ {#if visible === 'oneOpen' && canShowOneDeck && currentCharacter}
+ <ModifierDeckWidget
+ {session}
+ deck={currentCharacter.characterState.modifierDeck}
+ name={currentCharacter.id}
+ className={currentCharacter.characterClass}
+ perks={perksFor(currentCharacter)}
+ onOpenMenu={() => onOpenAmd(currentCharacter.id)}
+ onZoom={() => onZoom(currentCharacter.id, currentCharacter)}
+ />
+ {:else}
+ {#each charsWithPerks as char (char.id)}
+ <ModifierDeckWidget
+ {session}
+ deck={char.characterState.modifierDeck}
+ name={char.id}
+ className={char.characterClass}
+ perks={perksFor(char)}
+ onOpenMenu={() => onOpenAmd(char.id)}
+ onZoom={() => onZoom(char.id, char)}
+ />
+ {/each}
+ {/if}
+ {/if}
+ {/if}
+
+ {#if $gameState && shouldShowAlliesDeck($gameState)}
+ <ModifierDeckWidget
+ {session}
+ deck={$gameState.modifierDeckAllies}
+ name="allies"
+ className={null}
+ onOpenMenu={() => onOpenAmd('allies')}
+ onZoom={() => onZoom('allies', null)}
+ />
+ {/if}
+
+ {#if $gameState}
+ <ModifierDeckWidget
+ {session}
+ deck={$gameState.modifierDeck}
+ name=""
+ className={null}
+ onOpenMenu={() => onOpenAmd('')}
+ onZoom={() => onZoom('', null)}
+ />
+ {/if}
+ </div>
+</div>
+
+<style>
+ .deckarea {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ gap: 24px;
+ padding: 4px 8px;
+ }
+ .deckarea__loot {
+ display: flex;
+ align-items: center;
+ }
+ .deckarea__decks {
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+ align-items: flex-end;
+ }
+ .toggle {
+ padding: 2px 10px;
+ font-size: 12px;
+ border: none;
+ border-radius: 4px;
+ background: rgba(255, 255, 255, 0.15);
+ color: inherit;
+ cursor: pointer;
+ }
+ .toggle:hover {
+ background: rgba(255, 255, 255, 0.3);
+ }
+</style>
diff --git a/web/src/lib/ui/decks/LootCardsMenu.svelte b/web/src/lib/ui/decks/LootCardsMenu.svelte
new file mode 100644
index 0000000..638fd0c
--- /dev/null
+++ b/web/src/lib/ui/decks/LootCardsMenu.svelte
@@ -0,0 +1,492 @@
+<!--
+ The loot-cards menu (the reference `LootCardsMenu`): the button bar —
+ Character loot, add/remove special cards 1418/1419, Enhance cards,
+ Add Card, Return to Top/Bottom — above the discard grid (tap a card →
+ Set Loot Owner). The other buttons open nested submenus (the
+ reference's CharacterLootMenu / AddLootCardMenu /
+ LootCardEnhancementMenu dialogs).
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import type { LootCard as Card, LootPoolKey } from '$lib/protocol/types';
+ import { isCharacter } from '$lib/protocol/types';
+ import { t } from '$lib/i18n';
+ import {
+ characterLootTotal,
+ poolCardGfx
+ } from '$lib/game/cards/lootCard';
+ import LootCard from '../cards/LootCard.svelte';
+ import LootEnhancementCounter from './LootEnhancementCounter.svelte';
+ import Menu from '../Menu.svelte';
+
+ const CARD_1418 = 1418;
+ const CARD_1419 = 1419;
+ const GRID_COLUMNS = 4;
+
+ // Enhancement sections, in the reference order: materials (8 cards:
+ // 2× "1", 3× "2 for 2", 3× "2 for 2-3"), herbs (2 cards), coin
+ // (12× "1", 6× "2", 2× "3" in rows of 3).
+ const MATERIAL_KEYS: LootPoolKey[] = ['hide', 'lumber', 'metal'];
+ // Per material: 2× value-1, 3× "2 for 2", 3× "2 for 2-3".
+ const MATERIAL_SPLIT = [2, 3, 3];
+ const HERB_KEYS: LootPoolKey[] = [
+ 'arrowvine',
+ 'axenut',
+ 'corpsecap',
+ 'flamefruit',
+ 'rockroot',
+ 'snowthistle'
+ ];
+ // Coin pool: 12× "1", 6× "2", 2× "3", shown in rows of 3.
+ const COIN_SPLIT = [12, 6, 2];
+ const COIN_ROW_SIZE = 3;
+
+ // AddLootCardMenu names (in `addedCards` order).
+ const ADD_LOOT_NAMES = [
+ 'hide',
+ 'lumber',
+ 'metal',
+ 'arrowvine',
+ 'axenut',
+ 'corpsecap',
+ 'flamefruit',
+ 'rockroot',
+ 'snowthistle'
+ ];
+
+ // CharacterLootMenu rows (coin first).
+ const LOOT_ROWS = [
+ 'coin',
+ 'hide',
+ 'lumber',
+ 'metal',
+ 'arrowvine',
+ 'axenut',
+ 'corpsecap',
+ 'flamefruit',
+ 'rockroot',
+ 'snowthistle'
+ ];
+
+ let {
+ session,
+ deck,
+ open = $bindable(true)
+ }: {
+ session: GameSession;
+ deck: import('$lib/protocol/types').LootDeck;
+ open?: boolean;
+ } = $props();
+
+ const gameState = session.state;
+ const player = session.player;
+
+ // The discard pile displays most-recently-drawn first (the reference
+ // reverses the pile list).
+ const discardDisplay = $derived([...deck.discardPile].reverse());
+
+ const characters = $derived(
+ ($gameState?.currentList ?? []).filter(isCharacter)
+ );
+
+ function cmd(command: string, args: Record<string, unknown> = {}) {
+ if ($player) session.command(command, args);
+ }
+
+ function lootName(label: string): string {
+ return t(`lootName${label.charAt(0).toUpperCase()}${label.slice(1)}`);
+ }
+
+ /** A character's display name by id ("" until found). */
+ function characterDisplay(charId: string): string {
+ for (const c of $gameState?.currentList ?? []) {
+ if (isCharacter(c) && c.id === charId) return c.characterState.display;
+ }
+ return '';
+ }
+
+ // --- submenus (nested overlays, the reference's dialog stack) ------------
+
+ type Sub =
+ | { kind: 'owner'; card: Card }
+ | { kind: 'charLoot' }
+ | { kind: 'addLoot' }
+ | { kind: 'enhance' };
+
+ let sub = $state<Sub | null>(null);
+
+ // One enhancement counter per pool card.
+ function counter(key: LootPoolKey, index: number) {
+ const pool = deck.pools[key] ?? [];
+ const id = pool[index] ?? -1;
+ return {
+ id,
+ gfx: poolCardGfx(key, index),
+ value: id >= 0 ? deck.enhancements[String(id)] ?? 0 : 0
+ };
+ }
+
+ // The enhancement sections, in the reference order (the
+ // `LootCardEnhancementMenu` column): materials, herbs, coin.
+ type EnhSection = { key: LootPoolKey; label: string; rows: number[][] };
+ const enhSections = $derived.by<EnhSection[]>(() => {
+ const sections: EnhSection[] = [];
+ MATERIAL_KEYS.forEach((key) => {
+ let start = 0;
+ [
+ '1',
+ t('lootAmount2For2'),
+ t('lootAmount2For23')
+ ].forEach((label, i) => {
+ const count = MATERIAL_SPLIT[i];
+ sections.push({
+ key,
+ label: `${lootName(key)} ${label}`,
+ rows: rowsFor(start, count, count)
+ });
+ start += count;
+ });
+ });
+ HERB_KEYS.forEach((key) => {
+ sections.push({
+ key,
+ label: lootName(key),
+ rows: rowsFor(0, 2, 2)
+ });
+ });
+ let coinStart = 0;
+ ['1', '2', '3'].forEach((label, i) => {
+ const count = COIN_SPLIT[i];
+ sections.push({
+ key: 'coin',
+ label: `${lootName('coin')} ${label}`,
+ rows: rowsFor(coinStart, count, COIN_ROW_SIZE)
+ });
+ coinStart += count;
+ });
+ return sections;
+ });
+
+ // `count` cards, `rowSize` per row, starting at pool [start].
+ function rowsFor(start: number, count: number, rowSize: number): number[][] {
+ const rows: number[][] = [];
+ for (let s = start; s < start + count; s += rowSize) {
+ rows.push(Array.from({ length: Math.min(rowSize, start + count - s) }, (_, j) => s + j));
+ }
+ return rows;
+ }
+
+ // Character loot totals per row (the reference `_getLootAmount`).
+ function charLootRows(charId: string) {
+ const characterCount = characters.length;
+ return LOOT_ROWS.map((name) => ({
+ name,
+ amount: characterLootTotal(
+ deck.discardPile,
+ charId,
+ name,
+ characterCount
+ )
+ }));
+ }
+</script>
+
+<Menu {open} title="Loot Cards">
+ {#if $gameState}
+ <div class="bar">
+ <button class="pill pill--text" onclick={() => (sub = { kind: 'charLoot' })}>
+ {t('characterLoot')}
+ </button>
+ <button
+ class="pill pill--text"
+ disabled={!player}
+ onclick={() =>
+ cmd(deck['1418'] ? 'removeSpecialLootCard' : 'addSpecialLootCard', {
+ nr: CARD_1418
+ })}
+ >
+ {deck['1418']
+ ? t('removeSpecialCard', { nr: CARD_1418 })
+ : t('addSpecialCard', { nr: CARD_1418 })}
+ </button>
+ <button
+ class="pill pill--text"
+ disabled={!player}
+ onclick={() =>
+ cmd(deck['1419'] ? 'removeSpecialLootCard' : 'addSpecialLootCard', {
+ nr: CARD_1419
+ })}
+ >
+ {deck['1419']
+ ? t('removeSpecialCard', { nr: CARD_1419 })
+ : t('addSpecialCard', { nr: CARD_1419 })}
+ </button>
+ <button class="pill pill--text" onclick={() => (sub = { kind: 'enhance' })}>
+ {t('enhanceCards')}
+ </button>
+ <button class="pill pill--text" onclick={() => (sub = { kind: 'addLoot' })}>
+ {t('addLootCard')}
+ </button>
+ {#if deck.discardPile.length > 0}
+ <button class="pill pill--text" disabled={!player} onclick={() => cmd('returnLootCard', { top: true })}>
+ {t('returnToTop')}
+ </button>
+ <button class="pill pill--text" disabled={!player} onclick={() => cmd('returnLootCard', { top: false })}>
+ {t('returnToBottom')}
+ </button>
+ {/if}
+ </div>
+
+ <div class="grid" style="grid-template-columns: repeat({GRID_COLUMNS}, 1fr)">
+ {#each discardDisplay as card}
+ <button
+ class="grid__cell"
+ onclick={() => (sub = { kind: 'owner', card })}
+ role="button"
+ tabindex="0"
+ aria-label="loot card {card.id}"
+ >
+ <LootCard
+ {card}
+ revealed
+ ownerName={characterDisplay(card.owner)}
+ characterCount={characters.length}
+ scale={0.6}
+ />
+ </button>
+ {/each}
+ </div>
+ {/if}
+
+ <!-- set loot owner -->
+ {#if sub && sub.kind === 'owner'}
+ {@const s = sub}
+ <div class="sub" role="dialog" aria-modal="true">
+ <div class="sub__title">{t('setLootOwner')}</div>
+ {#each characters as char}
+ <button
+ class="ownerrow"
+ disabled={!player}
+ onclick={() => {
+ cmd('setLootOwner', { ownerId: char.id, cardId: s.card.id });
+ sub = null;
+ }}
+ >
+ <img src="/images/class-icons/{char.id}.png" alt={char.id} />
+ <span>{char.characterState.display}</span>
+ </button>
+ {/each}
+ </div>
+ {/if}
+
+ <!-- character loot totals -->
+ {#if sub?.kind === 'charLoot'}
+ <div class="sub sub--scroll">
+ {#each characters as char}
+ <div class="divider"></div>
+ <div class="charrow">
+ <img src="/images/class-icons/{char.id}.png" alt={char.id} />
+ <span>{t('characterLootTitle', { name: char.characterState.display })}</span>
+ </div>
+ {#each charLootRows(char.id) as row}
+ {#if row.amount > 0}
+ <div class="lootrow">
+ <img src="/images/loot/{row.name}_icon.png" alt={row.name} />
+ <span>{lootName(row.name)}</span>
+ <span class="lootrow__amount">{row.amount}</span>
+ </div>
+ {/if}
+ {/each}
+ {/each}
+ </div>
+ {/if}
+
+ <!-- add an extra loot card -->
+ {#if sub?.kind === 'addLoot'}
+ <div class="sub sub--scroll">
+ <div class="sub__title">{t('addExtraLootCard')}</div>
+ {#each ADD_LOOT_NAMES as name, i}
+ <button
+ class="lootrow"
+ disabled={!player}
+ onclick={() => cmd('addLootCard', { resourceType: name })}
+ >
+ <img src="/images/loot/{name}_icon.png" alt={name} />
+ <span>{lootName(name)}</span>
+ <span class="lootrow__amount">
+ {t('addedCount', { count: deck.addedCards[i] ?? 0 })}
+ </span>
+ </button>
+ {/each}
+ </div>
+ {/if}
+
+ <!-- enhancements -->
+ {#if sub?.kind === 'enhance'}
+ <div class="sub sub--scroll">
+ <div class="sub__title">{t('lootCardEnhancements')}</div>
+ {#each enhSections as section}
+ <div class="secheader">
+ <img src="/images/loot/{section.key}_icon.png" alt={section.key} />
+ <span>{section.label}</span>
+ </div>
+ {#each section.rows as row}
+ <div class="coinrow">
+ {#each row as idx}
+ {@const c = counter(section.key, idx)}
+ <LootEnhancementCounter {session} {...c} />
+ {/each}
+ </div>
+ {/each}
+ <div class="divider"></div>
+ {/each}
+ </div>
+ {/if}
+</Menu>
+
+<style>
+ .bar {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: 4px;
+ margin-bottom: 10px;
+ }
+ .pill {
+ 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:disabled {
+ opacity: 0.35;
+ cursor: default;
+ }
+ .pill--text {
+ min-width: 0;
+ }
+ .grid {
+ display: grid;
+ gap: 2px;
+ max-height: 55vh;
+ overflow-y: auto;
+ }
+ .grid__cell {
+ padding: 0;
+ background: none;
+ border: none;
+ cursor: pointer;
+ aspect-ratio: 0.72;
+ }
+ .grid__cell:focus-visible {
+ outline: 2px solid #7ec8ff;
+ }
+ .sub {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+ margin-top: 10px;
+ padding: 10px;
+ border-radius: 8px;
+ background: rgba(0, 0, 0, 0.35);
+ }
+ .sub--scroll {
+ max-height: 60vh;
+ overflow-y: auto;
+ }
+ .sub__title {
+ font-size: 14px;
+ font-weight: 600;
+ }
+ .ownerrow {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ padding: 6px 8px;
+ font-size: 14px;
+ border: none;
+ border-radius: 4px;
+ background: rgba(255, 255, 255, 0.12);
+ color: inherit;
+ cursor: pointer;
+ }
+ .ownerrow:hover:not(:disabled) {
+ background: rgba(255, 255, 255, 0.25);
+ }
+ .ownerrow:disabled {
+ opacity: 0.35;
+ cursor: default;
+ }
+ .ownerrow img {
+ width: 24px;
+ height: 24px;
+ object-fit: contain;
+ }
+ .charrow {
+ display: flex;
+ align-items: flex-end;
+ justify-content: center;
+ gap: 10px;
+ font-size: 14px;
+ font-weight: 600;
+ }
+ .charrow img {
+ width: 24px;
+ height: 24px;
+ object-fit: contain;
+ }
+ .lootrow {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ padding: 4px 8px;
+ font-size: 13px;
+ border: none;
+ border-radius: 4px;
+ background: rgba(255, 255, 255, 0.08);
+ color: inherit;
+ }
+ .lootrow:not(:disabled) {
+ cursor: pointer;
+ }
+ .lootrow:hover:not(:disabled) {
+ background: rgba(255, 255, 255, 0.2);
+ }
+ .lootrow img {
+ width: 24px;
+ height: 24px;
+ object-fit: contain;
+ }
+ .lootrow__amount {
+ margin-left: auto;
+ font-weight: 700;
+ }
+ .divider {
+ height: 1px;
+ background: rgba(255, 255, 255, 0.2);
+ }
+ .secheader {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ font-size: 13px;
+ font-weight: 600;
+ }
+ .secheader img {
+ width: 24px;
+ height: 24px;
+ object-fit: contain;
+ }
+ .coinrow {
+ display: flex;
+ justify-content: space-evenly;
+ gap: 4px;
+ }
+</style>
diff --git a/web/src/lib/ui/decks/LootDeckWidget.svelte b/web/src/lib/ui/decks/LootDeckWidget.svelte
new file mode 100644
index 0000000..369a6c2
--- /dev/null
+++ b/web/src/lib/ui/decks/LootDeckWidget.svelte
@@ -0,0 +1,163 @@
+<!--
+ The loot deck (the reference `LootDeckWidget`): the draw pile (tap to
+ draw, current-character class icon above it) beside the discard box
+ (tap to open the loot cards menu). Hidden while both piles are empty
+ (the reference `shouldHide`).
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import type { LootDeck as Deck } from '$lib/protocol/types';
+ import { currentCharacterId } from '$lib/game/rules';
+ import LootCard from '../cards/LootCard.svelte';
+
+ const CARD_W = 40;
+ const CARD_ROT = 15;
+
+ let {
+ session,
+ deck,
+ onOpenMenu
+ }: {
+ session: GameSession;
+ deck: Deck;
+ onOpenMenu: () => void;
+ } = $props();
+
+ const gameState = session.state;
+ const player = session.player;
+
+ // Hidden while the deck is empty (the reference `shouldHide`).
+ const hidden = $derived(deck.drawPile.length === 0 && deck.discardPile.length === 0);
+
+ const currentCharacterName = $derived(
+ $gameState ? currentCharacterId($gameState) : null
+ );
+
+ // The top three discard cards, bottom-most first (for the stack offsets).
+ const discardStack = $derived(
+ deck.discardPile.slice(-3).map((card, i, arr) => ({
+ card,
+ depth: arr.length - 1 - i
+ }))
+ );
+
+ function draw() {
+ if ($player && deck.drawPile.length > 0) {
+ session.command('drawLootCard', {});
+ }
+ }
+</script>
+
+{#if !hidden}
+ <div class="deck">
+ <div
+ class="drawpile"
+ role="button"
+ tabindex="0"
+ aria-label="draw pile"
+ onclick={draw}
+ onkeydown={(e) => {
+ if (e.key === 'Enter' || e.key === ' ') draw();
+ }}
+ >
+ {#if deck.drawPile.length > 0}
+ <LootCard card={deck.drawPile[deck.drawPile.length - 1]} revealed={false} />
+ {:else}
+ <div class="empty"></div>
+ {/if}
+ <span class="count">{deck.drawPile.length}</span>
+ {#if currentCharacterName != null && deck.drawPile.length > 0}
+ <img
+ class="icon"
+ src="/images/class-icons/{currentCharacterName}.png"
+ alt={currentCharacterName}
+ />
+ {/if}
+ </div>
+
+ <div
+ class="discard"
+ role="button"
+ tabindex="0"
+ aria-label="discard pile"
+ onclick={onOpenMenu}
+ onkeydown={(e) => {
+ if (e.key === 'Enter' || e.key === ' ') onOpenMenu();
+ }}
+ >
+ {#each discardStack as entry}
+ <div
+ class="discard__card"
+ style="left: {4 + entry.depth * 13}px; transform: rotate({entry.depth === 0 ? 0 : CARD_ROT}deg)"
+ >
+ <LootCard card={entry.card} revealed />
+ </div>
+ {/each}
+ </div>
+ </div>
+{/if}
+
+<style>
+ .deck {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ width: 94px;
+ height: 39px;
+ }
+ .drawpile {
+ position: relative;
+ width: 40px;
+ height: 39px;
+ cursor: pointer;
+ }
+ .drawpile:focus-visible {
+ outline: 2px solid #7ec8ff;
+ border-radius: 4px;
+ }
+ .empty {
+ width: 40px;
+ height: 39px;
+ border-radius: 4px;
+ background: rgba(0, 0, 0, 0.48);
+ }
+ .count {
+ position: absolute;
+ right: 3px;
+ bottom: 0;
+ font-size: 13px;
+ font-weight: 700;
+ color: #fff;
+ text-shadow: 1px 1px 1px #000;
+ pointer-events: none;
+ }
+ .icon {
+ position: absolute;
+ top: 12px;
+ left: 4px;
+ width: 35px;
+ height: 35px;
+ object-fit: contain;
+ filter: brightness(0) invert(1) drop-shadow(2px 2px 1.5px rgba(0, 0, 0, 0.54));
+ pointer-events: none;
+ }
+ .discard {
+ position: relative;
+ width: 39px;
+ height: 57.6666px;
+ border-radius: 5px;
+ border: 1px solid rgba(255, 255, 255, 0.7);
+ background: rgba(0, 0, 0, 0.48);
+ cursor: pointer;
+ overflow: visible;
+ }
+ .discard:focus-visible {
+ outline: 2px solid #7ec8ff;
+ }
+ .discard__card {
+ position: absolute;
+ top: 0;
+ left: 4px;
+ transition: left 0.2s ease, transform 0.2s ease;
+ }
+</style>
diff --git a/web/src/lib/ui/decks/LootEnhancementCounter.svelte b/web/src/lib/ui/decks/LootEnhancementCounter.svelte
new file mode 100644
index 0000000..7139222
--- /dev/null
+++ b/web/src/lib/ui/decks/LootEnhancementCounter.svelte
@@ -0,0 +1,77 @@
+<!--
+ One loot-card enhancement counter (the reference
+ `EnhancementCounterButton`): [−] <value> [+], the minus only enabled
+ while the card is enhanced. `value` is the card's `enhanced` amount.
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+
+ let {
+ session,
+ id,
+ gfx,
+ value
+ }: {
+ session: GameSession;
+ id: number;
+ /** The card's `gfx` (the wire `resourceType`). */
+ gfx: string;
+ value: number;
+ } = $props();
+
+ const player = session.player;
+
+ function cmd(delta: number) {
+ if ($player) {
+ session.command('enhanceLootCard', {
+ id,
+ value: value + delta,
+ resourceType: gfx
+ });
+ }
+ }
+</script>
+
+<div class="counters">
+ <button class="cbtn" disabled={!player || value <= 0} onclick={() => cmd(-1)}>−</button>
+ <span class="cval">{value}</span>
+ <button class="cbtn" disabled={!player} onclick={() => cmd(1)}>+</button>
+</div>
+
+<style>
+ .counters {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: 6px;
+ padding: 3px;
+ }
+ .cbtn {
+ width: 24px;
+ height: 24px;
+ font-size: 16px;
+ line-height: 1;
+ border: none;
+ border-radius: 4px;
+ background: rgba(255, 255, 255, 0.15);
+ color: inherit;
+ cursor: pointer;
+ }
+ .cbtn:hover:not(:disabled) {
+ background: rgba(255, 255, 255, 0.3);
+ }
+ .cbtn:disabled {
+ opacity: 0.35;
+ cursor: default;
+ }
+ .cval {
+ min-width: 24px;
+ padding: 2px 6px;
+ text-align: center;
+ font-size: 13px;
+ font-weight: 700;
+ border-radius: 2px;
+ background: #fff;
+ color: #000;
+ }
+</style>
diff --git a/web/src/lib/ui/decks/ModifierCardZoom.svelte b/web/src/lib/ui/decks/ModifierCardZoom.svelte
new file mode 100644
index 0000000..68cb150
--- /dev/null
+++ b/web/src/lib/ui/decks/ModifierCardZoom.svelte
@@ -0,0 +1,56 @@
+<!--
+ The modifier-card zoom (the reference `ModifierCardZoom`): the top card
+ at ~3x scale (shrunk to fit the screen width), tap (or Escape) to close.
+-->
+<script lang="ts">
+ import type { ModifierCard as Card } from '$lib/protocol/types';
+ import ModifierCard from '../cards/ModifierCard.svelte';
+
+ const DEFAULT_ZOOM = 3.0;
+ const CARD_WIDTH = 58.6666;
+
+ let {
+ card,
+ name,
+ perks = null,
+ open = $bindable(true)
+ }: {
+ card: Card;
+ /** The deck name ("" party, "allies", or a character id). */
+ name: string;
+ perks?: string[][] | null;
+ open?: boolean;
+ } = $props();
+
+ // Fit the card into the viewport (the reference shrinks the zoom to fit).
+ function scaleFor(): number {
+ if (typeof window === 'undefined') return DEFAULT_ZOOM;
+ return Math.min(DEFAULT_ZOOM, window.innerWidth / (CARD_WIDTH + 80));
+ }
+ const scale = $state(scaleFor());
+</script>
+
+{#if open}
+ <div
+ class="zoom"
+ role="dialog"
+ aria-modal="true"
+ onclick={() => (open = false)}
+ onkeydown={(e) => e.key === 'Escape' && (open = false)}
+ >
+ <ModifierCard {card} {name} revealed {perks} {scale} />
+ </div>
+{/if}
+
+<style>
+ .zoom {
+ position: fixed;
+ inset: 0;
+ z-index: 40;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ background: rgba(0, 0, 0, 0.75);
+ cursor: pointer;
+ }
+</style>
diff --git a/web/src/lib/ui/decks/ModifierDeckHeader.svelte b/web/src/lib/ui/decks/ModifierDeckHeader.svelte
new file mode 100644
index 0000000..0f7ae9d
--- /dev/null
+++ b/web/src/lib/ui/decks/ModifierDeckHeader.svelte
@@ -0,0 +1,460 @@
+<!--
+ The modifier-deck menu header (the reference `ModifierDeckHeader`): the
+ wrap of deck commands — Bad Omen, Corrosive Spew, ±1/-2/+0 removal,
+ Imbue/Advanced Imbue, Hail/Cassandra perk toggles, Cassandra save,
+ removed-card count, Crimson Scales sanctuary/party card, faction
+ menus, the bless/curse/empower/enfeeble counters, and the reveal
+ buttons (0..n / All).
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import type { GameState, ModifierDeck as Deck } from '$lib/protocol/types';
+ import type { ClassData } from '$lib/data/gameData';
+ import { t } from '$lib/i18n';
+ import {
+ deckHasMinus1,
+ deckHasPlus0,
+ deckMinus2Present,
+ drawPileTopFirst,
+ removableTotal
+ } from '$lib/game/modifierDeck';
+ import { hasCharacterClass, isCSCampaign } from '$lib/game/rules';
+ import CounterButton from '../CounterButton.svelte';
+
+ const MAX_BLESS_CURSE = 10;
+ const MAX_RUINMAW_EMPOWER = 12;
+ const MAX_VIMTHREADER_GR_EMPOWER = 5;
+ const MAX_LIFESPEAKER_ENFEEBLE = 15;
+ const MAX_REVEAL_BUTTONS = 6;
+ const MAX_REVEAL_BUTTONS_CASSANDRA = 8;
+ const HAIL_PERK_INDEX = 17;
+ const CASSANDRA_PERK_INDEX = 15;
+ const PARTY_BUTTON_COUNT = 4;
+
+ let {
+ session,
+ state,
+ deck,
+ name,
+ characterClassData = null,
+ onOpenRemoved,
+ onOpenPerks,
+ onOpenFaction
+ }: {
+ session: GameSession;
+ state: GameState;
+ deck: Deck;
+ /** "" party deck, "allies", or a character id. */
+ name: string;
+ /** The owning character's class data (character decks only). */
+ characterClassData?: ClassData | null;
+ onOpenRemoved: () => void;
+ onOpenPerks: () => void;
+ onOpenFaction: (faction: string) => void;
+ } = $props();
+
+ const player = session.player;
+
+ const isCharacter = $derived(name !== '' && name !== 'allies');
+ const monsterDeck = $derived(name === '');
+
+ const hasDiviner = $derived(hasCharacterClass(state, 'Diviner'));
+ const hasIncarnate = $derived(hasCharacterClass(state, 'Incarnate'));
+ const hasVimthreader = $derived(hasCharacterClass(state, 'Vimthreader'));
+ const hasLifespeaker = $derived(hasCharacterClass(state, 'Lifespeaker'));
+ const hasCassandra = $derived(hasCharacterClass(state, 'Cassandra'));
+
+ const hail = $derived(
+ state.currentList.find(
+ (i) => 'characterClass' in i && i.characterClass === 'Hail'
+ )
+ );
+ const hasHailPerk = $derived(
+ hail != null && 'characterState' in hail
+ ? (hail.characterState.perkList[HAIL_PERK_INDEX] ?? false)
+ : false
+ );
+ const cassandra = $derived(
+ state.currentList.find(
+ (i) => 'characterClass' in i && i.characterClass === 'Cassandra'
+ )
+ );
+ const hasCassandraPerk = $derived(
+ cassandra != null && 'characterState' in cassandra
+ ? (cassandra.characterState.perkList[CASSANDRA_PERK_INDEX] ?? false)
+ : false
+ );
+
+ const nrOfEnfeebles = $derived(
+ (hasVimthreader ? 1 : 0) + (hasLifespeaker ? 1 : 0) + (hasIncarnate ? 1 : 0)
+ );
+ const nrOfEmpowers = $derived(
+ (hasVimthreader ? 1 : 0) + (hasIncarnate ? 1 : 0)
+ );
+ const moreThanOneEnfeeble = $derived(monsterDeck && nrOfEnfeebles > 1);
+ const moreThanOneEmpower = $derived(
+ ((isCharacter || name === 'allies') && nrOfEmpowers > 1) ||
+ (isCharacter && name === 'Ruinmaw' && nrOfEmpowers > 0)
+ );
+
+ const drawPile = $derived(drawPileTopFirst(deck));
+ // 8 reveal buttons when the party has a Cassandra (the reference
+ // `vm.hasCassandra` — her revealed-card special needs the extra).
+ const maxRevealButtons = $derived(
+ hasCassandra
+ ? MAX_REVEAL_BUTTONS_CASSANDRA
+ : MAX_REVEAL_BUTTONS
+ );
+ // Reveal button count: 0..min(drawPile, max) + the All button.
+ const revealCount = $derived(
+ Math.min(drawPile.length + 1, maxRevealButtons + 1)
+ );
+
+ const hasPlus0Card = $derived(deckHasPlus0(deck));
+
+ const factionUnlocked = $derived(
+ (['Demons', 'Merchant-Guild', 'Military'] as const).filter(
+ (f) => state.unlockedClasses.includes(f)
+ )
+ );
+
+ function cmd(name: string, args: Record<string, unknown> = {}) {
+ if (player) session.command(name, args);
+ }
+
+ /** The deck counter's ownerId (party deck → "" resolves to the party). */
+ const ownerId = $derived(name === '' ? '' : name);
+
+ function changeBless(delta: number) {
+ cmd('changeBless', { change: delta, figureId: '', ownerId });
+ }
+ function changeCurse(delta: number) {
+ cmd('changeCurse', { change: delta, figureId: '', ownerId });
+ }
+ function changeEmpower(gfx: string, delta: number) {
+ cmd('changeEmpower', { change: delta, gfx, figureId: '', ownerId });
+ }
+ function changeEnfeeble(gfx: string, delta: number) {
+ cmd('changeEnfeeble', { change: delta, gfx, figureId: '', ownerId });
+ }
+</script>
+
+<div class="hdr">
+ {#if hasDiviner && !isCharacter}
+ {#if deck.badOmen === 0}
+ <button class="btn" disabled={!player} onclick={() => cmd('badOmen', { allies: name === 'allies' })}>
+ {t('badOmen')}
+ </button>
+ {:else}
+ <span class="label">{t('badOmensLeft', { count: deck.badOmen })}</span>
+ {/if}
+ {/if}
+
+ {#if name === 'Ruinmaw' && !deck.corrosiveSpew}
+ <button class="btn" disabled={!player} onclick={() => cmd('corrosiveSpew')}>
+ {t('corrosiveSpew')}
+ </button>
+ {/if}
+ {#if deck.corrosiveSpew}
+ <span class="label">{t('empowersOnTop')}</span>
+ {/if}
+
+ <button
+ class="btn"
+ disabled={!player}
+ onclick={() => cmd('amdAddMinusOne', { name })}
+ >
+ {deck.addedMinusOnes < 0
+ ? t('addMinusOneCardRemoved', { count: Math.abs(deck.addedMinusOnes) })
+ : t('addMinusOneCardAdded', { count: Math.abs(deck.addedMinusOnes) })}
+ </button>
+
+ <button
+ class="btn"
+ disabled={!player || !deckHasMinus1(deck)}
+ onclick={() => cmd('amdRemoveMinus1', { name })}
+ >
+ {t('removeMinusOneCard')}
+ </button>
+
+ {#if !isCharacter}
+ <button class="btn" disabled={!player} onclick={() => cmd('amdRemoveMinus2', { allies: name === 'allies' })}>
+ {deckMinus2Present(deck)
+ ? t('removeMinusTwoCard')
+ : t('minusTwoCardRemoved')}
+ </button>
+ {/if}
+
+ {#if isCharacter && hasPlus0Card}
+ <button
+ class="btn"
+ disabled={!player}
+ onclick={() => cmd('amdRemovePlus0', { name, remove: hasPlus0Card })}
+ >
+ {hasPlus0Card ? t('removePlusZeroCard') : t('plusZeroCardRemoved')}
+ </button>
+ {/if}
+
+ {#if monsterDeck}
+ <button
+ class="btn"
+ disabled={!player}
+ onclick={() =>
+ cmd(deck.imbuement > 0 ? 'amdRemoveImbue' : 'amdImbue1')}
+ >
+ {deck.imbuement > 0 ? t('removeImbue') : t('imbue')}
+ </button>
+ {#if deck.imbuement !== 2}
+ <button class="btn" disabled={!player} onclick={() => cmd('amdImbue2')}>
+ {t('advancedImbue')}
+ </button>
+ {/if}
+ {/if}
+
+ {#if name === '' && hail != null}
+ <button
+ class="btn"
+ disabled={!player}
+ onclick={() => cmd('addPerk', { characterId: 'Hail', index: HAIL_PERK_INDEX })}
+ >
+ {hasHailPerk ? t('removeHailPerk') : t('addHailPerk')}
+ </button>
+ {/if}
+
+ {#if hasCassandraPerk}
+ <button
+ class="btn"
+ disabled={!player}
+ onclick={() =>
+ cmd('amdCassandraSpecial', { deckId: name, on: !deck.cassandra })}
+ >
+ {deck.cassandra
+ ? t('dontSaveRevealedCards')
+ : t('saveRevealedCards')}
+ </button>
+ {/if}
+
+ {#if deck.removedPile.length > 0}
+ <button class="btn" disabled={!player} onclick={onOpenRemoved}>
+ {t('removedCountLabel', { count: deck.removedPile.length })}
+ </button>
+ {/if}
+
+ {#if isCSCampaign(state.currentCampaign) && isCharacter}
+ {#if deck.drawPile.some((c) => c.gfx.startsWith('sanctuary')) || deck.discardPile.some((c) => c.gfx.startsWith('sanctuary'))}
+ <button
+ class="btn"
+ disabled={!player}
+ onclick={() =>
+ cmd('removeCSSanctuaryDonation', { characterId: name })}
+ >
+ {t('removeDonation')}
+ </button>
+ {:else}
+ <button
+ class="btn"
+ disabled={!player}
+ onclick={() => cmd('donateCSSanctuary', { characterId: name })}
+ >
+ {t('donateSanctuary')}
+ </button>
+ {/if}
+
+ {#if deck.drawPile.some((c) => c.gfx.startsWith('party')) || deck.discardPile.some((c) => c.gfx.startsWith('party'))}
+ <button
+ class="btn"
+ disabled={!player}
+ onclick={() => cmd('removeCSPartyCard', { characterId: name })}
+ >
+ {t('removePartyCard')}
+ </button>
+ {:else}
+ <span class="label">{t('addPartyCard')}</span>
+ {#each Array(PARTY_BUTTON_COUNT) as _, i}
+ <button
+ class="btn btn--num"
+ disabled={!player}
+ onclick={() =>
+ cmd('addCSPartyCard', { characterId: name, type: 1 })}
+ >
+ {i + 1}
+ </button>
+ {/each}
+ {/if}
+ {/if}
+
+ {#if isCharacter}
+ {#each factionUnlocked as faction}
+ <button
+ class="btn btn--icon"
+ disabled={!player}
+ aria-label={faction}
+ onclick={() => onOpenFaction(faction)}
+ >
+ <img
+ src={
+ faction === 'Demons'
+ ? '/images/demons.png'
+ : faction === 'Merchant-Guild'
+ ? '/images/merchant-guild.png'
+ : '/images/military.png'
+ }
+ alt={faction}
+ />
+ </button>
+ {/each}
+ {/if}
+
+ <CounterButton
+ image="/images/abilities/bless.png"
+ total={removableTotal(deck, 'bless')}
+ maxValue={MAX_BLESS_CURSE}
+ onDecrement={() => changeBless(-1)}
+ onIncrement={() => changeBless(1)}
+ />
+ <CounterButton
+ image="/images/abilities/curse.png"
+ total={removableTotal(deck, 'curse')}
+ maxValue={MAX_BLESS_CURSE}
+ onDecrement={() => changeCurse(-1)}
+ onIncrement={() => changeCurse(1)}
+ />
+
+ {#if hasIncarnate && !isCharacter}
+ <CounterButton
+ image="/images/abilities/enfeeble_old.png"
+ total={removableTotal(deck, 'in-enfeeble')}
+ maxValue={MAX_BLESS_CURSE}
+ extraImage={moreThanOneEnfeeble ? '/images/class-icons/Incarnate.png' : null}
+ onDecrement={() => changeEnfeeble('in-enfeeble', -1)}
+ onIncrement={() => changeEnfeeble('in-enfeeble', 1)}
+ />
+ {/if}
+ {#if (isCharacter || name === 'allies') && hasIncarnate}
+ <CounterButton
+ image="/images/abilities/empower_old.png"
+ total={removableTotal(deck, 'in-empower')}
+ maxValue={MAX_BLESS_CURSE}
+ extraImage={moreThanOneEmpower ? '/images/class-icons/Incarnate.png' : null}
+ onDecrement={() => changeEmpower('in-empower', -1)}
+ onIncrement={() => changeEmpower('in-empower', 1)}
+ />
+ {/if}
+ {#if name === 'Ruinmaw'}
+ <CounterButton
+ image="/images/abilities/empower_old.png"
+ total={removableTotal(deck, 'rm-empower')}
+ maxValue={MAX_RUINMAW_EMPOWER}
+ extraImage={moreThanOneEmpower ? '/images/class-icons/Ruinmaw.png' : null}
+ onDecrement={() => changeEmpower('rm-empower', -1)}
+ onIncrement={() => changeEmpower('rm-empower', 1)}
+ />
+ {/if}
+ {#if (isCharacter || name === 'allies') && hasVimthreader}
+ <CounterButton
+ image="/images/abilities/empower.png"
+ total={removableTotal(deck, 'vi-empower')}
+ maxValue={MAX_BLESS_CURSE}
+ extraImage={moreThanOneEmpower ? '/images/class-icons/Vimthreader.png' : null}
+ onDecrement={() => changeEmpower('vi-empower', -1)}
+ onIncrement={() => changeEmpower('vi-empower', 1)}
+ />
+ <CounterButton
+ image="/images/abilities/greater-empower.png"
+ total={removableTotal(deck, 'vi-gr-empower')}
+ maxValue={MAX_VIMTHREADER_GR_EMPOWER}
+ onDecrement={() => changeEmpower('vi-gr-empower', -1)}
+ onIncrement={() => changeEmpower('vi-gr-empower', 1)}
+ />
+ {/if}
+ {#if !isCharacter && hasVimthreader}
+ <CounterButton
+ image="/images/abilities/enfeeble.png"
+ total={removableTotal(deck, 'vi-enfeeble')}
+ maxValue={MAX_BLESS_CURSE}
+ extraImage={moreThanOneEnfeeble ? '/images/class-icons/Vimthreader.png' : null}
+ onDecrement={() => changeEnfeeble('vi-enfeeble', -1)}
+ onIncrement={() => changeEnfeeble('vi-enfeeble', 1)}
+ />
+ <CounterButton
+ image="/images/abilities/greater-enfeeble.png"
+ total={removableTotal(deck, 'vi-gr-enfeeble')}
+ maxValue={MAX_BLESS_CURSE}
+ onDecrement={() => changeEnfeeble('vi-gr-enfeeble', -1)}
+ onIncrement={() => changeEnfeeble('vi-gr-enfeeble', 1)}
+ />
+ {/if}
+ {#if (!isCharacter || name === 'Lifespeaker') && hasLifespeaker}
+ <CounterButton
+ image="/images/abilities/enfeeble.png"
+ total={removableTotal(deck, 'li-enfeeble')}
+ maxValue={MAX_LIFESPEAKER_ENFEEBLE}
+ extraImage={moreThanOneEnfeeble ? '/images/class-icons/Lifespeaker.png' : null}
+ onDecrement={() => changeEnfeeble('li-enfeeble', -1)}
+ onIncrement={() => changeEnfeeble('li-enfeeble', 1)}
+ />
+ {/if}
+
+ {#if isCharacter && characterClassData && characterClassData.perkDetails.length > 0}
+ <button class="btn" disabled={!player} onclick={onOpenPerks}>
+ {t('perks')}
+ </button>
+ {/if}
+
+ <span class="label">{t('revealCards')}</span>
+ {#each Array(revealCount) as _, i}
+ <button
+ class="btn btn--num"
+ disabled={!player}
+ onclick={() => cmd('amdReveal', { amount: i, name })}
+ >
+ {i >= drawPile.length ? t('revealAll') : i}
+ </button>
+ {/each}
+</div>
+
+<style>
+ .hdr {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: 4px;
+ margin-bottom: 10px;
+ }
+ .btn {
+ padding: 4px 8px;
+ font-size: 12px;
+ border: none;
+ border-radius: 4px;
+ background: rgba(255, 255, 255, 0.12);
+ color: inherit;
+ cursor: pointer;
+ white-space: pre;
+ }
+ .btn:hover:not(:disabled) {
+ background: rgba(255, 255, 255, 0.25);
+ }
+ .btn:disabled {
+ opacity: 0.35;
+ cursor: default;
+ }
+ .btn--num {
+ min-width: 30px;
+ padding: 4px 6px;
+ }
+ .btn--icon {
+ width: 34px;
+ height: 34px;
+ padding: 3px;
+ }
+ .btn--icon img {
+ width: 100%;
+ height: 100%;
+ object-fit: contain;
+ }
+ .label {
+ font-size: 12px;
+ opacity: 0.85;
+ white-space: pre;
+ }
+</style>
diff --git a/web/src/lib/ui/decks/ModifierDeckMenu.svelte b/web/src/lib/ui/decks/ModifierDeckMenu.svelte
new file mode 100644
index 0000000..2cfac21
--- /dev/null
+++ b/web/src/lib/ui/decks/ModifierDeckMenu.svelte
@@ -0,0 +1,570 @@
+<!--
+ The modifier-deck menu (the reference `ModifierDeckMenu`): the header
+ command bar above two card columns — the draw pile (top-first,
+ drag-reorderable, tap → "send to bottom / shuffle / remove") and the
+ discard pile (face up, tap → "remove / return top card"). The header's
+ "Removed", faction, and Perks buttons open nested submenus (the
+ reference's RemovedModifierCardMenu / GH2eFactionAMDCardMenu /
+ PerksMenu dialogs).
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import type { ModifierDeck as Deck } from '$lib/protocol/types';
+ import { isCharacter } from '$lib/protocol/types';
+ import type { ClassData } from '$lib/data/gameData';
+ import { t } from '$lib/i18n';
+ import {
+ drawPileTopFirst,
+ factionCards,
+ factionCardInAnyCharacterDeck
+ } from '$lib/game/modifierDeck';
+ import {
+ activePerks,
+ canAddPerk,
+ canRemovePerk,
+ perkDescription
+ } from '$lib/game/perks';
+ import ModifierCard from '../cards/ModifierCard.svelte';
+ import ModifierDeckHeader from './ModifierDeckHeader.svelte';
+ import Menu from '../Menu.svelte';
+
+ const LIST_CARD_SCALE = 0.8;
+ // Submenu card preview (the reference zooms at 6x, clamped to width).
+ const PREVIEW_SCALE = 3.0;
+
+ let {
+ session,
+ deck,
+ name,
+ characterClassData = null,
+ open = $bindable(true)
+ }: {
+ session: GameSession;
+ deck: Deck;
+ /** "" party deck, "allies", or a character id. */
+ name: string;
+ /** The owning character's class data (character decks only). */
+ characterClassData?: ClassData | null;
+ open?: boolean;
+ } = $props();
+
+ const gameState = session.state;
+ const player = session.player;
+
+ const isCharacterDeck = $derived(name !== '' && name !== 'allies');
+
+ const drawTopFirst = $derived(drawPileTopFirst(deck));
+ // The discard pile displays most-recently-drawn first (the reference
+ // reverses the pile list); taps map back to pile indices.
+ const discardDisplay = $derived([...deck.discardPile].reverse());
+ const removedDisplay = $derived([...deck.removedPile].reverse());
+
+ // The top `deck.revealed` draw cards are face up (Cassandra's special).
+ function isDrawRevealed(pileIndex: number): boolean {
+ const topFirst = drawPileTopFirst(deck);
+ return topFirst.length - 1 - pileIndex < deck.revealed;
+ }
+
+ function cmd(command: string, args: Record<string, unknown> = {}) {
+ if ($player) session.command(command, args);
+ }
+
+ // --- 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;
+ cmd('reorderModifierList', {
+ newIndex: n - 1 - dropIndex,
+ oldIndex: n - 1 - dragIndex,
+ name
+ });
+ }
+ dragIndex = null;
+ dropIndex = null;
+ }
+
+ // --- submenus (nested overlays, the reference's dialog stack) ------------
+
+ type Sub =
+ | { kind: 'sendToBottom'; displayIndex: number }
+ | { kind: 'removeAmd'; pileIndex: number }
+ | { kind: 'removed' }
+ | { kind: 'returnAmd'; pileIndex: number }
+ | { kind: 'faction'; faction: string }
+ | { kind: 'perks' };
+
+ let sub = $state<Sub | null>(null);
+
+ // Close a stale discard-pile submenu when the pile shrinks (the reference
+ // pops when `index >= discardPileSize`).
+ $effect(() => {
+ if (
+ sub?.kind === 'removeAmd' &&
+ sub.pileIndex >= deck.discardPile.length
+ ) {
+ sub = null;
+ }
+ });
+
+ // The character (for the perks submenu).
+ const character = $derived(
+ ($gameState?.currentList ?? []).find(
+ (i): i is import('$lib/protocol/types').CharacterItem =>
+ isCharacter(i) && i.id === name
+ ) ?? null
+ );
+
+ // The faction-cards submenu state (which card this deck has added).
+ const factionGfxs = $derived(
+ sub?.kind === 'faction' ? factionCards(sub.faction) : []
+ );
+ const factionAdded = $derived(
+ sub?.kind === 'faction'
+ ? factionGfxs.find((g) =>
+ deck.drawPile.some((c) => c.gfx === g) ||
+ deck.discardPile.some((c) => c.gfx === g)
+ ) ?? null
+ : null
+ );
+
+ /** Every character's personal deck (the faction gray-out check). */
+ const characterDecks = $derived(
+ ($gameState?.currentList ?? []).filter(isCharacter).map((c) => ({
+ name: c.id,
+ deck: c.characterState.modifierDeck
+ }))
+ );
+
+ function factionGrayed(gfx: string): boolean {
+ return factionCardInAnyCharacterDeck(characterDecks, gfx);
+ }
+
+ // Perks submenu state.
+ const perks = $derived(
+ isCharacterDeck && character && characterClassData
+ ? activePerks(characterClassData, character.characterState)
+ : []
+ );
+</script>
+
+<Menu {open} title={name === '' ? 'Global' : name}>
+ {#if $gameState}
+ <ModifierDeckHeader
+ {session}
+ state={$gameState}
+ {deck}
+ {name}
+ {characterClassData}
+ onOpenRemoved={() => (sub = { kind: 'removed' })}
+ onOpenPerks={() => (sub = { kind: 'perks' })}
+ onOpenFaction={(faction) => (sub = { kind: 'faction', faction })}
+ />
+
+ <div class="columns">
+ <div class="col" ondragend={() => (dragIndex = null)} ondrop={onDrop}>
+ {#each drawTopFirst as card, i}
+ {@const pileIndex = deck.drawPile.length - 1 - i}
+ <div
+ class="cardwrap"
+ draggable
+ ondragstart={() => onDragStart(i)}
+ ondragover={(e) => onDragOver(e, i)}
+ onclick={() =>
+ (sub = { kind: 'sendToBottom', displayIndex: i })}
+ role="button"
+ tabindex="0"
+ onkeydown={(e) => {
+ if (e.key === 'Enter' || e.key === ' ')
+ sub = { kind: 'sendToBottom', displayIndex: i };
+ }}
+ >
+ <ModifierCard
+ {card}
+ {name}
+ revealed={isDrawRevealed(pileIndex)}
+ scale={LIST_CARD_SCALE}
+ />
+ </div>
+ {/each}
+ </div>
+
+ <div class="col">
+ {#each discardDisplay as card, i}
+ {@const pileIndex = deck.discardPile.length - 1 - i}
+ <div
+ class="cardwrap"
+ onclick={() => (sub = { kind: 'removeAmd', pileIndex })}
+ role="button"
+ tabindex="0"
+ onkeydown={(e) => {
+ if (e.key === 'Enter' || e.key === ' ')
+ sub = { kind: 'removeAmd', pileIndex };
+ }}
+ >
+ <ModifierCard {card} {name} revealed scale={LIST_CARD_SCALE} />
+ </div>
+ {/each}
+ </div>
+ </div>
+ {/if}
+
+ <!-- send-to-bottom (draw-pile card) -->
+ {#if sub?.kind === 'sendToBottom'}
+ {@const pileIndex = deck.drawPile.length - 1 - sub.displayIndex}
+ {@const card = deck.drawPile[pileIndex]}
+ <div class="confirm" role="dialog" aria-modal="true">
+ {#if card}
+ <ModifierCard
+ {card}
+ {name}
+ revealed={isDrawRevealed(pileIndex)}
+ scale={PREVIEW_SCALE}
+ />
+ {/if}
+ <div class="confirm__btns">
+ <button
+ class="pill pill--text"
+ onclick={() => {
+ cmd('reorderModifierList', {
+ newIndex: 0,
+ oldIndex: pileIndex,
+ name
+ });
+ sub = null;
+ }}
+ >
+ {t('sendToBottom')}
+ </button>
+ <button
+ class="pill pill--text"
+ onclick={() => {
+ cmd('shuffleAMDCard', { name });
+ sub = null;
+ }}
+ >
+ {t('shuffleUndrawnCards')}
+ </button>
+ <button
+ class="pill pill--text"
+ onclick={() => {
+ cmd('removeAMDCard', { index: pileIndex, name, fromDrawPile: true });
+ sub = null;
+ }}
+ >
+ {t('removeCardQuestion')}
+ </button>
+ </div>
+ </div>
+ {/if}
+
+ <!-- remove / return (discard-pile card) -->
+ {#if sub && sub.kind === 'removeAmd'}
+ {@const s = sub}
+ {@const card = deck.discardPile[s.pileIndex]}
+ <div class="confirm" role="dialog" aria-modal="true">
+ {#if card}
+ <ModifierCard {card} {name} revealed scale={PREVIEW_SCALE} />
+ {/if}
+ <div class="confirm__btns">
+ <button
+ class="pill pill--text"
+ onclick={() => {
+ cmd('removeAMDCard', { index: s.pileIndex, name });
+ sub = null;
+ }}
+ >
+ {t('removeCardQuestion')}
+ </button>
+ <button
+ class="pill pill--text"
+ onclick={() => cmd('returnModifierCard', { name })}
+ >
+ {t('returnTopCard')}
+ </button>
+ </div>
+ </div>
+ {/if}
+
+ <!-- removed cards -->
+ {#if sub?.kind === 'removed'}
+ <div class="sub">
+ <div class="sub__title">Removed cards</div>
+ <div class="col">
+ {#each removedDisplay as card, i}
+ {@const pileIndex = deck.removedPile.length - 1 - i}
+ <div
+ class="cardwrap"
+ onclick={() => (sub = { kind: 'returnAmd', pileIndex })}
+ role="button"
+ tabindex="0"
+ onkeydown={(e) => {
+ if (e.key === 'Enter' || e.key === ' ')
+ sub = { kind: 'returnAmd', pileIndex };
+ }}
+ >
+ <ModifierCard {card} {name} revealed scale={LIST_CARD_SCALE} />
+ </div>
+ {/each}
+ </div>
+ </div>
+ {/if}
+
+ <!-- return a removed card -->
+ {#if sub && sub.kind === 'returnAmd'}
+ {@const s = sub}
+ {@const card = deck.removedPile[s.pileIndex]}
+ <div class="confirm" role="dialog" aria-modal="true">
+ {#if card}
+ <ModifierCard {card} {name} revealed scale={PREVIEW_SCALE} />
+ {/if}
+ <div class="confirm__btns">
+ <button
+ class="pill pill--text"
+ onclick={() => {
+ cmd('returnRemovedAMDCard', {
+ index: s.pileIndex,
+ name,
+ toDrawPile: false
+ });
+ sub = null;
+ }}
+ >
+ {t('returnToDiscardPile')}
+ </button>
+ <button
+ class="pill pill--text"
+ onclick={() => {
+ cmd('returnRemovedAMDCard', {
+ index: s.pileIndex,
+ name,
+ toDrawPile: true
+ });
+ sub = null;
+ }}
+ >
+ {t('returnToDrawPile')}
+ </button>
+ </div>
+ </div>
+ {/if}
+
+ <!-- faction cards -->
+ {#if sub?.kind === 'faction'}
+ <div class="sub">
+ <div class="grid">
+ {#each factionGfxs as gfx}
+ <button
+ class="grid__cell"
+ class:grid__cell--grayed={factionGrayed(gfx)}
+ disabled={!player}
+ aria-label={gfx}
+ onclick={() => {
+ if (factionAdded == null && !factionGrayed(gfx)) {
+ cmd('addFactionCard', {
+ characterId: name,
+ cardId: gfx,
+ add: true
+ });
+ }
+ }}
+ >
+ <ModifierCard
+ card={{ gfx }}
+ name=""
+ revealed
+ scale={PREVIEW_SCALE}
+ />
+ </button>
+ {/each}
+ </div>
+ <div class="confirm__btns">
+ {#if factionAdded == null}
+ <span class="label">{t('tapCardToAddToDeck')}</span>
+ {:else}
+ <button
+ class="pill pill--text"
+ onclick={() => {
+ cmd('addFactionCard', {
+ characterId: name,
+ cardId: factionAdded,
+ add: false
+ });
+ }}
+ >
+ {t('removeCardFromDeckQuestion')}
+ </button>
+ {/if}
+ </div>
+ </div>
+ {/if}
+
+ <!-- perks -->
+ {#if sub?.kind === 'perks' && character && characterClassData}
+ <div class="sub sub--perks">
+ <div class="sub__title">{t('addPerks')}</div>
+ {#if characterClassData.perkDetailsFH.length > 0}
+ <label class="perkrow">
+ <input
+ type="checkbox"
+ checked={character.characterState.useFHPerks}
+ disabled={!player}
+ onchange={() =>
+ cmd('useFHPerks', { characterId: character.id })}
+ />
+ <span>{t('useFrosthavenPerks')}</span>
+ </label>
+ {/if}
+ {#each perks as perk, i}
+ {@const added = character.characterState.perkList[i] ?? false}
+ {@const enabled = added
+ ? canRemovePerk(
+ character.characterState.modifierDeck,
+ perks,
+ i
+ )
+ : canAddPerk(
+ character.characterState.modifierDeck,
+ perks,
+ character.characterState.perkList,
+ i
+ )}
+ <div class="divider"></div>
+ <label class="perkrow" class:perkrow--disabled={!enabled}>
+ <input
+ type="checkbox"
+ checked={added}
+ disabled={!player || !enabled}
+ onchange={() =>
+ cmd('addPerk', { characterId: character.id, index: i })}
+ />
+ <span class="perkrow__desc">{perkDescription(perk)}</span>
+ </label>
+ {/each}
+ </div>
+ {/if}
+</Menu>
+
+<style>
+ .columns {
+ display: flex;
+ gap: 12px;
+ align-items: flex-start;
+ }
+ .col {
+ flex: 1;
+ display: flex;
+ flex-direction: column;
+ gap: 8px;
+ max-height: 50vh;
+ overflow-y: auto;
+ }
+ .cardwrap {
+ cursor: pointer;
+ border-radius: 6px;
+ }
+ .cardwrap:focus-visible {
+ outline: 2px solid #7ec8ff;
+ }
+ .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;
+ }
+ .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;
+ flex-wrap: wrap;
+ gap: 8px;
+ justify-content: center;
+ }
+ .sub {
+ 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);
+ }
+ .sub__title {
+ font-size: 14px;
+ font-weight: 600;
+ }
+ .sub--perks {
+ align-items: stretch;
+ max-height: 60vh;
+ overflow-y: auto;
+ }
+ .grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, 60px);
+ gap: 8px;
+ justify-content: center;
+ }
+ .grid__cell {
+ padding: 0;
+ background: none;
+ border: none;
+ cursor: pointer;
+ }
+ .grid__cell--grayed {
+ filter: grayscale(1);
+ opacity: 0.5;
+ }
+ .label {
+ font-size: 13px;
+ }
+ .perkrow {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ padding: 4px 0;
+ font-size: 13px;
+ cursor: pointer;
+ }
+ .perkrow--disabled {
+ opacity: 0.35;
+ cursor: default;
+ }
+ .perkrow__desc {
+ flex: 1;
+ }
+ .divider {
+ height: 1px;
+ background: rgba(255, 255, 255, 0.2);
+ }
+</style>
diff --git a/web/src/lib/ui/decks/ModifierDeckWidget.svelte b/web/src/lib/ui/decks/ModifierDeckWidget.svelte
new file mode 100644
index 0000000..a79bf50
--- /dev/null
+++ b/web/src/lib/ui/decks/ModifierDeckWidget.svelte
@@ -0,0 +1,185 @@
+<!--
+ One modifier (AMD) deck (the reference `ModifierDeckWidget`): the draw
+ pile (tap to draw; face-up top card when cards are revealed; a class icon
+ + "Shuffle & Draw" when empty) beside the discard box (tap to open the
+ deck menu, double-tap to zoom the top card).
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import type { ModifierDeck as Deck } from '$lib/protocol/types';
+ import { currentCharacterId } from '$lib/game/rules';
+ import ModifierCard from '../cards/ModifierCard.svelte';
+
+ let {
+ session,
+ deck,
+ name,
+ className = null,
+ perks = null,
+ onOpenMenu,
+ onZoom
+ }: {
+ session: GameSession;
+ deck: Deck;
+ /** "" party deck, "allies", or a character id. */
+ name: string;
+ /** The character-class name (deck icon), null for party decks. */
+ className?: string | null;
+ /** The class's perk `adds` lists (for `P<n>` card graphics). */
+ perks?: string[][] | null;
+ onOpenMenu: () => void;
+ onZoom: () => void;
+ } = $props();
+
+ const gameState = session.state;
+ const player = session.player;
+
+ // The empty-draw-pile icon: the current character, but only when this
+ // deck is theirs (the reference `currentCharacter`).
+ const showIcon = $derived(
+ className != null && $gameState != null && currentCharacterId($gameState) === className
+ );
+
+ const drawTop = $derived(
+ deck.drawPile.length > 0
+ ? deck.drawPile[deck.drawPile.length - 1]
+ : null
+ );
+ // The top three discard cards, bottom-most first (for the stack offsets).
+ const discardStack = $derived(
+ deck.discardPile.slice(-3).map((c, i, arr) => ({
+ card: c,
+ depth: arr.length - 1 - i
+ }))
+ );
+
+ function draw() {
+ if ($player && deck.drawPile.length > 0) {
+ session.command('drawModifierCard', { name });
+ }
+ }
+</script>
+
+<div class="deck">
+ <div
+ class="drawpile"
+ role="button"
+ tabindex={0}
+ aria-label="draw pile"
+ onclick={draw}
+ onkeydown={(e) => {
+ if (e.key === 'Enter' || e.key === ' ') draw();
+ }}
+ >
+ {#if drawTop != null}
+ <ModifierCard
+ card={drawTop}
+ {name}
+ revealed={deck.revealed > 0}
+ {perks}
+ />
+ {:else}
+ <div class="empty">
+ {#if className}
+ <img class="empty__icon" src="/images/class-icons/{className}.png" alt={className} />
+ {/if}
+ <span class="empty__label">Shuffle &amp; Draw</span>
+ </div>
+ {/if}
+ <span class="count">{deck.drawPile.length}</span>
+ </div>
+
+ <div
+ class="discard"
+ role="button"
+ tabindex={0}
+ aria-label="discard pile"
+ onclick={onOpenMenu}
+ ondblclick={onZoom}
+ onkeydown={(e) => {
+ if (e.key === 'Enter' || e.key === ' ') onOpenMenu();
+ }}
+ >
+ {#each discardStack as entry}
+ <div
+ class="discard__card"
+ style="left: {entry.depth * 11}px; transform: rotate({entry.depth === 0 ? 0 : entry.depth * -7.5}deg)"
+ >
+ <ModifierCard card={entry.card} {name} revealed {perks} />
+ </div>
+ {/each}
+ </div>
+</div>
+
+<style>
+ .deck {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ width: 153px;
+ height: 39px;
+ }
+ .drawpile {
+ position: relative;
+ width: 58.6666px;
+ height: 39px;
+ cursor: pointer;
+ }
+ .drawpile:focus-visible {
+ outline: 2px solid #7ec8ff;
+ border-radius: 4px;
+ }
+ .empty {
+ position: relative;
+ width: 58.6666px;
+ height: 39px;
+ border-radius: 4px;
+ background: rgba(0, 0, 0, 0.48);
+ display: flex;
+ align-items: flex-end;
+ justify-content: center;
+ }
+ .empty__icon {
+ position: absolute;
+ top: 4px;
+ left: 12px;
+ width: 27px;
+ height: 27px;
+ filter: brightness(0.6);
+ }
+ .empty__label {
+ font-size: 9px;
+ color: #fff;
+ text-shadow: 0.6px 0.6px 1px rgba(0, 0, 0, 0.87);
+ padding-bottom: 2px;
+ }
+ .count {
+ position: absolute;
+ right: 3px;
+ bottom: 0;
+ font-size: 13px;
+ font-weight: 700;
+ color: #fff;
+ text-shadow: 1px 1px 1px #000;
+ pointer-events: none;
+ }
+ .discard {
+ position: relative;
+ width: 66.6666px;
+ height: 39px;
+ border-radius: 5px;
+ border: 1px solid rgba(255, 255, 255, 0.7);
+ background: rgba(0, 0, 0, 0.48);
+ cursor: pointer;
+ overflow: visible;
+ }
+ .discard:focus-visible {
+ outline: 2px solid #7ec8ff;
+ }
+ .discard__card {
+ position: absolute;
+ top: 0;
+ left: 4px;
+ transition: left 0.2s ease, transform 0.2s ease;
+ }
+</style>