2021-11-05 18:23:49 +01:00
|
|
|
#!/usr/bin/env python3
|
2023-08-31 18:04:06 +02:00
|
|
|
import argparse
|
2021-03-17 12:14:43 +01:00
|
|
|
import json
|
2021-11-05 18:23:49 +01:00
|
|
|
from pathlib import Path
|
|
|
|
|
2024-04-09 00:37:46 +02:00
|
|
|
from shared.versioning import generate_version
|
|
|
|
|
2023-11-25 14:01:34 +01:00
|
|
|
try:
|
|
|
|
import pyjson5
|
|
|
|
except ImportError:
|
|
|
|
import json5 as pyjson5
|
2021-03-17 12:14:43 +01:00
|
|
|
|
2021-10-19 16:56:11 +02:00
|
|
|
REPO_DIR = Path(__file__).parent.parent
|
2024-03-23 13:34:59 +01:00
|
|
|
SHIP_DIR = REPO_DIR / "data/ship"
|
2021-10-19 16:56:11 +02:00
|
|
|
SRC_DIR = REPO_DIR / "src"
|
2024-03-23 13:34:59 +01:00
|
|
|
CONFIG_DIR = SHIP_DIR / "cfg"
|
2023-09-26 16:22:29 +02:00
|
|
|
GAMEFLOW_PATH = CONFIG_DIR / "TR1X_gameflow.json5"
|
2021-03-17 12:14:43 +01:00
|
|
|
|
|
|
|
|
2024-04-09 00:37:46 +02:00
|
|
|
TEMPLATE = """
|
2021-12-04 03:15:21 +01:00
|
|
|
#include "game/gameflow.h"
|
2022-05-13 00:24:21 +02:00
|
|
|
#include "global/types.h"
|
|
|
|
|
|
|
|
#include <stddef.h>
|
2021-12-04 03:15:21 +01:00
|
|
|
|
2023-09-26 16:22:29 +02:00
|
|
|
const char *g_TR1XVersion = "{version}";
|
2021-12-04 03:15:21 +01:00
|
|
|
|
2024-04-09 00:37:46 +02:00
|
|
|
GAMEFLOW_DEFAULT_STRING g_GameFlowDefaultStrings[] = {{
|
|
|
|
{strings}
|
|
|
|
{{ 0, NULL }},
|
|
|
|
}};
|
2021-12-04 03:15:21 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
2023-08-31 18:04:06 +02:00
|
|
|
def parse_args() -> argparse.Namespace:
|
|
|
|
parser = argparse.ArgumentParser()
|
2024-04-09 00:37:46 +02:00
|
|
|
parser.add_argument("-o", "--output", type=Path)
|
2023-08-31 18:04:06 +02:00
|
|
|
return parser.parse_args()
|
|
|
|
|
2021-11-05 18:23:49 +01:00
|
|
|
|
2024-04-09 00:37:46 +02:00
|
|
|
def get_init_c() -> str:
|
2023-08-31 18:04:06 +02:00
|
|
|
gameflow = pyjson5.loads(GAMEFLOW_PATH.read_text(encoding="utf-8"))
|
2024-04-09 00:37:46 +02:00
|
|
|
return TEMPLATE.format(
|
|
|
|
version=generate_version(),
|
|
|
|
strings="\n".join(
|
|
|
|
f" {{ GS_{key}, {json.dumps(value)} }},"
|
|
|
|
for key, value in gameflow["strings"].items()
|
|
|
|
),
|
|
|
|
)
|
2021-11-12 21:22:47 +01:00
|
|
|
|
2023-08-31 18:04:06 +02:00
|
|
|
|
2024-04-09 00:37:46 +02:00
|
|
|
def update_init_c(output_path: Path) -> None:
|
|
|
|
new_text = get_init_c()
|
2023-08-31 18:04:06 +02:00
|
|
|
if not output_path.exists() or output_path.read_text() != new_text:
|
|
|
|
output_path.write_text(new_text)
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
|
|
|
args = parse_args()
|
2024-04-09 00:37:46 +02:00
|
|
|
if args.output:
|
|
|
|
update_init_c(output_path=args.output)
|
2023-08-31 18:04:06 +02:00
|
|
|
else:
|
2024-04-09 00:37:46 +02:00
|
|
|
print(args.outptu)
|
2021-03-17 12:14:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|