/** * Modifier (AMD) deck view helpers (Phase 4 ยง6(d)): the pure read-only * derivations the deck widget and its menu compute from the wire deck โ€” * the reference `ModifierDeck` accessors the header/view-model used. */ import type { ModifierCard, ModifierDeck } from '$lib/protocol/types'; /** The draw pile, top-first (the reference reverses `drawPileContents`). */ export function drawPileTopFirst(deck: ModifierDeck): ModifierCard[] { return [...deck.drawPile].reverse(); } /** The discard pile, bottom-first (draw order). */ export function discardPile(deck: ModifierDeck): ModifierCard[] { return deck.discardPile; } /** Whether [gfx] is in the draw or discard pile (the reference `hasCard`). */ export function deckHasCard(deck: ModifierDeck, gfx: string): boolean { return ( deck.drawPile.some((c) => c.gfx === gfx) || deck.discardPile.some((c) => c.gfx === gfx) ); } /** A `-1` card is available (in the draw or discard pile). */ export function deckHasMinus1(deck: ModifierDeck): boolean { return deckHasCard(deck, 'minus1'); } /** * The `-2` is "not removed" (the reference `hasMinus2` is true when the * removed pile has no `minus2` โ€” i.e. the card can still be removed). */ export function deckMinus2Present(deck: ModifierDeck): boolean { return !deck.removedPile.some((c) => c.gfx === 'minus2'); } /** A `+0` card is in the deck. */ export function deckHasPlus0(deck: ModifierDeck): boolean { return deckHasCard(deck, 'plus0'); } /** The removable-counter total for [gfx] (0 when unset). */ export function removableTotal(deck: ModifierDeck, gfx: string): number { return deck.removables[gfx] ?? 0; } /** The top `count` draw-pile cards (top-first) are revealed. */ export function revealedCards( deck: ModifierDeck, count: number ): ModifierCard[] { const reversed = drawPileTopFirst(deck); return reversed.slice(0, Math.max(0, Math.min(count, reversed.length))); } /** * The Gloomhaven 2nd Edition faction cards (the reference * `GameMethods.getFactionCards`): four addable cards per faction, or empty * for an unknown faction. */ export function factionCards(faction: string): string[] { if (faction === 'Demons') { return [ 'Demons-perks/plus1any', 'Demons-perks/plus1retaliate1flip', 'Demons-perks/plus0wardallyflip', 'Demons-perks/unique/fuck3' ]; } if (faction === 'Merchant-Guild') { return [ 'Merchant-Guild-perks/plus1curse', 'Merchant-Guild-perks/plus1wound', 'Merchant-Guild-perks/plus0heal2flip', 'Merchant-Guild-perks/unique/fuck2' ]; } if (faction === 'Military') { return [ 'Military-perks/plus1strengthenally', 'Military-perks/plus1shield1flip', 'Military-perks/plus1push2flip', 'Military-perks/unique/fuck1' ]; } return []; } /** * Whether [gfx] is in any character's personal deck (the reference * `GameMethods.isCardInAnyCharacterDeck`) โ€” the faction menu grays out * cards another character already has. */ export function factionCardInAnyCharacterDeck( deckNames: { name: string; deck: ModifierDeck }[], gfx: string ): boolean { return deckNames.some(({ deck }) => deck.drawPile.some((c) => c.gfx === gfx) || deck.discardPile.some((c) => c.gfx === gfx) ); } /** The sanctuary/party-card flag on a deck (gfx prefix, the reference `hasCSSanctuary`/`hasPartyCard`). */ export function deckHasSanctuaryCard(deck: ModifierDeck): boolean { return deckPileHasPrefix(deck, 'sanctuary'); } export function deckHasPartyCard(deck: ModifierDeck): boolean { return deckPileHasPrefix(deck, 'party'); } function deckPileHasPrefix(deck: ModifierDeck, prefix: string): boolean { return ( deck.drawPile.some((c) => c.gfx.startsWith(prefix)) || deck.discardPile.some((c) => c.gfx.startsWith(prefix)) ); }