mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 21:27:52 -04:00
9c390e1461
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.
39 lines
1.6 KiB
Python
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)
|