Fixed duskdefs
This commit is contained in:
@@ -15,6 +15,7 @@ add_subdirectory(locale)
|
||||
add_asset(SCRIPT init.lua)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(item)
|
||||
add_subdirectory(entity)
|
||||
add_subdirectory(map)
|
||||
add_subdirectory(ui)
|
||||
|
||||
20
assets/item/CMakeLists.txt
Normal file
20
assets/item/CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
dusk_csv_to_enum(
|
||||
${CMAKE_CURRENT_LIST_DIR}/items.csv
|
||||
item/itemtype.h
|
||||
itemtype_t
|
||||
ITEM_TYPE
|
||||
type
|
||||
)
|
||||
|
||||
dusk_csv_to_enum(
|
||||
${CMAKE_CURRENT_LIST_DIR}/items.csv
|
||||
item/itemid.h
|
||||
itemid_t
|
||||
ITEM_ID
|
||||
id
|
||||
)
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"automappingRulesFile": "",
|
||||
"commands": [
|
||||
],
|
||||
"compatibilityVersion": 1100,
|
||||
"extensionsPath": "extensions",
|
||||
"folders": [
|
||||
"."
|
||||
],
|
||||
"properties": [
|
||||
],
|
||||
"propertyTypes": [
|
||||
]
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
{
|
||||
"Map/SizeTest": {
|
||||
"height": 4300,
|
||||
"width": 2
|
||||
},
|
||||
"activeFile": "map/untitled.tmx",
|
||||
"expandedProjectPaths": [
|
||||
"tileset",
|
||||
".",
|
||||
"map"
|
||||
],
|
||||
"file.lastUsedOpenFilter": "All Files (*)",
|
||||
"fileStates": {
|
||||
"entity/entities.tsx": {
|
||||
"scaleInDock": 1,
|
||||
"scaleInEditor": 1
|
||||
},
|
||||
"map/prarie.tsx": {
|
||||
"scaleInDock": 1,
|
||||
"scaleInEditor": 11
|
||||
},
|
||||
"map/untitled.tmx": {
|
||||
"scale": 2,
|
||||
"selectedLayer": 0,
|
||||
"viewCenter": {
|
||||
"x": 285.5,
|
||||
"y": 162.75
|
||||
}
|
||||
},
|
||||
"tileset/prarie.tsx": {
|
||||
"scaleInDock": 1,
|
||||
"scaleInEditor": 1
|
||||
}
|
||||
},
|
||||
"last.imagePath": "/home/yourwishes/htdocs/dusk/assets/tileset",
|
||||
"map.lastUsedFormat": "tmx",
|
||||
"map.tileHeight": 16,
|
||||
"map.tileWidth": 16,
|
||||
"openFiles": [
|
||||
"entity/entities.tsx",
|
||||
"map/untitled.tmx",
|
||||
"tileset/prarie.tsx"
|
||||
],
|
||||
"project": "untitled.tiled-project",
|
||||
"recentFiles": [
|
||||
"entity/entities.tsx",
|
||||
"tileset/prarie.tsx",
|
||||
"map/untitled.tmx",
|
||||
"map/prarie.tsx"
|
||||
],
|
||||
"tileset.lastUsedFormat": "tsx",
|
||||
"tileset.tileSize": {
|
||||
"height": 16,
|
||||
"width": 16
|
||||
}
|
||||
}
|
||||
@@ -6,18 +6,11 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "itemtype.h"
|
||||
#include "item/itemtype.h"
|
||||
#include "item/itemid.h"
|
||||
|
||||
typedef struct {
|
||||
itemtype_t type;
|
||||
} item_t;
|
||||
|
||||
typedef enum {
|
||||
ITEM_ID_NULL = 0,
|
||||
|
||||
ITEM_ID_POTION,
|
||||
ITEM_ID_POTATO,
|
||||
ITEM_ID_APPLE
|
||||
} itemid_t;
|
||||
|
||||
extern const item_t ITEMS[];
|
||||
@@ -1,20 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef enum {
|
||||
ITEM_TYPE_NULL = 0,
|
||||
|
||||
ITEM_TYPE_MEDICINE,
|
||||
ITEM_TYPE_INGREDIENT,
|
||||
ITEM_TYPE_FOOD,
|
||||
ITEM_TYPE_KEYITEM,
|
||||
|
||||
ITEM_TYPE_COUNT
|
||||
} itemtype_t;
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
add_subdirectory(run_python)
|
||||
add_subdirectory(env_to_h)
|
||||
add_subdirectory(csv_to_enum)
|
||||
|
||||
# Function that adds an asset to be compiled
|
||||
function(add_asset ASSET_TYPE ASSET_PATH)
|
||||
|
||||
35
tools/csv_to_enum/CMakeLists.txt
Normal file
35
tools/csv_to_enum/CMakeLists.txt
Normal file
@@ -0,0 +1,35 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
function(dusk_csv_to_enum INPUT_PATH OUTPUT_NAME_RELATIVE TYPEDEF PREFIX TAKE_COLUMN)
|
||||
set(NULL_ENTRY TRUE)
|
||||
set(COUNT_ENTRY TRUE)
|
||||
|
||||
# Take NULL_ENTRY and COUNT_ENTRY from ARGN
|
||||
foreach(ARG IN LISTS ARGN)
|
||||
if(ARG STREQUAL "NO_NULL_ENTRY")
|
||||
set(NULL_ENTRY FALSE)
|
||||
elseif(ARG STREQUAL "NO_COUNT_ENTRY")
|
||||
set(COUNT_ENTRY FALSE)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(DUSK_DEFS_TARGET_NAME "DUSK_DEFS_${OUTPUT_NAME_RELATIVE}")
|
||||
string(REPLACE "." "_" DUSK_DEFS_TARGET_NAME ${DUSK_DEFS_TARGET_NAME})
|
||||
string(REPLACE "/" "_" DUSK_DEFS_TARGET_NAME ${DUSK_DEFS_TARGET_NAME})
|
||||
|
||||
dusk_run_python(
|
||||
${DUSK_DEFS_TARGET_NAME}
|
||||
tools.csv_to_enum
|
||||
--csv ${INPUT_PATH}
|
||||
--output ${DUSK_GENERATED_HEADERS_DIR}/${OUTPUT_NAME_RELATIVE}
|
||||
--typedef ${TYPEDEF}
|
||||
--prefix ${PREFIX}
|
||||
--take-column ${TAKE_COLUMN}
|
||||
--null-entry ${NULL_ENTRY}
|
||||
--count-entry ${COUNT_ENTRY}
|
||||
)
|
||||
add_dependencies(${DUSK_LIBRARY_TARGET_NAME} ${DUSK_DEFS_TARGET_NAME})
|
||||
endfunction()
|
||||
50
tools/csv_to_enum/__main__.py
Normal file
50
tools/csv_to_enum/__main__.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import argparse
|
||||
import os
|
||||
import csv
|
||||
|
||||
parser = argparse.ArgumentParser(description="Convert CSV to .h defines")
|
||||
parser.add_argument("--csv", required=True, help="Path to CSV file")
|
||||
parser.add_argument("--output", required=True, help="Path to output .h file")
|
||||
parser.add_argument("--prefix", default="", help="Prefix for each define")
|
||||
parser.add_argument("--typedef", required=True, help="Typedef name for the enum")
|
||||
parser.add_argument("--take-column", required=True, help="Column name to take the values for the enum for")
|
||||
parser.add_argument("--null-entry", default=None, help="Optional name for a NULL/INVALID entry")
|
||||
parser.add_argument("--count-entry", default=None, help="Optional name for a COUNT entry")
|
||||
args = parser.parse_args()
|
||||
|
||||
outHeader = ""
|
||||
outHeader += "#include \"dusk.h\"\n\n"
|
||||
with open(args.csv, newline='') as csvfile:
|
||||
reader = csv.reader(csvfile)
|
||||
|
||||
headers = next(reader)
|
||||
if args.take_column not in headers:
|
||||
raise ValueError(f"Column '{args.take_column}' not found in CSV headers")
|
||||
take_column_index = headers.index(args.take_column)
|
||||
|
||||
# Extract entries
|
||||
entries = []
|
||||
for row in reader:
|
||||
value = row[take_column_index]
|
||||
clean_define_name = value.replace(" ", "_").upper()
|
||||
if clean_define_name in entries:
|
||||
continue # Avoid duplicates
|
||||
entries.append(clean_define_name)
|
||||
|
||||
# Gen enum.
|
||||
outHeader += f"typedef enum {{\n"
|
||||
if args.null_entry == "TRUE":
|
||||
outHeader += f" {args.prefix}_NULL = 0,\n\n"
|
||||
|
||||
for entry in entries:
|
||||
outHeader += f" {args.prefix}_{entry},\n"
|
||||
|
||||
if args.count_entry == "TRUE":
|
||||
outHeader += f"\n {args.prefix}_COUNT,\n"
|
||||
|
||||
outHeader += f"}} {args.typedef};\n\n"
|
||||
|
||||
# Write to output file (mkdirp if needed)
|
||||
os.makedirs(os.path.dirname(args.output), exist_ok=True)
|
||||
with open(args.output, 'w') as outFile:
|
||||
outFile.write(outHeader)
|
||||
@@ -8,8 +8,8 @@ function(dusk_env_to_h INPUT_PATH OUTPUT_NAME_RELATIVE)
|
||||
dusk_run_python(
|
||||
${DUSK_DEFS_TARGET_NAME}
|
||||
tools.env_to_h
|
||||
--env ${INPUT_PATH}
|
||||
--output ${DUSK_BUILT_ASSETS_DIR}/${OUTPUT_NAME_RELATIVE}
|
||||
--env "${CMAKE_CURRENT_LIST_DIR}/${INPUT_PATH}"
|
||||
--output ${DUSK_GENERATED_HEADERS_DIR}/${OUTPUT_NAME_RELATIVE}
|
||||
)
|
||||
add_dependencies(${DUSK_LIBRARY_TARGET_NAME} ${DUSK_DEFS_TARGET_NAME})
|
||||
endfunction()
|
||||
@@ -11,7 +11,6 @@ args = parser.parse_args()
|
||||
load_dotenv(dotenv_path=args.env)
|
||||
fileDefs = dotenv_values(dotenv_path=args.env)
|
||||
|
||||
|
||||
outHeader = ""
|
||||
outHeader += "#include \"dusk.h\"\n\n"
|
||||
for key, value in fileDefs.items():
|
||||
|
||||
Reference in New Issue
Block a user