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

126 lines
2.8 KiB
Python
Raw Normal View History

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-23 14:00:17 +00:00
# constants
OUT_DIR_NAME = "out" # name of output directory
2021-08-23 12:57:05 +00:00
def opus_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]:
# import an opus
2021-08-23 16:16:56 +00:00
opus = fftcg.Opus(args.opus_id, args.language)
book = fftcg.Book(opus, args.language, args.num_requests)
2021-08-23 12:57:05 +00:00
book.save()
# load the current carddb
carddb = fftcg.CardDB.get()
carddb.load()
2021-08-23 14:46:53 +00:00
carddb.update(opus)
2021-08-23 12:57:05 +00:00
# create elemental decks for opus
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)]
2021-08-09 02:03:24 +00:00
def main() -> None:
# 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.",
)
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-09 04:18:56 +00:00
"opus_id",
2021-08-23 12:57:05 +00:00
type=str,
2021-08-04 22:54:15 +00:00
metavar="Opus_ID",
2021-08-09 04:18:56 +00:00
help="the Opus to import",
)
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
# set up logging
2021-08-23 12:57:05 +00:00
logging.basicConfig(
level=logging.INFO,
format="%(levelname)s: %(processName)s %(message)s",
)
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
args = parser.parse_args()
for deck in args.func(args):
2021-08-18 15:38:58 +00:00
deck.save()
# bye
logging.info("Done. Put the generated JSON files in your 'Saved Objects' Folder.")
logging.info("Thanks for using fftcgtool!")
2021-08-04 01:39:19 +00:00
2021-08-09 04:18:56 +00:00
if __name__ == "__main__":
2021-08-03 21:41:25 +00:00
main()