update msg building for precomp

This commit is contained in:
alex 2022-01-08 15:45:42 +00:00
parent 559007d861
commit 715e469ab9
No known key found for this signature in database
GPG Key ID: E907B20C17C70B03

View File

@ -338,10 +338,12 @@ def strip_c_comments(text):
if __name__ == "__main__":
if len(argv) < 3:
print("usage: parse_compile.py [in.msg] [out.msgpack]")
print("usage: parse_compile.py [in.msg] [out.msgpack] [--c]")
exit(1)
_, filename, outfile = argv
filename = argv[1]
outfile = argv[2]
is_output_format_c = "--c" in argv
messages = []
@ -392,7 +394,17 @@ if __name__ == "__main__":
directive = directive.split(":")
if directive[0] != "#message" or len(directive) != 3:
if directive[0] != "#message":
print(f"{filename}:{lineno}: expected #message directive")
exit(1)
if is_output_format_c:
if len(directive) != 2:
print(f"{filename}:{lineno}: expected #message:NAME directive")
exit(1)
message = Message(directive[1], None, None)
else:
if len(directive) != 3:
print(f"{filename}:{lineno}: expected #message:SECTION:INDEX directive")
exit(1)
@ -1100,6 +1112,17 @@ if __name__ == "__main__":
print(f"{filename}: missing [end]")
exit(1)
if is_output_format_c:
with open(outfile, "w") as f:
f.write(f"#include <ultra64.h>\n")
for message in messages:
f.write(f"static s8 {message.name}[] = {{\n")
for b in message.bytes:
f.write(f"0x{b:02X},")
f.write(f"\n}};\n")
else:
with open(outfile, "wb") as f:
msgpack.pack([{
"section": message.section,