From e211e3697df98f0f9dafb62931e6bfa906e88da3 Mon Sep 17 00:00:00 2001 From: LDericher <40151420+ldericher@users.noreply.github.com> Date: Sun, 12 Dec 2021 03:06:04 +0100 Subject: [PATCH] Fixes for new crystal mechanic & cards --- fftcgtool/card.py | 45 ++++++++++++++++++++++++++++++++------------- fftcgtool/code.py | 2 +- fftcgtool/opus.py | 16 +++++++++------- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/fftcgtool/card.py b/fftcgtool/card.py index 9f3affb..84b83b2 100644 --- a/fftcgtool/card.py +++ b/fftcgtool/card.py @@ -17,11 +17,11 @@ class CardContent: _ELEMENTS_JAP = [ - "火", "氷", "風", "土", "雷", "水", "光", "闇" + "火", "氷", "風", "土", "雷", "水", "光", "闇", ] _ELEMENTS_ENG = [ - "Fire", "Ice", "Wind", "Earth", "Lightning", "Water", "Light", "Darkness" + "Fire", "Ice", "Wind", "Earth", "Lightning", "Water", "Light", "Darkness", ] _ELEMENTS_MAP = { @@ -49,6 +49,8 @@ def _load_text(language: Language, data: dict) -> str: text = text.replace("《S》", encircle_symbol("S", False)) # place elemental cost symbols text = re.sub(rf"《([{''.join(_ELEMENTS_JAP)}])》", _sub_elements, text, flags=re.UNICODE) + # place crystal symbols + text = text.replace("《C》", "⟠") # place dull symbols text = text.replace("《ダル》", "[⤵]") # relocate misplaced line break markers @@ -93,20 +95,37 @@ class Card: ) else: - return cls( - code=Code(data["Code"]), - elements=[ - _ELEMENTS_MAP[element] - for element in data["Element"].split("/") - ], - content={ + code = Code(data["Code"]) + + if code.opus == "C": + elements = ["Crystal"] + content = { language: CardContent( - _load_name(language, data), - _load_text(language, data), - "" + name="⟠", + text="", + face="", ) for language in API_LANGS - }, + } + + else: + elements = [ + _ELEMENTS_MAP[element] + for element in data["Element"].split("/") + ] + content = { + language: CardContent( + name=_load_name(language, data), + text=_load_text(language, data), + face="", + ) + for language in API_LANGS + } + + return cls( + code=code, + elements=elements, + content=content, ) def __repr__(self) -> str: diff --git a/fftcgtool/code.py b/fftcgtool/code.py index 2fe6957..5100c01 100644 --- a/fftcgtool/code.py +++ b/fftcgtool/code.py @@ -11,7 +11,7 @@ class Code: rarity: str = field(init=False, compare=False) code_init: InitVar[str] = field(default="") - __RE = re.compile(r"([1-9][0-9]*|PR|B)-([0-9]+)([CRHLS]?)", flags=re.UNICODE) + __RE = re.compile(r"([1-9][0-9]*|PR|B|C)-([0-9]+)([CRHLS]?)", flags=re.UNICODE) def __post_init__(self, code_init: str): match = Code.__RE.match(code_init) diff --git a/fftcgtool/opus.py b/fftcgtool/opus.py index 8221d40..c3eb852 100644 --- a/fftcgtool/opus.py +++ b/fftcgtool/opus.py @@ -56,17 +56,19 @@ class Opus(Cards): # get cards from square api req = requests.post(Opus.__SQUARE_API_URL, json=params) carddb = CardDB() - cards = [ + cards = ( Card.from_square_api_data(card_data) for card_data in req.json()["cards"] + ) + + cards = [ + card + for card in cards + if card.code.opus == self.__number or not card.code.opus.isnumeric() ] # remove reprints - super().__init__(name, [ - card - for card in cards - if card.code.opus == self.__number - ]) + super().__init__(name, cards) # sort cards by opus, then serial self.sort(key=lambda x: x.code.serial) @@ -114,7 +116,7 @@ class Opus(Cards): # light/darkness elemental deck "Light-Darkness": lambda card: card.elements == ["Light"] or card.elements == ["Darkness"], # multi element deck - "Multi": lambda card: len(card.elements) > 1, + "Multi": lambda card: "Crystal" in card.elements or len(card.elements) > 1, } # sort cards by element, then alphabetically