Cleaned some tools up
This commit is contained in:
@@ -5,8 +5,6 @@
|
||||
|
||||
add_subdirectory(run_python)
|
||||
add_subdirectory(env_to_h)
|
||||
add_subdirectory(item)
|
||||
add_subdirectory(input)
|
||||
|
||||
# Function that adds an asset to be compiled
|
||||
function(add_asset ASSET_TYPE ASSET_PATH)
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(csv)
|
||||
@@ -1,37 +0,0 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
function(dusk_input_csv CSV_FILE)
|
||||
# dusk_csv_to_enum(
|
||||
# ${CSV_FILE}
|
||||
# input/inputactiontype.h
|
||||
# inputaction_t
|
||||
# INPUT_ACTION_
|
||||
# id
|
||||
# )
|
||||
|
||||
# dusk_csv_to_array(
|
||||
# ${CSV_FILE}
|
||||
# input/inputactionname.h
|
||||
# INPUT_ACTION_NAMES
|
||||
# input/inputactiontype.h
|
||||
# INPUT_ACTION_
|
||||
# id
|
||||
# id
|
||||
# )
|
||||
|
||||
dusk_run_python(
|
||||
dusk_input_csv_defs
|
||||
tools.input.csv
|
||||
--csv ${CSV_FILE}
|
||||
--output ${DUSK_GENERATED_HEADERS_DIR}/input/inputactiontype.h
|
||||
)
|
||||
add_dependencies(${DUSK_LIBRARY_TARGET_NAME} dusk_input_csv_defs)
|
||||
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
INPUT_CSV_GENERATED=1
|
||||
)
|
||||
endfunction()
|
||||
@@ -24,17 +24,22 @@ with open(args.csv, newline="", encoding="utf-8") as csvfile:
|
||||
|
||||
# For each ID
|
||||
inputIds = []
|
||||
inputIdValues = {}
|
||||
for row in reader:
|
||||
inputId = row["id"]
|
||||
if inputId not in inputIds:
|
||||
inputIds.append(inputId)
|
||||
|
||||
# For each ID, create enum entry.
|
||||
count = 0
|
||||
outHeader += "typedef enum {\n"
|
||||
outHeader += " INPUT_ACTION_NULL = 0,\n\n"
|
||||
outHeader += f" INPUT_ACTION_NULL = {count},\n\n"
|
||||
count += 1
|
||||
for inputId in inputIds:
|
||||
outHeader += f" {csvIdToEnumName(inputId)},\n"
|
||||
outHeader += f"\n INPUT_ACTION_COUNT\n"
|
||||
inputIdValues[inputId] = count
|
||||
outHeader += f" {csvIdToEnumName(inputId)} = {count},\n"
|
||||
count += 1
|
||||
outHeader += f"\n INPUT_ACTION_COUNT = {count}\n"
|
||||
outHeader += "} inputaction_t;\n\n"
|
||||
|
||||
# Write IDs to char array.
|
||||
@@ -43,6 +48,13 @@ with open(args.csv, newline="", encoding="utf-8") as csvfile:
|
||||
outHeader += f" [{csvIdToEnumName(inputId)}] = \"{inputId}\",\n"
|
||||
outHeader += f"}};\n\n"
|
||||
|
||||
# Lua Script
|
||||
outHeader += f"static const char_t *INPUT_ACTION_SCRIPT = \n"
|
||||
for inputId in inputIds:
|
||||
# Reference the enum
|
||||
outHeader += f" \"{csvIdToEnumName(inputId)} = {inputIdValues[inputId]}\\n\"\n"
|
||||
outHeader += f";\n\n"
|
||||
|
||||
# Write to output file.
|
||||
os.makedirs(os.path.dirname(args.output), exist_ok=True)
|
||||
with open(args.output, "w", encoding="utf-8") as outFile:
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(csv)
|
||||
@@ -1,46 +0,0 @@
|
||||
# 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
|
||||
# )
|
||||
|
||||
|
||||
dusk_run_python(
|
||||
dusk_item_csv_defs
|
||||
tools.item.csv
|
||||
--csv ${CSV_FILE}
|
||||
--output ${DUSK_GENERATED_HEADERS_DIR}/item/item.h
|
||||
)
|
||||
add_dependencies(${DUSK_LIBRARY_TARGET_NAME} dusk_item_csv_defs)
|
||||
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
ITEM_CSV_GENERATED=1
|
||||
)
|
||||
endfunction()
|
||||
@@ -42,19 +42,28 @@ with open(args.csv, newline="", encoding="utf-8") as csvfile:
|
||||
outHeader = "#pragma once\n"
|
||||
outHeader += '#include "dusk.h"\n\n'
|
||||
|
||||
itemTypeValues = {}
|
||||
itemIdValues = {}
|
||||
count = 0
|
||||
|
||||
# Create enum for types and ids, include null and count.
|
||||
outHeader += "typedef enum {\n"
|
||||
outHeader += " ITEM_TYPE_NULL = 0,\n"
|
||||
outHeader += f" ITEM_TYPE_NULL = {count},\n"
|
||||
count += 1
|
||||
for itemType in itemTypes:
|
||||
outHeader += f" {csvIdToEnumName(itemType)},\n"
|
||||
outHeader += f" ITEM_TYPE_COUNT\n"
|
||||
itemTypeValues[itemType] = count
|
||||
outHeader += f" {csvIdToEnumName(itemType)} = {count},\n"
|
||||
count += 1
|
||||
outHeader += f" ITEM_TYPE_COUNT = {count}\n"
|
||||
outHeader += "} itemtype_t;\n\n"
|
||||
|
||||
outHeader += "typedef enum {\n"
|
||||
outHeader += " ITEM_ID_NULL = 0,\n"
|
||||
outHeader += f" ITEM_ID_NULL = {count},\n"
|
||||
for itemId in itemIds:
|
||||
outHeader += f" {csvIdToEnumName(itemId)},\n"
|
||||
outHeader += f" ITEM_ID_COUNT\n"
|
||||
itemIdValues[itemId] = count
|
||||
outHeader += f" {csvIdToEnumName(itemId)} = {count},\n"
|
||||
count += 1
|
||||
outHeader += f" ITEM_ID_COUNT = {count}\n"
|
||||
outHeader += "} itemid_t;\n\n"
|
||||
|
||||
# Create struct for item data.
|
||||
@@ -76,6 +85,14 @@ for itemId in itemIds:
|
||||
outHeader += f" }},\n"
|
||||
outHeader += f"}};\n\n"
|
||||
|
||||
# Create lua script defining items.
|
||||
outHeader += f"static const char_t *ITEM_SCRIPT = \n"
|
||||
for itemId in itemIds:
|
||||
outHeader += f" \"{csvIdToEnumName(itemId)} = {itemIdValues[itemId]}\\n\"\n"
|
||||
for itemType in itemTypes:
|
||||
outHeader += f" \"{csvIdToEnumName(itemType)} = {itemTypeValues[itemType]}\\n\"\n"
|
||||
outHeader += f";\n\n"
|
||||
|
||||
# Write to output file.
|
||||
os.makedirs(os.path.dirname(args.output), exist_ok=True)
|
||||
with open(args.output, "w", encoding="utf-8") as outFile:
|
||||
|
||||
Reference in New Issue
Block a user