jak-project/scripts/gsrc/skeleton_creation/generate_dgo_files.py
Tyler Wilding 9c390e1461
scripts: add a script to generate game.gp code, comment out generated code for now (#1966)
Generates the `game.gp` code for all DGOs, code added to the project
file has been commented out for now.

In my opinion, this is way too much in a single file -- it would be nice
if this code would live directly inside the `.gd` files themselves, then
everything is nicely organized. But this approach might have issues I'm
not aware of.
2022-10-14 19:10:05 -04:00

39 lines
1.6 KiB
Python

# Creates the `*.gd` files that go in ./goal_src/<game>/dgos
# Takes input from the `dgo.txt` file that is generated by the decompiler
# Run with all inputs enabled to get all the info!
# example - python .\scripts\gsrc\skeleton_creation\generate_dgo_files.py --game jak2 --dgotxt .\decompiler_out\jak2\dgo.txt
import argparse
parser = argparse.ArgumentParser("generate_dgo_files")
parser.add_argument("--game", help="The name of the game", type=str)
parser.add_argument("--dgotxt", help="Path to the dgo.txt file", type=str)
args = parser.parse_args()
# Read in the dgo.txt file
with open(args.dgotxt, "r") as f:
lines = f.readlines()[2:] # skip the first two lines, assumed to be a comment header and an empty line
# OpenGOAL still doesn't have a data serialization/deserialization format
# so read line by line, assuming each DGO is seperated by an empty line
current_dgo_name = None
current_dgo_lines = []
for line in lines:
if line.strip() == "":
# Write out contents to the .gd file
if current_dgo_name is not None:
path = "./goal_src/{}/dgos/{}".format(args.game, current_dgo_name)
print("writing to {}".format(path))
with open(path, "w") as wf:
wf.writelines(current_dgo_lines)
current_dgo_name = None
current_dgo_lines = []
continue
if ".CGO" in line or ".DGO" in line:
print("found one! - {}".format(line.strip()))
# figure out the name
current_dgo_name = line.replace("(", "").replace("\"", "").strip().lower().replace(".dgo", ".gd").replace(".cgo", ".gd")
print(current_dgo_name)
if current_dgo_name is not None:
current_dgo_lines.append(line)