1
0
Fork 0
mirror of https://github.com/ldericher/fftcgtool synced 2025-01-15 23:03:00 +00:00
fftcgtool/fftcg/card.py
2021-08-09 06:18:56 +02:00

81 lines
2.2 KiB
Python

import re
class Card:
__ELEMENTS_MAP = {
"": "Fire",
"": "Ice",
"": "Wind",
"": "Earth",
"": "Lightning",
"": "Water",
"": "Light",
"": "Darkness"
}
def __init__(self, data: dict[str, any], language: str = "EN"):
if not data:
self.__opus = "0"
self.__serial = "000"
self.__rarity = "X"
self.__elements = None
self.__text = None
else:
if str(data["Code"])[0].isnumeric():
# card code starts with a number
self.__opus, self.__serial, self.__rarity = \
re.match(r"([0-9]+)-([0-9]+)([CRHLS])", data["Code"]).groups()
elif str(data["Code"]).startswith("PR"):
# card code starts with "PR"
self.__opus, self.__serial = \
re.match(r"(PR)-([0-9]+)", data["Code"]).groups()
self.__rarity = ""
elif str(data["Code"]).startswith("B"):
# card code starts with "B"
self.__opus, self.__serial = \
re.match(r"(B)-([0-9]+)", data["Code"]).groups()
self.__rarity = ""
else:
# card code not recognized
self.__opus, self.__serial, self.__rarity = \
"?", "???", "?"
self.__elements = [Card.__ELEMENTS_MAP[element] for element in data["Element"].split("/")]
self.__name = data[f"Name_{language}"]
self.__text = data[f"Text_{language}"]
def __str__(self) -> str:
return f"'{self.__name}' ({'/'.join(self.__elements)}, {self.code})"
# 6-048C
@property
def code(self) -> str:
return f"{self.__opus}-{self.__serial}{self.__rarity}"
@property
def opus(self) -> str:
return self.__opus
@property
def serial(self) -> int:
return int(self.__serial)
@property
def rarity(self) -> str:
return self.__rarity
@property
def name(self) -> str:
return self.__name
@property
def text(self) -> str:
return self.__text
@property
def elements(self) -> list[str]:
return self.__elements