Dusk texture creator

This commit is contained in:
2026-04-13 19:51:11 -05:00
parent 4b3826edd9
commit 5a651d2d1f
39 changed files with 1402 additions and 2659 deletions
+37 -36
View File
@@ -1,48 +1,49 @@
import argparse
import os
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("--header-file", required=True, help="Path to output .h file")
parser.add_argument("--output", required=True, help="Path to output .h file")
args = parser.parse_args()
def idToEnum(id):
return "STORY_FLAG_" + id.upper().replace(" ", "_")
def flag_enum(name):
return "STORY_FLAG_" + name.upper().replace(" ", "_")
# Load up CSV file.
outHeader = "#pragma once\n"
outHeader += '#include "story/storyflagdefs.h"\n\n'
with open(args.csv, newline="", encoding="utf-8") as csvfile:
reader = csv.DictReader(csvfile)
# CSV must have id column
# Load flags
flags = []
with open(args.csv, newline="", encoding="utf-8") as f:
reader = csv.DictReader(f)
if "id" not in reader.fieldnames:
raise Exception("CSV file must have 'id' column")
# Generate enum
outHeader += "typedef enum {\n"
outHeader += " STORY_FLAG_NULL,\n\n"
raise ValueError("CSV must have an 'id' column")
for row in reader:
id = idToEnum(row["id"].strip())
outHeader += f" {id},\n"
outHeader += "\n STORY_FLAG_COUNT\n"
outHeader += "} storyflag_t;\n\n"
flags.append({
"id": row["id"].strip(),
"initial": (row.get("initial") or "0").strip(),
})
# Generate flag values
csvfile.seek(0)
reader = csv.DictReader(csvfile)
# 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 += ["};", ""]
outHeader += "static storyflagvalue_t STORY_FLAG_VALUES[STORY_FLAG_COUNT] = {\n"
for row in reader:
id = idToEnum(row["id"].strip())
initial = row.get("initial", "0").strip() or "0"
outHeader += f" [{id}] = {initial},\n"
outHeader += "};\n"
os.makedirs(os.path.dirname(args.header_file), exist_ok=True)
# Write header
with open(args.header_file, "w", encoding="utf-8") as headerFile:
headerFile.write(outHeader)
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))