prog
This commit is contained in:
@@ -1,37 +1 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
function(dusk_item_csv CSV_FILE)
|
||||
dusk_csv_to_enum(
|
||||
${CSV_FILE}
|
||||
item/itemtype.h
|
||||
itemtype_t
|
||||
ITEM_TYPE_
|
||||
type
|
||||
)
|
||||
|
||||
dusk_csv_to_enum(
|
||||
${CSV_FILE}
|
||||
item/itemid.h
|
||||
itemid_t
|
||||
ITEM_ID_
|
||||
id
|
||||
)
|
||||
|
||||
dusk_csv_to_array(
|
||||
${CSV_FILE}
|
||||
item/itemname.h
|
||||
ITEM_NAMES
|
||||
item/itemid.h
|
||||
ITEM_ID_
|
||||
id
|
||||
id
|
||||
)
|
||||
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
ITEM_CSV_GENERATED=1
|
||||
)
|
||||
endfunction()
|
||||
add_subdirectory(csv)
|
||||
45
tools/item/csv/CMakeLists.txt
Normal file
45
tools/item/csv/CMakeLists.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
function(dusk_item_csv CSV_FILE)
|
||||
# dusk_csv_to_enum(
|
||||
# ${CSV_FILE}
|
||||
# item/itemtype.h
|
||||
# itemtype_t
|
||||
# ITEM_TYPE_
|
||||
# type
|
||||
# )
|
||||
|
||||
# dusk_csv_to_enum(
|
||||
# ${CSV_FILE}
|
||||
# item/itemid.h
|
||||
# itemid_t
|
||||
# ITEM_ID_
|
||||
# id
|
||||
# )
|
||||
|
||||
# dusk_csv_to_array(
|
||||
# ${CSV_FILE}
|
||||
# item/itemname.h
|
||||
# ITEM_NAMES
|
||||
# item/itemid.h
|
||||
# ITEM_ID_
|
||||
# id
|
||||
# id
|
||||
# )
|
||||
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
ITEM_CSV_GENERATED=1
|
||||
)
|
||||
|
||||
dusk_run_python(
|
||||
dusk_item_csv_defs
|
||||
tools.item.csv
|
||||
--csv ${CSV_FILE}
|
||||
--output ${DUSK_GENERATED_HEADERS_DIR}/item/itemdefs.h
|
||||
)
|
||||
add_dependencies(${DUSK_LIBRARY_TARGET_NAME} dusk_item_csv_defs)
|
||||
endfunction()
|
||||
19
tools/item/csv/__main__.py
Normal file
19
tools/item/csv/__main__.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import argparse
|
||||
import os
|
||||
import csv
|
||||
from tools.util.type import detectType, stringToCType, typeToCType
|
||||
|
||||
parser = argparse.ArgumentParser(description="Item CSV to .h defines")
|
||||
parser.add_argument("--csv", required=True, help="Path to item CSV file")
|
||||
parser.add_argument("--output", required=True, help="Path to output .h file")
|
||||
args = parser.parse_args()
|
||||
|
||||
# Load up CSV file.
|
||||
outHeader = "#pragma once\n"
|
||||
outHeader += "#include \"item/item.h\"\n\n"
|
||||
with open(args.csv, newline="", encoding="utf-8") as csvfile:
|
||||
reader = csv.DictReader(csvfile)
|
||||
|
||||
# CSV must have id and type columns.
|
||||
if "id" not in reader.fieldnames or "type" not in reader.fieldnames:
|
||||
raise Exception("CSV file must have 'id' and 'type' columns")
|
||||
Reference in New Issue
Block a user