mirror of
https://github.com/ldericher/fftcgtool
synced 2025-01-15 15:02:59 +00:00
56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import re
|
|
|
|
|
|
class Code:
|
|
__RE_NUM = re.compile(r"([0-9]+)-([0-9]+)([CRHLS]?)")
|
|
__RE_PROMO = re.compile(r"(PR)-([0-9]+)")
|
|
__RE_BOSS = re.compile(r"(B)-([0-9]+)")
|
|
|
|
def __init__(self, code: str):
|
|
if code[0].isnumeric():
|
|
# card code starts with a number
|
|
self.__opus, self.__serial, self.__rarity = \
|
|
Code.__RE_NUM.match(code).groups()
|
|
|
|
elif code.startswith("PR"):
|
|
# card code starts with "PR"
|
|
self.__opus, self.__serial = \
|
|
Code.__RE_PROMO.match(code).groups()
|
|
self.__rarity = ""
|
|
|
|
elif code.startswith("B"):
|
|
# card code starts with "B"
|
|
self.__opus, self.__serial = \
|
|
Code.__RE_BOSS.match(code).groups()
|
|
self.__rarity = ""
|
|
|
|
else:
|
|
# card code not recognized
|
|
self.__opus, self.__serial, self.__rarity = \
|
|
"?", "???", "?"
|
|
|
|
def __str__(self) -> str:
|
|
return f"{self.__opus}-{self.__serial}"
|
|
|
|
def __repr__(self) -> str:
|
|
return f"Code(\"{self.__opus}-{self.__serial}{self.__rarity}\")"
|
|
|
|
def __hash__(self) -> hash:
|
|
return hash(str(self))
|
|
|
|
def __eq__(self, other: Code):
|
|
return str(self) == str(other)
|
|
|
|
@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
|