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

subcommands

This commit is contained in:
Jörn-Michael Miehe 2021-08-23 14:57:05 +02:00
parent f7b9573998
commit ab3e9deb7b
2 changed files with 89 additions and 36 deletions

View file

@ -2,5 +2,6 @@ from .book import Book
from .card import Card from .card import Card
from .carddb import CardDB from .carddb import CardDB
from .opus import Opus from .opus import Opus
from .ttsdeck import TTSDeck
__all__ = ["Book", "Opus", "Card", "CardDB"] __all__ = ["Book", "Card", "CardDB", "Opus", "TTSDeck"]

122
main.py
View file

@ -6,41 +6,10 @@ import os
import fftcg import fftcg
def main() -> None: def opus_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]:
# set up CLI # import an opus
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
opus = fftcg.Opus(args.opus_id) opus = fftcg.Opus(args.opus_id)
book = fftcg.Book(opus, "eg", args.num_threads) book = fftcg.Book(opus, "eg", args.num_requests)
book.save() book.save()
# load the current carddb # load the current carddb
@ -48,7 +17,90 @@ def main() -> None:
carddb.load() carddb.load()
# create elemental decks for opus # 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() deck.save()
# bye # bye