diff --git a/fftcg/book.py b/fftcg/book.py index ab09f62..1962e2c 100644 --- a/fftcg/book.py +++ b/fftcg/book.py @@ -24,6 +24,10 @@ class Book: def __init__(self, cards, grid, resolution, language, num_threads): logger = logging.getLogger(__name__) + # sort cards by element, then alphabetically + cards.sort(key=lambda x: x.name) + cards.sort(key=lambda x: "Multi" if len(x.elements) > 1 else x.elements[0]) + # all card face URLs urls = [Book.__FACE_URL.format(card.code, language) for card in cards] # card back URL diff --git a/fftcg/card.py b/fftcg/card.py index 7d456a5..e4feb0e 100644 --- a/fftcg/card.py +++ b/fftcg/card.py @@ -56,6 +56,18 @@ class Card: def code(self): return f"{self.__opus}-{self.__serial}{self.__rarity}" + @property + def opus(self): + return self.__opus + + @property + def serial(self): + return int(self.__serial) + + @property + def rarity(self): + return self.__rarity + @property def name(self): return self.__name diff --git a/fftcg/opus.py b/fftcg/opus.py index e98dd7b..4802ac2 100644 --- a/fftcg/opus.py +++ b/fftcg/opus.py @@ -11,24 +11,29 @@ class Opus(Cards): if isinstance(opus_id, str) and opus_id.isnumeric(): roman_opus_id = roman.toRoman(int(opus_id)) - api_set = f"Opus {roman_opus_id.upper()}" + params_add = {"set": [f"Opus {roman_opus_id.upper()}"]} self.__number = str(opus_id) self.__name = f"opus_{opus_id}" elif opus_id == "chaos": - api_set = "Boss Deck Chaos" + params_add = {"set": ["Boss Deck Chaos"]} self.__number = "B" self.__name = "boss_deck_chaos" + elif opus_id == "promo": + params_add = {"rarity": ["pr"]} + self.__number = "PR" + self.__name = "promo" + else: - api_set = "?" + params_add = {"set": ["?"]} self.__number = "?" self.__name = "?" params = { "text": "", - "element": ["darkness"], - "set": [api_set], + # "element": ["darkness"], + **params_add } Cards.__init__(self, params) @@ -38,10 +43,9 @@ class Opus(Cards): if not card.code.startswith(self.__number + "-"): self.remove(card) - # sort every element alphabetically - self.sort(key=lambda x: x.code) - self.sort(key=lambda x: x.name) - self.sort(key=lambda x: "Multi" if len(x.elements) > 1 else x.elements[0]) + # sort cards by opus, then serial + self.sort(key=lambda x: x.serial) + self.sort(key=lambda x: x.opus) for card in self: logger.info(f"imported card {card}")