1
0
Fork 0
mirror of https://github.com/ldericher/fftcgtool synced 2025-01-15 23:03:00 +00:00
fftcgtool/fftcg/card.py

82 lines
2.2 KiB
Python
Raw Normal View History

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