mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-29 05:08:00 +03:00
66 lines
1.3 KiB
Python
Executable file
66 lines
1.3 KiB
Python
Executable file
#!/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"
|
|
|
|
|
|
BODY_PREFIX = """
|
|
#include "init.h"
|
|
#include "game/gameflow.h"
|
|
#include "global/vars.h"
|
|
#include "memory.h"
|
|
|
|
// THIS IS AN AUTOGENERATED FILE.
|
|
// To generate it, run scripts/generate_init.
|
|
|
|
#ifndef VERSION
|
|
#define VERSION "T1M (unknown version)"
|
|
#endif
|
|
|
|
const char *g_T1MVersion = VERSION;
|
|
|
|
typedef struct {
|
|
GAME_STRING_ID key;
|
|
char *string;
|
|
} STRING_DEF;
|
|
|
|
STRING_DEF m_StringDefs[] = {"""
|
|
|
|
BODY_SUFFIX = """ { 0, NULL },
|
|
};
|
|
|
|
void T1MInit()
|
|
{
|
|
for (const STRING_DEF *def = m_StringDefs; def->string; def++) {
|
|
g_GameFlow.strings[def->key] = Memory_Dup(def->string);
|
|
}
|
|
}
|
|
"""
|
|
|
|
|
|
def main() -> None:
|
|
gf = pyjson5.loads(
|
|
(CONFIG_DIR / "Tomb1Main_gameflow.json5").read_text(encoding="utf-8")
|
|
)
|
|
|
|
with io.StringIO() as handle:
|
|
print(BODY_PREFIX.lstrip(), file=handle)
|
|
for key, value in gf["strings"].items():
|
|
print(f" {{ GS_{key}, {json.dumps(value)} }},", file=handle)
|
|
print(BODY_SUFFIX.rstrip(), 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()
|