2021-08-03 00:22:00 +00:00
|
|
|
#!/usr/bin/env python3
|
2021-08-04 16:36:23 +00:00
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import os
|
2021-08-03 00:22:00 +00:00
|
|
|
|
2021-08-09 05:01:25 +00:00
|
|
|
import fftcg
|
2021-08-04 22:17:47 +00:00
|
|
|
|
2021-08-23 14:00:17 +00:00
|
|
|
# constants
|
|
|
|
OUT_DIR_NAME = "out" # name of output directory
|
|
|
|
|
2018-11-02 22:13:17 +00:00
|
|
|
|
2021-08-23 12:57:05 +00:00
|
|
|
def opus_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]:
|
2021-08-23 16:25:25 +00:00
|
|
|
decks: list[fftcg.TTSDeck] = []
|
2021-08-23 12:57:05 +00:00
|
|
|
|
2021-08-23 16:25:25 +00:00
|
|
|
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)
|
2021-08-23 12:57:05 +00:00
|
|
|
|
|
|
|
# create elemental decks for opus
|
2021-08-23 16:25:25 +00:00
|
|
|
return decks
|
2021-08-23 12:57:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
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)]
|
|
|
|
|
|
|
|
|
2021-08-09 02:03:24 +00:00
|
|
|
def main() -> None:
|
2021-08-04 22:17:47 +00:00
|
|
|
# set up CLI
|
2021-08-23 12:57:05 +00:00
|
|
|
|
|
|
|
# main parser
|
2021-08-04 16:36:23 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
2021-08-23 12:57:05 +00:00
|
|
|
prog="fftcgtool",
|
2021-08-09 04:18:56 +00:00
|
|
|
description="Imports FFTCG cards for TT-Sim.",
|
|
|
|
)
|
2018-11-02 22:13:17 +00:00
|
|
|
|
2021-08-24 15:29:12 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"-v", "--verbose",
|
|
|
|
help="increase output verbosity",
|
|
|
|
action="count",
|
|
|
|
)
|
|
|
|
|
2021-08-23 16:16:56 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"-l", "--language",
|
|
|
|
type=fftcg.Language,
|
|
|
|
default="en",
|
|
|
|
metavar="LANGUAGE",
|
|
|
|
help="lang",
|
|
|
|
)
|
|
|
|
|
2021-08-23 12:57:05 +00:00
|
|
|
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(
|
2021-08-23 16:25:25 +00:00
|
|
|
"opus_ids",
|
2021-08-23 12:57:05 +00:00
|
|
|
type=str,
|
2021-08-23 16:25:25 +00:00
|
|
|
nargs="+",
|
2021-08-04 22:54:15 +00:00
|
|
|
metavar="Opus_ID",
|
2021-08-23 16:25:25 +00:00
|
|
|
help="the Opuses to import",
|
2021-08-09 04:18:56 +00:00
|
|
|
)
|
2021-08-04 16:36:23 +00:00
|
|
|
|
2021-08-23 12:57:05 +00:00
|
|
|
opus_parser.add_argument(
|
|
|
|
"-n", "--num_requests",
|
2021-08-04 16:36:23 +00:00
|
|
|
type=int,
|
|
|
|
default=20,
|
|
|
|
metavar="COUNT",
|
2021-08-09 04:18:56 +00:00
|
|
|
help="maximum number of concurrent requests",
|
|
|
|
)
|
2021-08-04 16:36:23 +00:00
|
|
|
|
2021-08-23 12:57:05 +00:00
|
|
|
# "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",
|
|
|
|
)
|
2021-08-04 16:36:23 +00:00
|
|
|
|
2021-08-24 15:29:12 +00:00
|
|
|
# parse arguments
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2021-08-04 22:17:47 +00:00
|
|
|
# set up logging
|
2021-08-24 15:29:12 +00:00
|
|
|
if args.verbose is None:
|
|
|
|
args.verbose = logging.WARN
|
|
|
|
elif args.verbose == 1:
|
|
|
|
args.verbose = logging.INFO
|
|
|
|
else:
|
|
|
|
args.verbose = logging.DEBUG
|
|
|
|
|
2021-08-23 12:57:05 +00:00
|
|
|
logging.basicConfig(
|
2021-08-24 15:29:12 +00:00
|
|
|
level=args.verbose,
|
2021-08-23 12:57:05 +00:00
|
|
|
format="%(levelname)s: %(processName)s %(message)s",
|
|
|
|
)
|
2021-08-04 16:36:23 +00:00
|
|
|
|
2021-08-24 15:29:12 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
logger.debug(f"{args = }")
|
|
|
|
|
2021-08-04 16:36:23 +00:00
|
|
|
# output directory
|
2021-08-23 14:00:17 +00:00
|
|
|
if not os.path.exists(OUT_DIR_NAME):
|
|
|
|
os.mkdir(OUT_DIR_NAME)
|
|
|
|
|
|
|
|
os.chdir(OUT_DIR_NAME)
|
2021-08-04 16:36:23 +00:00
|
|
|
|
2021-08-23 12:57:05 +00:00
|
|
|
# call function based on args
|
|
|
|
for deck in args.func(args):
|
2021-08-18 15:38:58 +00:00
|
|
|
deck.save()
|
2021-08-04 22:17:47 +00:00
|
|
|
|
|
|
|
# bye
|
2021-08-24 15:29:12 +00:00
|
|
|
print("Done. Put the generated JSON files in your 'Saved Objects' Folder.")
|
|
|
|
print("Thanks for using fftcgtool!")
|
2021-08-04 01:39:19 +00:00
|
|
|
|
2018-11-02 22:13:17 +00:00
|
|
|
|
2021-08-09 04:18:56 +00:00
|
|
|
if __name__ == "__main__":
|
2021-08-03 21:41:25 +00:00
|
|
|
main()
|