prog
All checks were successful
Build Dusk / run-tests (push) Successful in 1m39s
Build Dusk / build-linux (push) Successful in 1m36s
Build Dusk / build-psp (push) Successful in 1m52s

This commit is contained in:
2026-01-31 21:20:33 -06:00
parent c2cad858a5
commit 982d28a3e0
15 changed files with 247 additions and 1 deletions

6
assets/ui/test.lua Normal file
View File

@@ -0,0 +1,6 @@
module('ui')
module('color')
function draw(x, y)
uiDrawRect(COLOR_WHITE, x, y, 32, 32)
end

View File

@@ -65,4 +65,5 @@ add_subdirectory(script)
add_subdirectory(thread)
add_subdirectory(time)
add_subdirectory(ui)
add_subdirectory(ui2)
add_subdirectory(util)

22
src/display/color.csv Normal file
View File

@@ -0,0 +1,22 @@
name,r,g,b,a
black,0,0,0,1
white,1,1,1,1
red,1,0,0,1
green,0,1,0,1
blue,0,0,1,1
yellow,1,1,0,1
cyan,0,1,1,1
magenta,1,0,1,1
transparent,0,0,0,0
transparent_white,1,1,1,0
transparent_black,0,0,0,0
gray,0.5,0.5,0.5,1
light_gray,0.75,0.75,0.75,1
dark_gray,0.25,0.25,0.25,1
orange,1,0.65,0,1
purple,0.5,0,0.5,1
brown,0.6,0.4,0.2,1
pink,1,0.75,0.8,1
lime,0.75,1,0,1
navy,0,0,0.5,1
teal,0,0.5,0.5,1
1 name r g b a
2 black 0 0 0 1
3 white 1 1 1 1
4 red 1 0 0 1
5 green 0 1 0 1
6 blue 0 0 1 1
7 yellow 1 1 0 1
8 cyan 0 1 1 1
9 magenta 1 0 1 1
10 transparent 0 0 0 0
11 transparent_white 1 1 1 0
12 transparent_black 0 0 0 0
13 gray 0.5 0.5 0.5 1
14 light_gray 0.75 0.75 0.75 1
15 dark_gray 0.25 0.25 0.25 1
16 orange 1 0.65 0 1
17 purple 0.5 0 0.5 1
18 brown 0.6 0.4 0.2 1
19 pink 1 0.75 0.8 1
20 lime 0.75 1 0 1
21 navy 0 0 0.5 1
22 teal 0 0.5 0.5 1

View File

@@ -11,4 +11,5 @@ add_subdirectory(item)
add_subdirectory(locale)
add_subdirectory(system)
add_subdirectory(scene)
add_subdirectory(time)
add_subdirectory(time)
add_subdirectory(ui)

View File

@@ -10,4 +10,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
modulecamera.c
modulespritebatch.c
moduleglm.c
modulecolor.c
)

View File

@@ -0,0 +1,48 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "modulecolor.h"
#include "display/color.h"
#include "assert/assert.h"
#include "script/struct/scriptstruct.h"
#include "util/string.h"
void moduleColor(scriptcontext_t *context) {
assertNotNull(context, "Context cannot be NULL.");
scriptStructRegister(context, "color_mt", moduleColorGetter, NULL);
}
void moduleColorGetter(
const scriptcontext_t *context,
const char_t *key,
const void *structPtr,
scriptvalue_t *outValue
) {
const color_t *color = (color_t*)structPtr;
if(stringCompare(key, "r") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_INT;
outValue->value.intValue = color->r;
return;
}
if(stringCompare(key, "g") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_INT;
outValue->value.intValue = color->g;
return;
}
if(stringCompare(key, "b") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_INT;
outValue->value.intValue = color->b;
return;
}
if(stringCompare(key, "a") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_INT;
outValue->value.intValue = color->a;
return;
}
}

View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "script/scriptcontext.h"
/**
* Registers the color module with the given script context.
*
* @param context The script context to register the module with.
*/
void moduleColor(scriptcontext_t *context);
/**
* Getter function for the color structure.
*
* @param context The script context.
* @param key The key to get.
* @param structPtr Pointer to the color structure.
* @param outValue Output value.
*/
void moduleColorGetter(
const scriptcontext_t *context,
const char_t *key,
const void *structPtr,
scriptvalue_t *outValue
);

View File

@@ -0,0 +1,10 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
moduleui.c
)

View File

@@ -0,0 +1,15 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "moduleui.h"
#include "assert/assert.h"
void moduleUi(scriptcontext_t *ctx) {
assertNotNull(ctx, "Script context cannot be NULL");
}

View File

@@ -0,0 +1,16 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "script/scriptcontext.h"
/**
* Registers the ui module within the given script context.
*
* @param ctx The script context to register the module in.
*/
void moduleUi(scriptcontext_t *ctx);

View File

@@ -14,15 +14,18 @@
#include "script/module/locale/modulelocale.h"
#include "script/module/time/moduletime.h"
#include "script/module/event/moduleevent.h"
#include "script/module/display/modulecolor.h"
#include "script/module/display/modulespritebatch.h"
#include "script/module/display/modulecamera.h"
#include "script/module/display/moduleglm.h"
#include "script/module/ui/moduleui.h"
#include "util/string.h"
const scriptmodule_t SCRIPT_MODULE_LIST[] = {
{ .name = "system", .callback = moduleSystem },
{ .name = "input", .callback = moduleInput },
{ .name = "platform", .callback = modulePlatform },
{ .name = "color", .callback = moduleColor },
{ .name = "scene", .callback = moduleScene },
{ .name = "item", .callback = moduleItem },
{ .name = "locale", .callback = moduleLocale },
@@ -31,6 +34,7 @@ const scriptmodule_t SCRIPT_MODULE_LIST[] = {
{ .name = "spritebatch", .callback = moduleSpriteBatch },
{ .name = "camera", .callback = moduleCamera },
{ .name = "glm", .callback = moduleGLM },
{ .name = "ui", .callback = moduleUi },
};
#define SCRIPT_MODULE_COUNT ( \

9
src/ui2/CMakeLists.txt Normal file
View File

@@ -0,0 +1,9 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
)

8
src/ui2/ui2.c Normal file
View File

@@ -0,0 +1,8 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "ui2.h"

10
src/ui2/ui2.h Normal file
View File

@@ -0,0 +1,10 @@
// Copyright (c) 2026 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dusk.h"
// Two kinds of UI elements, those that are scripted (with a state, logic, etc)
// and those that are draw only (rectangle, text, etc).

View File

@@ -0,0 +1,64 @@
import argparse
import os
import csv
from tools.util.type import detectType, stringToCType, typeToCType
parser = argparse.ArgumentParser(description="Color CSV to .h defines")
parser.add_argument("--csv", required=True, help="Path to color CSV file")
parser.add_argument("--output", required=True, help="Path to output .h file")
args = parser.parse_args()
def csvIdToEnumName(inputId):
return "INPUT_ACTION_" + inputId.upper()
# Load up CSV file.
outHeader = "#pragma once\n"
outHeader += '#include "dusk.h"\n\n'
outHeader += f"typedef float_t colorchannelf_t;\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")
# 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 += f" INPUT_ACTION_NULL = {count},\n\n"
count += 1
for inputId in inputIds:
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.
outHeader += f"static const char_t* INPUT_ACTION_IDS[] = {{\n"
for inputId in inputIds:
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:
outFile.write(outHeader)