Files
PythonLib/Tales_Exe.py

266 lines
6.8 KiB
Python
Raw Permalink Normal View History

2022-12-26 07:59:50 -05:00
import argparse
2023-05-19 10:19:16 -05:00
from pathlib import Path
2023-05-19 07:30:53 -05:00
2023-05-19 10:19:16 -05:00
from pythonlib.games import ToolsNDX, ToolsTOR
2022-12-26 07:59:50 -05:00
SCRIPT_VERSION = "0.0.3"
2023-05-19 07:30:53 -05:00
2022-12-26 07:59:50 -05:00
def get_arguments(argv=None):
# Init argument parser
parser = argparse.ArgumentParser()
parser.add_argument(
"-g",
"--game",
choices=["TOR", "NDX"],
required=True,
metavar="game",
help="Options: TOR, NDX",
)
parser.add_argument(
"-p",
"--project",
required=True,
type=Path,
metavar="project",
help="project.json file path",
)
2022-12-26 07:59:50 -05:00
sp = parser.add_subparsers(title="Available actions", required=False, dest="action")
# Extract commands
sp_extract = sp.add_parser(
"extract",
description="Extract the content of the files",
help="Extract the content of the files",
formatter_class=argparse.RawTextHelpFormatter,
)
sp_extract.add_argument(
"-ft",
"--file_type",
2024-09-24 12:48:26 -05:00
choices=["Iso", "Main", "Menu", "Story", "Minigame", "Skits"],
2022-12-26 07:59:50 -05:00
required=True,
metavar="file_type",
2024-09-24 12:48:26 -05:00
help="(Required) - Options: Iso, Init, Main, Menu, Story, Minigame, Skits",
2022-12-26 07:59:50 -05:00
)
sp_extract.add_argument(
"-i",
"--iso",
required=False,
default="../b-topndxj.iso",
metavar="iso",
help="(Optional) - Only for extract Iso command",
2022-12-26 07:59:50 -05:00
)
sp_extract.add_argument(
"-r",
"--replace",
required=False,
metavar="replace",
default=False,
help="(Optional) - Boolean to uses translations from the Repo to overwrite the one in the Data folder",
2022-12-26 07:59:50 -05:00
)
2023-10-08 07:20:16 -05:00
sp_extract.add_argument(
"--only-changed",
required=False,
action="store_true",
help="(Optional) - Insert only changed files not yet commited",
)
sp_extract.add_argument(
"--update-battle-subs",
required=False,
dest="update_subs",
action="store_true",
help="(Deprecated)",
)
sp_extract.add_argument(
"--update-subs",
required=False,
action="store_true",
help="(Optional) - Update Battle and Fmv Subs",
)
sp_extract.add_argument(
"--single-build",
required=False,
action="store_true",
help="(Optional) - Create just a single iso instead",
)
2022-12-26 07:59:50 -05:00
sp_insert = sp.add_parser(
"insert",
help="Take the new texts and recreate the files",
2022-12-26 07:59:50 -05:00
)
sp_insert.add_argument(
"-ft",
"--file_type",
2024-09-24 12:48:26 -05:00
choices=["Iso", "Main", "Menu", "Story", "Skits", "Minigame", "All", "Asm"],
2022-12-26 07:59:50 -05:00
required=True,
metavar="file_type",
2024-09-24 12:48:26 -05:00
help="(Required) - Options: Iso, Init, Main, Elf, Story, Skits, Minigame, All, Asm",
2022-12-26 07:59:50 -05:00
)
sp_insert.add_argument(
"-i",
"--iso",
required=False,
default="",
metavar="iso",
help="(Deprecated) - No longer in use for insertion",
)
2023-09-04 20:08:15 -05:00
sp_insert.add_argument(
"--with-proofreading",
required=False,
action="store_const",
const="Proofreading",
2023-09-04 20:08:15 -05:00
default="",
help="(Optional) - Insert lines in 'Proofreading' status",
)
sp_insert.add_argument(
"--with-editing",
required=False,
action="store_const",
const="Editing",
2023-09-04 20:08:15 -05:00
default="",
help="(Optional) - Insert lines in 'Editing' status",
)
sp_insert.add_argument(
"--with-problematic",
required=False,
action="store_const",
const="Problematic",
2023-09-04 20:08:15 -05:00
default="",
help="(Optional) - Insert lines in 'Problematic' status",
)
sp_insert.add_argument(
"--only-changed",
required=False,
action="store_true",
help="(Optional) - Insert only changed files not yet commited",
)
2024-11-30 09:33:23 -05:00
sp_insert.add_argument(
"--update-battle-subs",
required=False,
2024-12-05 19:54:30 -05:00
dest="update_subs",
action="store_true",
2024-12-05 19:54:30 -05:00
help="(Deprecated)",
)
sp_insert.add_argument(
"--update-subs",
required=False,
action="store_true",
help="(Optional) - Update Battle and Fmv Subs",
)
2024-11-30 09:33:23 -05:00
sp_insert.add_argument(
"--single-build",
required=False,
action="store_true",
help="(Optional) - Create just a single iso instead",
)
2023-09-04 20:08:15 -05:00
2022-12-26 07:59:50 -05:00
args = parser.parse_args()
return args
2023-05-19 07:30:53 -05:00
def getTalesInstance(args, game_name):
2023-05-19 07:30:53 -05:00
2022-12-26 07:59:50 -05:00
if game_name == "TOR":
2023-09-04 20:08:15 -05:00
if args.action == "insert":
insert_mask = [
args.with_proofreading,
args.with_editing,
args.with_problematic,
]
2023-09-04 20:08:15 -05:00
else:
2023-09-05 06:06:45 -05:00
insert_mask = []
talesInstance = ToolsTOR.ToolsTOR(
args.project.resolve(), insert_mask, args.only_changed
)
2024-11-30 09:33:23 -05:00
talesInstance.single_build = args.single_build
2024-12-05 19:54:30 -05:00
talesInstance.make_btl_subs = args.update_subs
2022-12-26 07:59:50 -05:00
elif game_name == "NDX":
talesInstance = ToolsNDX.ToolsNDX("TBL_All.json")
2023-05-19 07:30:53 -05:00
else:
raise ValueError("Unkown game name")
2022-12-26 07:59:50 -05:00
return talesInstance
2023-05-19 07:30:53 -05:00
2022-12-26 07:59:50 -05:00
if __name__ == "__main__":
args = get_arguments()
game_name = args.game
tales_instance = getTalesInstance(args, game_name)
2022-12-26 07:59:50 -05:00
if args.action == "insert":
2024-12-05 19:54:30 -05:00
if args.update_subs:
tales_instance.create_fmv_subs()
tales_instance.create_btl_subs()
2022-12-26 07:59:50 -05:00
if args.file_type == "Main":
2023-05-19 10:19:16 -05:00
tales_instance.pack_main_archive()
2022-12-26 07:59:50 -05:00
elif args.file_type == "Story":
2023-05-22 13:02:26 -05:00
tales_instance.pack_all_story()
2024-09-24 12:48:26 -05:00
elif args.file_type == "Minigame":
tales_instance.pack_all_minigame()
2022-12-26 07:59:50 -05:00
2024-01-31 18:15:39 -05:00
elif args.file_type == "Iso":
tales_instance.make_iso()
2022-12-26 07:59:50 -05:00
elif args.file_type == "Skits":
2023-05-22 13:02:26 -05:00
tales_instance.pack_all_skits()
2022-12-26 07:59:50 -05:00
2023-08-08 00:51:19 -05:00
elif args.file_type == "Menu":
tales_instance.pack_all_menu()
2023-08-08 00:51:19 -05:00
elif args.file_type == "Asm":
tales_instance.patch_binaries()
elif args.file_type == "All":
tales_instance.pack_all_story()
tales_instance.pack_all_skits()
tales_instance.pack_all_menu()
2024-09-24 12:48:26 -05:00
tales_instance.pack_all_minigame()
2023-08-08 00:51:19 -05:00
tales_instance.patch_binaries()
tales_instance.make_iso()
2023-08-08 00:51:19 -05:00
2022-12-26 07:59:50 -05:00
if args.action == "extract":
2023-05-19 07:30:53 -05:00
2022-12-26 07:59:50 -05:00
if args.file_type == "Iso":
2023-05-19 10:19:16 -05:00
tales_instance.extract_Iso(Path(args.iso))
tales_instance.extract_main_archive()
2022-12-26 07:59:50 -05:00
if args.file_type == "Main":
2023-05-19 10:19:16 -05:00
tales_instance.extract_main_archive()
2022-12-26 07:59:50 -05:00
if args.file_type == "Menu":
2023-05-27 17:10:21 -05:00
tales_instance.extract_all_menu()
2023-05-19 07:30:53 -05:00
2022-12-26 07:59:50 -05:00
if args.file_type == "Story":
2023-05-19 10:19:16 -05:00
tales_instance.extract_all_story()
2022-12-26 07:59:50 -05:00
2024-09-24 12:48:26 -05:00
if args.file_type == "Minigame":
tales_instance.extract_all_minigame()
2022-12-26 07:59:50 -05:00
if args.file_type == "Skits":
2023-05-19 10:19:16 -05:00
tales_instance.extract_all_skits(args.replace)