33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
|
from collections import defaultdict
|
||
|
from collections.abc import Iterator
|
||
|
|
||
|
from arkhamdb import ArkhamDBCard, ArkhamDBDeck
|
||
|
|
||
|
|
||
|
class Validator:
|
||
|
cards_by_code: dict[str, ArkhamDBCard]
|
||
|
|
||
|
def __init__(self, cards: list[ArkhamDBCard]) -> None:
|
||
|
cards: list[ArkhamDBCard]
|
||
|
self.cards_by_code = {card["code"]: card for card in cards}
|
||
|
|
||
|
def validate(self, decks: list[ArkhamDBDeck]) -> Iterator[str]:
|
||
|
card_total_counts = defaultdict(lambda: 0)
|
||
|
for deck in decks:
|
||
|
for code, count in deck["slots"].items():
|
||
|
card_total_counts[code] += count
|
||
|
|
||
|
for code, count in card_total_counts.items():
|
||
|
try:
|
||
|
card = self.cards_by_code[code]
|
||
|
quantity = card["quantity"]
|
||
|
# assume two copies of the core set
|
||
|
if card["pack_code"] == "core":
|
||
|
quantity = quantity * 2
|
||
|
|
||
|
if count > quantity:
|
||
|
in_decks = [deck["id"] for deck in decks if code in deck["slots"]]
|
||
|
yield f"Too many copies of {card['name']}! ({count} > {quantity}), in decks {in_decks}"
|
||
|
except KeyError:
|
||
|
yield f'Did not find card with code "{code}"'
|