Files
jak-project/scripts/tasks/update-env.py
T
Tyler Wilding 6d99f1bfc1 d/config: re-organize decompiler/config and eliminate most of the duplication (#2185)
Reasons for doing so include:
1. This should stop the confusion around editing the wrong config file's
flags -- when for example, extracting a level. Common settings can be in
one central place, with bespoke overrides being provided for each
version
2. Less verbose way of supporting multiple game versions. You don't have
to duplicate the entire `type_casts` file for example, just add or
override the json objects required.
3. Makes the folder structure consistent, Jak 1's `all-types` is now in
a `jak1` folder, etc.
2023-03-08 20:07:26 -05:00

84 lines
2.3 KiB
Python

import argparse
import os
import pprint
import sys
parser = argparse.ArgumentParser("update-env")
parser.add_argument("--game", help="The name of the game", type=str)
parser.add_argument("--decomp_config", help="The decompiler config file", type=str)
parser.add_argument("--info", help="Just print out current settings", action='store_true')
args = parser.parse_args()
# TODO - read from defaults
file = {
"GAME": "jak1",
"DECOMP_CONFIG": "jak1/jak1_config.jsonc",
"DECOMP_CONFIG_VERSION": "ntsc_v1"
}
env_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), ".env")
if not os.path.exists(env_path):
with open(env_path, 'w') as env_file:
for item in file.items():
env_file.write("{}={}\n".format(item[0], item[1]))
with open(env_path, 'r') as env_file:
flags = env_file.readlines()
for flag in flags:
tokens = flag.split("=")
if tokens[0] in file:
file[tokens[0]] = tokens[1].strip()
if args.info:
print(file)
sys.exit(0)
valid_games = ["jak1", "jak2"]
decomp_config_map = {
"jak1": "jak1/jak1_config.jsonc",
"jak2": "jak2/jak2_config.jsonc",
}
decomp_config_version_map = {
"jak1": {
"ntscv1": "ntsc_v1",
"ntscv2": "ntsc_v2",
"pal": "pal",
"ntscjp": "jp"
},
"jak2": {
"ntscv1": "ntsc_v1"
}
}
default_config_version_map = {
"jak1": "ntsc_v1",
"jak2": "ntsc_v1"
}
if args.game:
if args.game not in valid_games:
print("Unsupported game '{}'".format(args.game))
sys.exit(1)
curr = file["GAME"]
file["GAME"] = args.game
if (curr != file["GAME"]) or file["DECOMP_CONFIG_VERSION"] not in decomp_config_version_map[file["GAME"]]:
file["DECOMP_CONFIG"] = decomp_config_map[file["GAME"]]
file["DECOMP_CONFIG_VERSION"] = default_config_version_map[file["GAME"]]
if args.decomp_config:
if args.decomp_config not in decomp_config_version_map[file["GAME"]]:
print("Unsupported decomp config '{}' for game '{}'".format(args.decomp_config, file["GAME"]))
sys.exit(1)
file["DECOMP_CONFIG"] = decomp_config_map[file["GAME"]]
file["DECOMP_CONFIG_VERSION"] = decomp_config_version_map[file["GAME"]][args.decomp_config]
with open(env_path, 'w') as env_file:
for item in file.items():
env_file.write("{}={}\n".format(item[0], item[1]))
print("Task settings updated")
pp = pprint.PrettyPrinter(indent=2)
pp.pprint(file)