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 += ["};", ""] 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))