1
0
Fork 0
mirror of https://github.com/ldericher/fftcgtool synced 2025-01-15 15:02:59 +00:00

CardDB construction/loading

This commit is contained in:
Jörn-Michael Miehe 2021-09-01 20:14:56 +02:00
parent 6ae0e00c2c
commit 10526d34e9
3 changed files with 11 additions and 14 deletions

View file

@ -11,17 +11,15 @@ from .utils import CARDDB_FILE_NAME
class CardDB: class CardDB:
__instance: CardDB = None __instance: CardDB = None
__content: dict[Code, Card]
@classmethod def __new__(cls) -> CardDB:
def get(cls) -> CardDB: if CardDB.__instance is None:
if not CardDB.__instance: CardDB.__instance = object.__new__(cls)
CardDB.__instance = CardDB() CardDB.__instance.__content = {}
return CardDB.__instance return CardDB.__instance
def __init__(self):
self.__content: dict[Code, Card] = {}
def __getitem__(self, code: Code) -> Card: def __getitem__(self, code: Code) -> Card:
return self.__content[code] return self.__content[code]

View file

@ -18,7 +18,7 @@ class TTSDeck(Cards):
self.__description = description self.__description = description
# get cards from carddb # get cards from carddb
carddb = CardDB.get() carddb = CardDB()
self.extend([ self.extend([
carddb[code] carddb[code]
for code in codes for code in codes

11
main.py
View file

@ -10,19 +10,18 @@ OUT_DIR_NAME = "out" # name of output directory
def opus_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]: def opus_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]:
decks: list[fftcg.TTSDeck] = [] # load the current carddb
carddb = fftcg.CardDB()
carddb.load()
decks: list[fftcg.TTSDeck] = []
for opus_id in args.opus_ids: for opus_id in args.opus_ids:
# import an opus # import an opus
opus = fftcg.Opus(opus_id, args.language) opus = fftcg.Opus(opus_id, args.language)
book = fftcg.Book(opus, args.language, args.num_requests) book = fftcg.Book(opus, args.language, args.num_requests)
book.save() book.save()
# load the current carddb
carddb = fftcg.CardDB.get()
carddb.load()
carddb.update(opus) carddb.update(opus)
decks.extend(opus.elemental_decks) decks.extend(opus.elemental_decks)
# create elemental decks for opus # create elemental decks for opus
@ -31,7 +30,7 @@ def opus_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]:
def ffdecks_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]: def ffdecks_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]:
# load the current carddb # load the current carddb
carddb = fftcg.CardDB.get() carddb = fftcg.CardDB()
carddb.load() carddb.load()
decks: list[fftcg.TTSDeck] = [] decks: list[fftcg.TTSDeck] = []