diff options
Diffstat (limited to 'web/src/lib/ui/decks/AbilityCardSlot.svelte')
| -rw-r--r-- | web/src/lib/ui/decks/AbilityCardSlot.svelte | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/web/src/lib/ui/decks/AbilityCardSlot.svelte b/web/src/lib/ui/decks/AbilityCardSlot.svelte new file mode 100644 index 0000000..8b5250c --- /dev/null +++ b/web/src/lib/ui/decks/AbilityCardSlot.svelte @@ -0,0 +1,121 @@ +<!-- + One monster's ability card in its row (the reference + `MonsterAbilityCardWidget`): the front of the current (top discard) + card while the round is playing turns and the monster is active, + else the card back with the draw-pile size. Tap opens the deck + menu; double-tap (front only) zooms the card. +--> +<script lang="ts"> + import type { + GameState, + MonsterAbilityCard as AbilityCard, + MonsterAbilityState, + MonsterItem + } from '$lib/protocol/types'; + import type { CampaignData } from '$lib/data/gameData'; + import type { StatMonster } from '$lib/game/line/statApplier'; + import { statMonsterFor } from '$lib/game/line/buildAbility'; + import { isInactiveForRule } from '$lib/game/rules'; + import MonsterAbilityCard from '../cards/MonsterAbilityCard.svelte'; + import AbilityCardBack from '../cards/AbilityCardBack.svelte'; + + const ROW_CARD_SCALE = 0.72; + + let { + state, + item, + deck, + campaignData, + fh, + onOpen, + onZoom + }: { + state: GameState; + item: MonsterItem; + /** This monster's ability deck (matched by model deck name), if any. */ + deck: MonsterAbilityState | null; + campaignData: CampaignData | null; + fh: boolean; + onOpen: () => void; + onZoom: () => void; + } = $props(); + + const model = $derived( + campaignData?.monsters.find( + (m) => m.name === item.type || m.display === item.type + ) ?? null + ); + + const showFront = $derived( + state.roundState === 1 && + item.isActive && + !isInactiveForRule(state, item.type) && + deck != null && + deck.discardPile.length > 0 + ); + + const cardRef = $derived( + showFront && deck != null + ? deck.discardPile[deck.discardPile.length - 1] + : null + ); + const card = $derived.by((): AbilityCard | null => { + if (cardRef == null) return null; + const list = campaignData?.abilityDecks[cardRef.deck] ?? []; + return list.find((c) => c.nr === cardRef.nr) ?? null; + }); + + const stat = $derived.by((): StatMonster | null => { + if (model == null) return null; + return statMonsterFor( + model, + item.level, + item.monsterInstances.map((s) => s.type), + item.isActive + ); + }); + + function onKeydown(e: KeyboardEvent) { + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault(); + onOpen(); + } + } +</script> + +<div + class="slot" + role="button" + tabindex="0" + aria-label="ability cards" + onclick={onOpen} + ondblclick={() => { + if (showFront) onZoom(); + }} + onkeydown={onKeydown} +> + {#if showFront && card != null} + <MonsterAbilityCard + {card} + {stat} + {fh} + flying={model?.flying ?? false} + scale={ROW_CARD_SCALE} + applyStats={false} + /> + {:else} + <AbilityCardBack + {fh} + size={deck ? deck.drawPile.length : -1} + scale={ROW_CARD_SCALE} + /> + {/if} +</div> + +<style> + .slot { + flex-shrink: 0; + margin-left: 4px; + cursor: pointer; + } +</style> |
