57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
import argparse
|
|
import csv
|
|
import os
|
|
|
|
parser = argparse.ArgumentParser(description="Story CSV to .h defines")
|
|
parser.add_argument("--csv", required=True, help="Path to story CSV file")
|
|
parser.add_argument("--output", required=True, help="Path to output .h file")
|
|
args = parser.parse_args()
|
|
|
|
def flag_enum(name):
|
|
return "STORY_FLAG_" + name.upper().replace(" ", "_")
|
|
|
|
# Load flags
|
|
flags = []
|
|
with open(args.csv, newline="", encoding="utf-8") as f:
|
|
reader = csv.DictReader(f)
|
|
if "id" not in reader.fieldnames:
|
|
raise ValueError("CSV must have an 'id' column")
|
|
for row in reader:
|
|
flags.append({
|
|
"id": row["id"].strip(),
|
|
"initial": (row.get("initial") or "0").strip(),
|
|
})
|
|
|
|
# Build output
|
|
out = [
|
|
"#pragma once",
|
|
'#include "story/storyflagdefs.h"',
|
|
"",
|
|
"typedef enum {",
|
|
" STORY_FLAG_NULL,",
|
|
"",
|
|
]
|
|
for flag in flags:
|
|
out.append(f" {flag_enum(flag['id'])},")
|
|
out += [
|
|
"",
|
|
" STORY_FLAG_COUNT",
|
|
"} storyflag_t;",
|
|
"",
|
|
"static storyflagvalue_t STORY_FLAG_VALUES[STORY_FLAG_COUNT] = {",
|
|
]
|
|
for flag in flags:
|
|
out.append(f" [{flag_enum(flag['id'])}] = {flag['initial']},")
|
|
out += [
|
|
"};",
|
|
"",
|
|
"static const char_t *STORY_FLAG_SCRIPT =",
|
|
]
|
|
for i, flag in enumerate(flags):
|
|
out.append(f" \"{flag_enum(flag['id'])} = {i + 1}\\n\"")
|
|
out += [";", ""]
|
|
|
|
os.makedirs(os.path.dirname(args.output), exist_ok=True)
|
|
with open(args.output, "w", encoding="utf-8") as f:
|
|
f.write("\n".join(out))
|