summaryrefslogtreecommitdiff
path: root/web/src/lib/ui
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/lib/ui')
-rw-r--r--web/src/lib/ui/CounterButton.svelte115
-rw-r--r--web/src/lib/ui/MainList.svelte19
-rw-r--r--web/src/lib/ui/MonsterRow.svelte44
-rw-r--r--web/src/lib/ui/StatusMenu.svelte16
-rw-r--r--web/src/lib/ui/cards/AbilityCardBack.svelte60
-rw-r--r--web/src/lib/ui/cards/AbilityText.svelte200
-rw-r--r--web/src/lib/ui/cards/LootCard.svelte114
-rw-r--r--web/src/lib/ui/cards/ModifierCard.svelte124
-rw-r--r--web/src/lib/ui/cards/MonsterAbilityCard.svelte157
-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
20 files changed, 3564 insertions, 9 deletions
diff --git a/web/src/lib/ui/CounterButton.svelte b/web/src/lib/ui/CounterButton.svelte
new file mode 100644
index 0000000..8024b0e
--- /dev/null
+++ b/web/src/lib/ui/CounterButton.svelte
@@ -0,0 +1,115 @@
+<!--
+ One [−] icon [total] [+] counter (the reference `CounterButton`): the
+ deck-header removable counters (bless/curse/empower/enfeeble) send
+ changeBless/Curse/Empower/Enfeeble with `change` ±1 through it.
+-->
+<script lang="ts">
+ let {
+ image,
+ total,
+ maxValue,
+ showTotal = true,
+ extraImage = null,
+ onIncrement,
+ onDecrement
+ }: {
+ /** The counter icon, e.g. `/images/abilities/bless.png`. */
+ image: string;
+ /** The current total (the deck's removable counter). */
+ total: number;
+ /** The reference `maxValue` — the plus is disabled at/above it. */
+ maxValue: number;
+ /** Show the total next to the icon (deck headers do). */
+ showTotal?: boolean;
+ /** An optional second icon overprinted (two enfeeble owners, …). */
+ extraImage?: string | null;
+ onIncrement: () => void;
+ onDecrement: () => void;
+ } = $props();
+</script>
+
+<div class="counter" role="group" aria-label={image}>
+ <button
+ class="counter__btn"
+ aria-label="decrease"
+ disabled={total <= 0}
+ onclick={onDecrement}
+ >
+ <img src="/images/psd/sub.png" alt="−" />
+ </button>
+
+ <div class="counter__icon">
+ <img src={image} alt="" />
+ {#if extraImage}
+ <img class="counter__extra" src={extraImage} alt="" />
+ {/if}
+ {#if showTotal}
+ <span class="counter__total">{total}</span>
+ {/if}
+ </div>
+
+ <button
+ class="counter__btn"
+ aria-label="increase"
+ disabled={total >= maxValue}
+ onclick={onIncrement}
+ >
+ <img src="/images/psd/add.png" alt="+" />
+ </button>
+</div>
+
+<style>
+ .counter {
+ display: flex;
+ align-items: center;
+ gap: 2px;
+ }
+ .counter__btn {
+ width: 32px;
+ height: 32px;
+ padding: 2px;
+ background: transparent;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+ }
+ .counter__btn:hover:not(:disabled) {
+ background: rgba(255, 255, 255, 0.15);
+ }
+ .counter__btn:disabled {
+ opacity: 0.35;
+ cursor: default;
+ }
+ .counter__btn img {
+ width: 100%;
+ height: 100%;
+ filter: brightness(0) invert(1);
+ }
+ .counter__icon {
+ position: relative;
+ width: 32px;
+ height: 32px;
+ }
+ .counter__icon > img {
+ width: 100%;
+ height: 100%;
+ object-fit: contain;
+ }
+ .counter__extra {
+ position: absolute;
+ inset: 0;
+ opacity: 0.55;
+ }
+ .counter__total {
+ position: absolute;
+ inset: 0;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 14px;
+ font-weight: 700;
+ color: #fff;
+ text-shadow: 1px 1px 1px #000;
+ pointer-events: none;
+ }
+</style>
diff --git a/web/src/lib/ui/MainList.svelte b/web/src/lib/ui/MainList.svelte
index cb5ad49..f594778 100644
--- a/web/src/lib/ui/MainList.svelte
+++ b/web/src/lib/ui/MainList.svelte
@@ -7,6 +7,8 @@
<script lang="ts">
import type { GameSession } from '$lib/state/session';
import { isCharacter, isMonster, isNoteRow } from '$lib/protocol/types';
+ import type { MonsterItem } from '$lib/protocol/types';
+ import type { CampaignData } from '$lib/data/gameData';
import type { FigureRef } from './StatusMenu.svelte';
import CharacterRow from './CharacterRow.svelte';
import MonsterRow from './MonsterRow.svelte';
@@ -14,10 +16,16 @@
let {
session,
- onOpenMenu
+ onOpenMenu,
+ campaignData,
+ onOpenAbility,
+ onZoomAbility
}: {
session: GameSession;
onOpenMenu: (figure: FigureRef) => void;
+ campaignData: CampaignData | null;
+ onOpenAbility: (item: MonsterItem) => void;
+ onZoomAbility: (item: MonsterItem) => void;
} = $props();
const gameState = session.state;
@@ -29,7 +37,14 @@
{#if isCharacter(item)}
<CharacterRow {session} {item} {onOpenMenu} />
{:else if isMonster(item)}
- <MonsterRow {session} {item} {onOpenMenu} />
+ <MonsterRow
+ {session}
+ {item}
+ {onOpenMenu}
+ {campaignData}
+ {onOpenAbility}
+ {onZoomAbility}
+ />
{:else if isNoteRow(item)}
<NoteRow {session} {item} />
{/if}
diff --git a/web/src/lib/ui/MonsterRow.svelte b/web/src/lib/ui/MonsterRow.svelte
index 3f3442b..e2a4383 100644
--- a/web/src/lib/ui/MonsterRow.svelte
+++ b/web/src/lib/ui/MonsterRow.svelte
@@ -7,18 +7,28 @@
<script lang="ts">
import type { GameSession } from '$lib/state/session';
import type { MonsterItem } from '$lib/protocol/types';
+ import type { CampaignData } from '$lib/data/gameData';
import { monsterImage } from '$lib/game/art';
import { standeeFigureId } from '$lib/game/stats';
+ import { isFrosthavenStyleForMonster } from '$lib/game/rules';
+ import { styleTheme } from '$lib/settings';
import type { FigureRef } from './StatusMenu.svelte';
+ import AbilityCardSlot from './decks/AbilityCardSlot.svelte';
let {
session,
item,
- onOpenMenu
+ onOpenMenu,
+ campaignData,
+ onOpenAbility,
+ onZoomAbility
}: {
session: GameSession;
item: MonsterItem;
onOpenMenu: (figure: FigureRef) => void;
+ campaignData: CampaignData | null;
+ onOpenAbility: (item: MonsterItem) => void;
+ onZoomAbility: (item: MonsterItem) => void;
} = $props();
const player = session.player;
@@ -50,6 +60,26 @@
if (roundState !== 1 || !item.isActive || !$player) return;
session.command('turnDone', { id: item.id });
}
+
+ // --- ability cards (the reference `MonsterAbilityCardWidget`) -----------
+
+ const model = $derived(
+ campaignData?.monsters.find(
+ (m) => m.name === item.type || m.display === item.type
+ ) ?? null
+ );
+
+ const abilityDeck = $derived.by(() => {
+ const gs = $gameState;
+ if (gs == null || model == null) return null;
+ return gs.currentAbilityDecks.find((d) => d.name === model.deck) ?? null;
+ });
+
+ const fh = $derived.by((): boolean => {
+ const gs = $gameState;
+ if (gs == null || model == null) return false;
+ return isFrosthavenStyleForMonster(model.edition, gs, $styleTheme);
+ });
</script>
<div class="row row--monster" class:row--current={currentTurn} class:row--done={gray}>
@@ -106,4 +136,16 @@
{/each}
</div>
{/if}
+
+ {#if $gameState}
+ <AbilityCardSlot
+ state={$gameState}
+ {item}
+ deck={abilityDeck}
+ {campaignData}
+ {fh}
+ onOpen={() => onOpenAbility(item)}
+ onZoom={() => onZoomAbility(item)}
+ />
+ {/if}
</div>
diff --git a/web/src/lib/ui/StatusMenu.svelte b/web/src/lib/ui/StatusMenu.svelte
index 4563c07..46f6325 100644
--- a/web/src/lib/ui/StatusMenu.svelte
+++ b/web/src/lib/ui/StatusMenu.svelte
@@ -7,12 +7,16 @@
-->
<script lang="ts">
import type { GameSession } from '$lib/state/session';
- import type { CharacterItem, MonsterInstance, MonsterItem } from '$lib/protocol/types';
+ import type {
+ CharacterItem,
+ ModifierDeck,
+ MonsterInstance,
+ MonsterItem
+ } from '$lib/protocol/types';
import {
characterStatCounters,
standeeFigureId,
- standeeStatCounters,
- type ModifierDeckJson
+ standeeStatCounters
} from '$lib/game/stats';
import { isObjectiveOrEscort } from '$lib/data/classInfo';
import { CONDITIONS } from '$lib/game/conditions';
@@ -100,9 +104,9 @@
}
const owner = liveOwner;
if (!owner) return null;
- const deck = 'characterState' in owner
- ? (owner.characterState.modifierDeck as ModifierDeckJson | undefined)
- : ($gameState?.modifierDeck as ModifierDeckJson | undefined);
+ const deck: ModifierDeck | undefined = 'characterState' in owner
+ ? owner.characterState.modifierDeck
+ : $gameState?.modifierDeck;
return deck ? standeeStatCounters(deck) : null;
});
diff --git a/web/src/lib/ui/cards/AbilityCardBack.svelte b/web/src/lib/ui/cards/AbilityCardBack.svelte
new file mode 100644
index 0000000..362ced1
--- /dev/null
+++ b/web/src/lib/ui/cards/AbilityCardBack.svelte
@@ -0,0 +1,60 @@
+<!--
+ The back of a monster ability card (the reference
+ `MonsterAbilityCardRear`): the card artwork with the draw-pile size in
+ the bottom-right corner (hidden when `size` is negative).
+-->
+<script lang="ts">
+ let {
+ fh = true,
+ size = -1,
+ scale = 1
+ }: {
+ fh?: boolean;
+ /** The draw-pile count shown bottom-right; negative hides it. */
+ size?: number;
+ scale?: number;
+ } = $props();
+
+ const width = 142.4 * scale;
+ const height = 94.4 * scale;
+</script>
+
+<div
+ class="acback"
+ style="width: {width}px; height: {height}px"
+>
+ <img
+ class="acback__bg"
+ src={fh ? '/images/psd/MonsterAbility-back_fh.png' : '/images/psd/MonsterAbility-back.png'}
+ alt=""
+ draggable="false"
+ />
+ {#if size >= 0}
+ <div class="acback__size" style="font-size: {12.8 * scale}px">{size}</div>
+ {/if}
+</div>
+
+<style>
+ .acback {
+ position: relative;
+ border-radius: 4px;
+ flex-shrink: 0;
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
+ }
+ .acback__bg {
+ position: absolute;
+ inset: 0;
+ width: 100%;
+ height: 100%;
+ border-radius: 4px;
+ object-fit: fill;
+ }
+ .acback__size {
+ position: absolute;
+ right: 4.8px;
+ bottom: 0;
+ font-family: system-ui, sans-serif;
+ color: #fff;
+ text-shadow: 0.8px 0.8px 1px #000;
+ }
+</style>
diff --git a/web/src/lib/ui/cards/AbilityText.svelte b/web/src/lib/ui/cards/AbilityText.svelte
new file mode 100644
index 0000000..51fe672
--- /dev/null
+++ b/web/src/lib/ui/cards/AbilityText.svelte
@@ -0,0 +1,200 @@
+<!--
+ The ability-line renderer (the web counterpart of the reference
+ `LineBuilder.createLines` output, PORTING.md §8b). Walks the structured
+ tree produced by `parseLines` and renders it: rows of text / icons /
+ element-use, gray sub-line boxes, dotted conditional boxes, columns,
+ row-groups, element images and dividers. Font metrics come from
+ `resolveStyle` (the reference `LineStyles`); icons come from the served
+ `/images/abilities/` assets.
+-->
+<script lang="ts">
+ import type { LineStyle, Node } from '$lib/game/line/types';
+ import { resolveStyle } from '$lib/game/line/lineStyle';
+ import { abilityImage, dividerImage } from '$lib/game/line/images';
+
+ let {
+ node,
+ fh = true,
+ left = false,
+ scale = 1
+ }: {
+ node: Node;
+ fh?: boolean;
+ left?: boolean;
+ scale?: number;
+ } = $props();
+
+ /** The resolved font metrics for a style. */
+ function r(style: LineStyle) {
+ return resolveStyle(style, fh, left);
+ }
+</script>
+
+{#if node.kind === 'column'}
+ <div class="at-col" style="align-items: {node.align === 'left' ? 'flex-start' : node.align === 'right' ? 'flex-end' : 'center'}">
+ {#each node.children as child}
+ <svelte:self node={child} {fh} {left} {scale} />
+ {/each}
+ </div>
+{:else if node.kind === 'row' || node.kind === 'rowgroup'}
+ <div
+ class="at-row"
+ class:at-row--group={node.kind === 'rowgroup'}
+ style="justify-content: {node.align === 'left' ? 'flex-start' : node.align === 'right' ? 'flex-end' : 'center'}"
+ >
+ {#each node.children as child}
+ <svelte:self node={child} {fh} {left} {scale} />
+ {/each}
+ </div>
+{:else if node.kind === 'subline'}
+ <div class="at-subline" class:at-subline--boss={node.boss}>
+ {#each node.children as child}
+ <svelte:self node={child} {fh} {left} {scale} />
+ {/each}
+ </div>
+{:else if node.kind === 'conditional'}
+ <div class="at-conditional" class:at-conditional--boss={node.boss} class:at-conditional--banner={node.belongs}>
+ {#if node.belongs}
+ <img class="at-conditional__banner" src="/images/abilities/element_top.png" alt="" />
+ {/if}
+ <div class="at-conditional__inner">
+ {#each node.children as child}
+ <svelte:self node={child} {fh} {left} {scale} />
+ {/each}
+ </div>
+ </div>
+{:else if node.kind === 'text'}
+ {@const m = r(node.style)}
+ {#if m.color !== 'transparent'}
+ <span
+ class="at-text"
+ style="font-size: {m.size * scale}px; line-height: {m.height}; color: {m.color}"
+ >{node.text}</span>
+ {:else}
+ <span style="display: inline-block; width: {m.size * scale}px"></span>
+ {/if}
+{:else if node.kind === 'token'}
+ {@const h = r(node.style).size * scale}
+ <img
+ class="at-token"
+ src={abilityImage(node.gfx, node.token, fh)}
+ alt={node.token}
+ style="height: {h}px; width: {h}px"
+ draggable="false"
+ />
+{:else if node.kind === 'elementUse'}
+ {@const h = r(node.style).size * scale}
+ <span class="at-use" style="height: {h}px; width: {h}px">
+ <img src={abilityImage(node.element, node.element, fh)} alt={node.element} style="height: {h}px; width: {h}px" draggable="false" />
+ <img
+ class="at-use__use"
+ src={abilityImage('use', 'use', fh)}
+ alt="use"
+ style="height: {h * 0.5}px"
+ draggable="false"
+ />
+ </span>
+{:else if node.kind === 'image'}
+ {@const h = r('normal').size * scale * (node.element ? 0.6 : 1)}
+ <img
+ class="at-image"
+ src={abilityImage(node.gfx, node.gfx, fh)}
+ alt={node.gfx}
+ style="height: {h}px"
+ draggable="false"
+ />
+{:else if node.kind === 'divider'}
+ <img
+ class="at-divider"
+ src={dividerImage(node.boss)}
+ alt=""
+ style="height: {node.thin ? 2 * scale : 6 * scale}px; width: {55 * scale}px"
+ draggable="false"
+ />
+{/if}
+
+<style>
+ .at-col {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ width: 100%;
+ }
+ .at-row {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ width: 100%;
+ }
+ .at-row--group {
+ gap: 2px;
+ }
+ .at-text {
+ font-family: 'Markazi', 'Majalla', system-ui, sans-serif;
+ white-space: pre-wrap;
+ text-shadow: 0.4px 0.4px 1px rgba(0, 0, 0, 0.87);
+ }
+ .at-token {
+ display: inline-block;
+ vertical-align: middle;
+ flex-shrink: 0;
+ }
+ .at-image {
+ display: block;
+ margin: 0 auto;
+ }
+ .at-divider {
+ display: block;
+ margin: 0 auto;
+ opacity: 0.9;
+ }
+ .at-use {
+ position: relative;
+ display: inline-block;
+ vertical-align: middle;
+ flex-shrink: 0;
+ }
+ .at-use__use {
+ position: absolute;
+ bottom: 0;
+ left: 20%;
+ }
+ .at-subline {
+ display: flex;
+ flex-direction: column;
+ background: rgba(128, 128, 128, 0.6);
+ border-radius: 6px;
+ padding: 0.5px 2.5px 0.3px 2px;
+ margin: 0 2px;
+ }
+ .at-subline--boss {
+ background: rgba(210, 210, 210, 0.27);
+ }
+ .at-subline .at-row {
+ justify-content: flex-start;
+ }
+ .at-conditional {
+ position: relative;
+ display: inline-block;
+ margin: 2px;
+ }
+ .at-conditional__inner {
+ display: flex;
+ flex-direction: column;
+ background: rgba(128, 128, 128, 0.6);
+ border: 1.5px dotted rgba(255, 255, 255, 0.85);
+ border-radius: 10px;
+ padding: 2px 2px 0.5px 2px;
+ }
+ .at-conditional--boss .at-conditional__inner {
+ background: rgba(210, 210, 210, 0.27);
+ }
+ .at-conditional__banner {
+ position: absolute;
+ top: -3px;
+ left: 50%;
+ transform: translateX(-50%);
+ width: 20px;
+ z-index: 1;
+ }
+</style>
diff --git a/web/src/lib/ui/cards/LootCard.svelte b/web/src/lib/ui/cards/LootCard.svelte
new file mode 100644
index 0000000..49ddb2b
--- /dev/null
+++ b/web/src/lib/ui/cards/LootCard.svelte
@@ -0,0 +1,114 @@
+<!--
+ One loot card (the reference `LootCardFront` / `LootCardRear`): the loot
+ `gfx` image with its value (`+n`), the 1418/1419 special text, the
+ enhancement level, and the owning character's class icon.
+-->
+<script lang="ts">
+ import type { LootCard as Card } from '$lib/protocol/types';
+ import { lootValue } from '$lib/game/cards/lootCard';
+ import { t } from '$lib/i18n';
+
+ let {
+ card,
+ revealed,
+ ownerName = '',
+ characterCount = 4,
+ scale = 1
+ }: {
+ card: Card;
+ revealed: boolean;
+ /** The owning character's class name (for the corner icon). */
+ ownerName?: string;
+ /** Party size (the value table depends on it). */
+ characterCount?: number;
+ scale?: number;
+ } = $props();
+
+ const width = 39 * scale;
+ const height = 58.6666 * scale;
+
+ const value = $derived(revealed ? lootValue(card, characterCount) : null);
+ const special = $derived(
+ revealed
+ ? card.gfx.includes('1418')
+ ? '1418'
+ : card.gfx.includes('1419')
+ ? '1419'
+ : ''
+ : ''
+ );
+ const showOwner = $derived(revealed && card.owner.length > 0);
+</script>
+
+<div class="lootcard" style="width: {width}px; height: {height}px">
+ <img
+ class="lootcard__bg"
+ src={revealed ? `/images/loot/${card.gfx}.png` : '/images/loot/back.png'}
+ alt={card.gfx}
+ draggable="false"
+ />
+ {#if value !== null}
+ <div class="lootcard__value" style="font-size: {30 * scale}px">+{value}</div>
+ {/if}
+ {#if special}
+ <div class="lootcard__value" style="font-size: {25 * scale}px">{special}</div>
+ {/if}
+ {#if revealed && card.enhanced > 0}
+ <div class="lootcard__enhanced" style="font-size: {9 * scale}px">
+ {t('enhancedLevel', { level: card.enhanced })}
+ </div>
+ {/if}
+ {#if showOwner}
+ <img
+ class="lootcard__owner"
+ src="/images/class-icons/{ownerName}.png"
+ alt={ownerName}
+ style="width: {15 * scale}px; height: {15 * scale}px"
+ draggable="false"
+ />
+ {/if}
+</div>
+
+<style>
+ .lootcard {
+ position: relative;
+ border-radius: 4px;
+ flex-shrink: 0;
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
+ }
+ .lootcard__bg {
+ position: absolute;
+ inset: 0;
+ width: 100%;
+ height: 100%;
+ border-radius: 4px;
+ object-fit: fill;
+ }
+ .lootcard__value {
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ font-family: system-ui, sans-serif;
+ font-weight: 700;
+ color: #fff;
+ text-shadow: 0.6px 0.6px 1px rgba(0, 0, 0, 0.87);
+ pointer-events: none;
+ }
+ .lootcard__enhanced {
+ position: absolute;
+ bottom: 5px;
+ left: 0;
+ right: 0;
+ text-align: center;
+ color: #fff;
+ text-shadow: 0.3px 0.3px 0.8px rgba(0, 0, 0, 0.87);
+ pointer-events: none;
+ }
+ .lootcard__owner {
+ position: absolute;
+ top: 2px;
+ right: 2px;
+ filter: brightness(0) invert(1);
+ }
+</style>
diff --git a/web/src/lib/ui/cards/ModifierCard.svelte b/web/src/lib/ui/cards/ModifierCard.svelte
new file mode 100644
index 0000000..e5e7bf7
--- /dev/null
+++ b/web/src/lib/ui/cards/ModifierCard.svelte
@@ -0,0 +1,124 @@
+<!--
+ One modifier (AMD) card (the reference `ModifierCardFront` /
+ `ModifierCardRear`): the `gfx` image with an optional corner marker
+ (imbue / faction / perk / class icon). `name` is the owning deck — the
+ shared party deck (""), "allies", or a character-class name. Pass
+ `perks` for a character deck so `P<n>` graphics resolve.
+-->
+<script lang="ts">
+ import type { ModifierCard as Card } from '$lib/protocol/types';
+ import {
+ extraGfxUrl,
+ gfxUrl,
+ hasExtra,
+ rearMarker
+ } from '$lib/game/cards/modifierCardGfx';
+
+ let {
+ card,
+ name,
+ revealed,
+ perks = null,
+ scale = 1
+ }: {
+ card: Card;
+ name: string;
+ revealed: boolean;
+ perks?: string[][] | null;
+ scale?: number;
+ } = $props();
+
+ const width = 58.6666 * scale;
+ const height = 39 * scale;
+
+ const frontGfx = $derived(gfxUrl(card, name, perks));
+ const frontExtra = $derived(extraGfxUrl(card, name));
+ const showExtra = $derived(hasExtra(card, name));
+ const rear = $derived(rearMarker(name));
+</script>
+
+<div
+ class="modcard"
+ style="width: {width}px; height: {height}px; --scale: {scale}"
+>
+ {#if revealed}
+ <img
+ class="modcard__bg"
+ src={frontGfx}
+ alt={card.gfx}
+ draggable="false"
+ />
+ {#if showExtra}
+ <img
+ class="modcard__marker-bg"
+ src="/images/attack/class-marker-background.png"
+ alt=""
+ draggable="false"
+ />
+ <img class="modcard__marker-icon" src={frontExtra} alt="" draggable="false" />
+ {/if}
+ {:else}
+ <img
+ class="modcard__bg"
+ src="/images/attack/back.png"
+ alt=""
+ draggable="false"
+ />
+ {#if rear.has}
+ <img
+ class="modcard__rear-bg"
+ src="/images/attack/class-marker-background.png"
+ alt=""
+ draggable="false"
+ />
+ <img class="modcard__rear-icon" src={rear.gfx} alt="" draggable="false" />
+ {/if}
+ {/if}
+</div>
+
+<style>
+ .modcard {
+ position: relative;
+ border-radius: 4px;
+ flex-shrink: 0;
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
+ }
+ .modcard__bg {
+ position: absolute;
+ inset: 0;
+ width: 100%;
+ height: 100%;
+ border-radius: 4px;
+ object-fit: fill;
+ }
+ .modcard__marker-bg {
+ position: absolute;
+ top: calc(26.5 * var(--scale) * 1px);
+ left: calc(3 * var(--scale) * 1px);
+ width: calc(10 * var(--scale) * 1px);
+ height: calc(10 * var(--scale) * 1px);
+ }
+ .modcard__marker-icon {
+ position: absolute;
+ top: calc(27.75 * var(--scale) * 1px);
+ left: calc(4.2 * var(--scale) * 1px);
+ width: calc(7.5 * var(--scale) * 1px);
+ height: calc(7.5 * var(--scale) * 1px);
+ filter: brightness(0) invert(1);
+ }
+ .modcard__rear-bg {
+ position: absolute;
+ top: calc(5.5 * var(--scale) * 1px);
+ left: calc(15.7 * var(--scale) * 1px);
+ width: calc(27 * var(--scale) * 1px);
+ height: calc(27 * var(--scale) * 1px);
+ }
+ .modcard__rear-icon {
+ position: absolute;
+ top: calc(9 * var(--scale) * 1px);
+ left: calc(19 * var(--scale) * 1px);
+ width: calc(20 * var(--scale) * 1px);
+ height: calc(20 * var(--scale) * 1px);
+ filter: brightness(0) invert(1);
+ }
+</style>
diff --git a/web/src/lib/ui/cards/MonsterAbilityCard.svelte b/web/src/lib/ui/cards/MonsterAbilityCard.svelte
new file mode 100644
index 0000000..5310874
--- /dev/null
+++ b/web/src/lib/ui/cards/MonsterAbilityCard.svelte
@@ -0,0 +1,157 @@
+<!--
+ A monster ability card (the reference `MonsterAbilityCardFront`): the card
+ back with title, initiative, card number, shuffle badge, positioned
+ graphics, and the ability lines rendered by {@link AbilityText} from the
+ `parseLines` tree.
+-->
+<script lang="ts">
+ import type { MonsterAbilityCard } from '$lib/protocol/types';
+ import type { StatMonster } from '$lib/game/line/statApplier';
+ import type { ColumnNode } from '$lib/game/line/types';
+ import { buildAbilityCardTree } from '$lib/game/line/buildAbility';
+ import { gt, gameTable } from '$lib/i18n/gameI18n';
+ import { isElement } from '$lib/game/line/tokens';
+ import AbilityText from './AbilityText.svelte';
+
+ let {
+ card,
+ stat,
+ fh = true,
+ flying = false,
+ scale = 1,
+ applyStats = true,
+ applyAll = false
+ }: {
+ card: MonsterAbilityCard;
+ stat: StatMonster | null;
+ fh?: boolean;
+ flying?: boolean;
+ scale?: number;
+ applyStats?: boolean;
+ applyAll?: boolean;
+ } = $props();
+
+ // The tree re-resolves when the in-game locale table changes.
+ const tree = $derived.by(() => {
+ void $gameTable;
+ return buildAbilityCardTree(card, stat, {
+ fh,
+ flying,
+ scale,
+ applyStats,
+ applyAll
+ }) as ColumnNode;
+ });
+
+ const width = 142.4 * scale;
+ const height = 94.4 * scale;
+
+ const initText = $derived(
+ card.initiative.toString().length === 1
+ ? `0${card.initiative}`
+ : card.initiative.toString()
+ );
+</script>
+
+<div
+ class="mac"
+ style="width: {width}px; height: {height}px; --scale: {scale}"
+>
+ <img
+ class="mac__bg"
+ src={fh ? '/images/psd/monsterAbility-front_fh.png' : '/images/psd/monsterAbility-front.png'}
+ alt=""
+ draggable="false"
+ />
+
+ {#each card.graphics.slice(0, 4) as g}
+ <img
+ class="mac__gfx"
+ src={`/images/abilities/${g.gfx}.png`}
+ alt=""
+ draggable="false"
+ style="left: {g.x * width}px; top: {g.y * height}px; transform: rotate({g.angle}deg) scale({g.scale * scale * (isElement(g.gfx) ? 0.264 : 0.44)}); transform-origin: top left"
+ />
+ {/each}
+
+ <div class="mac__title" style="font-size: {fh ? 10 * scale : 11.2 * scale}px">
+ {gt(card.title)}
+ </div>
+ <div class="mac__init" style="font-size: {fh ? 15 * scale : 16 * scale}px">
+ {initText}
+ </div>
+ <div class="mac__nr" style="font-size: {6.4 * scale}px">{card.nr}</div>
+
+ {#if card.shuffle}
+ <img class="mac__shuffle" src="/images/abilities/shuffle.png" alt="shuffle" draggable="false" style="height: {12.8 * scale}px" />
+ {/if}
+
+ <div class="mac__lines">
+ <AbilityText node={tree} {fh} {scale} />
+ </div>
+</div>
+
+<style>
+ .mac {
+ position: relative;
+ border-radius: 8px;
+ flex-shrink: 0;
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
+ }
+ .mac__bg {
+ position: absolute;
+ inset: 0;
+ width: 100%;
+ height: 100%;
+ border-radius: 8px;
+ object-fit: fill;
+ }
+ .mac__gfx {
+ position: absolute;
+ }
+ .mac__title {
+ position: absolute;
+ top: 2px;
+ left: 0;
+ right: 0;
+ text-align: center;
+ font-family: 'Markazi', 'Majalla', system-ui, sans-serif;
+ color: #fff;
+ text-shadow: 0.6px 0.6px 1px rgba(0, 0, 0, 0.87);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
+ .mac__init {
+ position: absolute;
+ left: 4px;
+ top: 12.8px;
+ font-family: 'Markazi', 'Majalla', system-ui, sans-serif;
+ color: #fff;
+ text-shadow: 0.6px 0.6px 1px rgba(0, 0, 0, 0.87);
+ }
+ .mac__nr {
+ position: absolute;
+ left: 4.8px;
+ bottom: 0.4px;
+ font-family: system-ui, sans-serif;
+ color: #fff;
+ text-shadow: 0.6px 0.6px 1px rgba(0, 0, 0, 0.87);
+ }
+ .mac__shuffle {
+ position: absolute;
+ right: 6px;
+ bottom: 3.2px;
+ }
+ .mac__lines {
+ position: absolute;
+ top: 11px;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ padding: 0 4px;
+ }
+</style>
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>