From b17fa63d50671c613e2e04a39507316f450e5282 Mon Sep 17 00:00:00 2001 From: Garrett Mills Date: Tue, 10 Nov 2026 20:19:33 -0600 Subject: [PATCH] Decks: leave tokens and other non-deck pieces out of the card count Tokens, emblems, dungeons, planes/phenomena, schemes, vanguards, conspiracies, Theros heroes, stickers, attractions, contraptions, the TMNT bosses/events, and helper "Card"s no longer count toward a deck's size, composition stats, or legality checks. They still count toward cost and can stay in the deck. Closes #33 --- src/deckAnalysis.ts | 54 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/src/deckAnalysis.ts b/src/deckAnalysis.ts index 746553d..19e8819 100644 --- a/src/deckAnalysis.ts +++ b/src/deckAnalysis.ts @@ -10,6 +10,42 @@ export const shortBy = (e: DeckEntry) => Math.max(0, e.quantity - e.quantity_own * decks claim them. */ export const claimedElsewhere = (e: DeckEntry) => Math.max(0, Math.min(e.quantity, e.quantity_owned) - e.quantity_spare); +/** Card types of game pieces that live outside the main deck: tokens and + * emblems, dungeons, Planechase planes, Archenemy schemes, Vanguard, + * Conspiracy draft cards, Theros hero cards, Unfinity sticker sheets, the TMNT + * co-op bosses and events, and the theme/minigame/helper "Card"s. */ +const NON_DECK_TYPES = new Set([ + "Token", + "Emblem", + "Dungeon", + "Plane", + "Phenomenon", + "Scheme", + "Vanguard", + "Conspiracy", + "Hero", + "Stickers", + "Boss", + "Event", + "Card", +]); + +/** Subtypes of cards that go in their own side deck rather than the main one. */ +const NON_DECK_SUBTYPES = new Set(["Attraction", "Contraption"]); + +/** Whether a card is part of the deck proper — false for tokens, emblems, and + * the other non-deck pieces above, which a deck can hold (to keep them with + * it) but which don't count toward its size or deck-building rules. */ +export function isDeckCard(e: DeckEntry): boolean { + return !e.type_line.split(" // ").some((face) => { + const [types, subtypes = ""] = face.split("—"); + return ( + types.split(/\s+/).some((t) => NON_DECK_TYPES.has(t)) || + subtypes.split(/\s+/).some((t) => NON_DECK_SUBTYPES.has(t)) + ); + }); +} + export interface DeckStats { totalCards: number; uniqueCards: number; @@ -38,12 +74,12 @@ export interface DeckStats { /** * Deck composition stats, excluding the commander (shown separately in its - * own hero display) and the maybeboard (cards under consideration, not - * actually part of the deck) — matches the usual "99 + commander" framing + * own hero display), the maybeboard (cards under consideration, not + * actually part of the deck), and tokens and other non-deck pieces — matches the usual "99 + commander" framing * even for non-Commander decks, where it's just "everything but those". */ export function computeDeckStats(contents: DeckEntry[]): DeckStats { - const cards = contents.filter((e) => !e.is_commander && !e.is_maybeboard); + const cards = contents.filter((e) => !e.is_commander && !e.is_maybeboard && isDeckCard(e)); const totalCards = cards.reduce((sum, e) => sum + e.quantity, 0); const lands = cards.filter((e) => e.type_line.includes("Land")); const nonlands = cards.filter((e) => !e.type_line.includes("Land")); @@ -284,7 +320,7 @@ export function computeDeckLegality(deck: Deck | null | undefined, contents: Dec } const issues: LegalityIssue[] = []; - const cards = contents.filter((e) => !e.is_maybeboard); + const cards = contents.filter((e) => !e.is_maybeboard && isDeckCard(e)); if (COMMANDER_FORMATS.includes(deck.format)) { // Brawl (Scryfall's `brawl` legality key = paper/Historic Brawl) is @@ -414,7 +450,8 @@ export interface DeckSummary { commanders: DeckEntry[]; /** WUBRG mask: the commanders' identity, else the whole mainboard's. */ colors: number; - /** Mainboard copies, commander included. */ + /** Mainboard copies, commander included, tokens and other non-deck + * pieces not. */ size: number; /** The size the format calls for (a minimum for 60-card formats), or null * when there's no format to measure against. */ @@ -452,9 +489,10 @@ export function summarizeDeck(deck: Deck, contents: DeckEntry[]): DeckSummary { const main = contents.filter((e) => !e.is_maybeboard); const isPrimary = (e: DeckEntry) => Number(e.oracle_id === deck.commander_oracle_id); const commanders = main.filter((e) => e.is_commander).sort((a, b) => isPrimary(b) - isPrimary(a)); - const colorSource = commanders.length ? commanders : main; - const size = main.reduce((n, e) => n + e.quantity, 0); - const ownedCopies = main.reduce((n, e) => n + Math.min(e.quantity, e.quantity_owned), 0); + const deckCards = main.filter(isDeckCard); + const colorSource = commanders.length ? commanders : deckCards; + const size = deckCards.reduce((n, e) => n + e.quantity, 0); + const ownedCopies = deckCards.reduce((n, e) => n + Math.min(e.quantity, e.quantity_owned), 0); const target = COMMANDER_FORMATS.includes(deck.format) ? COMMANDER_DECK_SIZE : deck.format && deck.format !== "Other"