From 10526d34e959cc55b041d45e0aa3c5215e1e67e0 Mon Sep 17 00:00:00 2001 From: LDericher <40151420+ldericher@users.noreply.github.com> Date: Wed, 1 Sep 2021 20:14:56 +0200 Subject: [PATCH] CardDB construction/loading --- fftcg/carddb.py | 12 +++++------- fftcg/ttsdeck.py | 2 +- main.py | 11 +++++------ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/fftcg/carddb.py b/fftcg/carddb.py index a6bee57..a0d0af9 100644 --- a/fftcg/carddb.py +++ b/fftcg/carddb.py @@ -11,17 +11,15 @@ from .utils import CARDDB_FILE_NAME class CardDB: __instance: CardDB = None + __content: dict[Code, Card] - @classmethod - def get(cls) -> CardDB: - if not CardDB.__instance: - CardDB.__instance = CardDB() + def __new__(cls) -> CardDB: + if CardDB.__instance is None: + CardDB.__instance = object.__new__(cls) + CardDB.__instance.__content = {} return CardDB.__instance - def __init__(self): - self.__content: dict[Code, Card] = {} - def __getitem__(self, code: Code) -> Card: return self.__content[code] diff --git a/fftcg/ttsdeck.py b/fftcg/ttsdeck.py index a0672b2..6963431 100644 --- a/fftcg/ttsdeck.py +++ b/fftcg/ttsdeck.py @@ -18,7 +18,7 @@ class TTSDeck(Cards): self.__description = description # get cards from carddb - carddb = CardDB.get() + carddb = CardDB() self.extend([ carddb[code] for code in codes diff --git a/main.py b/main.py index 5e191df..38a48df 100755 --- a/main.py +++ b/main.py @@ -10,19 +10,18 @@ OUT_DIR_NAME = "out" # name of output directory 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: # import an opus opus = fftcg.Opus(opus_id, args.language) book = fftcg.Book(opus, args.language, args.num_requests) book.save() - # load the current carddb - carddb = fftcg.CardDB.get() - carddb.load() carddb.update(opus) - decks.extend(opus.elemental_decks) # 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]: # load the current carddb - carddb = fftcg.CardDB.get() + carddb = fftcg.CardDB() carddb.load() decks: list[fftcg.TTSDeck] = []