diff --git a/fftcg/__init__.py b/fftcg/__init__.py index 51f0407..c148d3c 100644 --- a/fftcg/__init__.py +++ b/fftcg/__init__.py @@ -2,5 +2,6 @@ from .book import Book from .card import Card from .carddb import CardDB from .opus import Opus +from .ttsdeck import TTSDeck -__all__ = ["Book", "Opus", "Card", "CardDB"] +__all__ = ["Book", "Card", "CardDB", "Opus", "TTSDeck"] diff --git a/main.py b/main.py index 27ea821..30c9ee5 100755 --- a/main.py +++ b/main.py @@ -6,41 +6,10 @@ import os import fftcg -def main() -> None: - # set up CLI - parser = argparse.ArgumentParser( - description="Imports FFTCG cards for TT-Sim.", - ) - - parser.add_argument( - "opus_id", - default="promo", - metavar="Opus_ID", - nargs="?", - help="the Opus to import", - ) - - parser.add_argument( - "-n", "--num_threads", - type=int, - default=20, - metavar="COUNT", - help="maximum number of concurrent requests", - ) - - args = parser.parse_args() - - # set up logging - logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(processName)s %(message)s") - - # output directory - if not os.path.exists("out"): - os.mkdir("out") - os.chdir("out") - - # main program +def opus_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]: + # import an opus opus = fftcg.Opus(args.opus_id) - book = fftcg.Book(opus, "eg", args.num_threads) + book = fftcg.Book(opus, "eg", args.num_requests) book.save() # load the current carddb @@ -48,7 +17,90 @@ def main() -> None: carddb.load() # create elemental decks for opus - for deck in opus.elemental_decks: + return opus.elemental_decks + + +def ffdecks_deck(args: argparse.Namespace) -> list[fftcg.TTSDeck]: + # load the current carddb + carddb = fftcg.CardDB.get() + carddb.load() + + # import a deck + return [fftcg.TTSDeck.from_ffdecks_deck(args.deck_id)] + + +def main() -> None: + # set up CLI + + # main parser + parser = argparse.ArgumentParser( + prog="fftcgtool", + description="Imports FFTCG cards for TT-Sim.", + ) + + subparsers = parser.add_subparsers( + description="Import either an Opus to extend the mod, or import a deck to play right away.", + dest="subcommand", + help="valid subcommands", + required=True, + ) + + # "opus" subcommand + opus_parser = subparsers.add_parser( + "opus", + description="Imports an Opus from the square API and creates its elemental decks as JSON files.", + ) + + opus_parser.set_defaults( + func=opus_decks + ) + + opus_parser.add_argument( + "opus_id", + type=str, + metavar="Opus_ID", + help="the Opus to import", + ) + + opus_parser.add_argument( + "-n", "--num_requests", + type=int, + default=20, + metavar="COUNT", + help="maximum number of concurrent requests", + ) + + # "deck" subcommand + deck_parser = subparsers.add_parser( + "deck", + description="Imports a Deck from the ffdecks.com API and creates it as a JSON file.", + ) + + deck_parser.set_defaults( + func=ffdecks_deck + ) + + deck_parser.add_argument( + "deck_id", + type=str, + metavar="Deck_ID", + help="the Deck to import", + ) + + # set up logging + logging.basicConfig( + level=logging.INFO, + format="%(levelname)s: %(processName)s %(message)s", + ) + + # output directory + if not os.path.exists("out"): + os.mkdir("out") + os.chdir("out") + + # call function based on args + args = parser.parse_args() + for deck in args.func(args): deck.save() # bye