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-04 22:40:32 +00:00
|
|
|
def __init__(self, data: dict, 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
|
|
|
|
|
|
|
def __str__(self):
|
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
|
|
|
|
def code(self):
|
2021-08-02 23:55:12 +00:00
|
|
|
return f"{self.__opus}-{self.__serial}{self.__rarity}"
|
2021-08-04 01:39:19 +00:00
|
|
|
|
2021-08-04 22:33:18 +00:00
|
|
|
@property
|
|
|
|
def opus(self):
|
|
|
|
return self.__opus
|
|
|
|
|
|
|
|
@property
|
|
|
|
def serial(self):
|
|
|
|
return int(self.__serial)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def rarity(self):
|
|
|
|
return self.__rarity
|
|
|
|
|
2021-08-04 16:36:23 +00:00
|
|
|
@property
|
|
|
|
def name(self):
|
2021-08-04 01:39:19 +00:00
|
|
|
return self.__name
|
|
|
|
|
2021-08-04 16:36:23 +00:00
|
|
|
@property
|
|
|
|
def text(self):
|
2021-08-04 01:39:19 +00:00
|
|
|
return self.__text
|
|
|
|
|
2021-08-04 16:36:23 +00:00
|
|
|
@property
|
|
|
|
def elements(self):
|
2021-08-04 01:39:19 +00:00
|
|
|
return self.__elements
|