mirror of
https://github.com/ldericher/fftcgtool
synced 2025-01-15 15:02:59 +00:00
CardDB construction/loading
This commit is contained in:
parent
6ae0e00c2c
commit
10526d34e9
3 changed files with 11 additions and 14 deletions
|
@ -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]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
11
main.py
11
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] = []
|
||||
|
|
Loading…
Reference in a new issue