#!/usr/bin/env python3 import io import json from pathlib import Path import pyjson5 REPO_DIR = Path(__file__).parent.parent BIN_DIR = REPO_DIR / "bin" SRC_DIR = REPO_DIR / "src" CONFIG_DIR = BIN_DIR / "cfg" def main() -> None: gf = pyjson5.loads( (CONFIG_DIR / "Tomb1Main_gameflow.json5").read_text(encoding="utf-8") ) with io.StringIO() as handle: print('#include "init.h"', file=handle) print(file=handle) print('#include "global/vars.h"', file=handle) print(file=handle) print("// THIS IS AN AUTOGENERATED FILE.", file=handle) print("// To generate it, run scripts/generate_init.", file=handle) print("", file=handle) print("#ifndef VERSION", file=handle) print(' #define VERSION "T1M (unknown version)"', file=handle) print("#endif", file=handle) print("", file=handle) print("const char *T1MVersion = VERSION;", file=handle) print("", file=handle) print("void T1MInit()", file=handle) print("{", file=handle) for key, value in gf["strings"].items(): print( f" GF.strings[GS_{key}] = {json.dumps(value)};", file=handle, ) print("}", file=handle) new_text = handle.getvalue() path = SRC_DIR / "init.c" if path.read_text() != new_text: path.write_text(new_text) if __name__ == "__main__": main()