Added story flags
This commit is contained in:
@@ -11,10 +11,6 @@ args = parser.parse_args()
|
||||
def csvIdToEnumName(itemId):
|
||||
return "ITEM_ID_" + itemId.upper()
|
||||
|
||||
# Load up CSV file.
|
||||
outHeader = "#pragma once\n"
|
||||
outHeader += '#include "dusk.h"\n\n'
|
||||
|
||||
itemIds = []
|
||||
itemTypes = []
|
||||
itemRowById = {}
|
||||
|
||||
49
tools/story/csv/__main__.py
Normal file
49
tools/story/csv/__main__.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import argparse
|
||||
import os
|
||||
import csv
|
||||
from tools.util.type import detectType, stringToCType, typeToCType
|
||||
|
||||
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")
|
||||
args = parser.parse_args()
|
||||
|
||||
def idToEnum(id):
|
||||
return "STORY_FLAG_" + id.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
|
||||
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"
|
||||
for row in reader:
|
||||
id = idToEnum(row["id"].strip())
|
||||
outHeader += f" {id},\n"
|
||||
outHeader += "\n STORY_FLAG_COUNT\n"
|
||||
outHeader += "} storyflag_t;\n\n"
|
||||
|
||||
# Generate flag values
|
||||
csvfile.seek(0)
|
||||
reader = csv.DictReader(csvfile)
|
||||
|
||||
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)
|
||||
Reference in New Issue
Block a user