diff --git a/assets/init.lua b/assets/init.lua index b50800b..beee571 100644 --- a/assets/init.lua +++ b/assets/init.lua @@ -4,7 +4,7 @@ module('scene') module('locale') -- Default Input bindings. -if PLATFORM == "psp" then +if PSP then inputBind("up", INPUT_ACTION_UP) inputBind("down", INPUT_ACTION_DOWN) inputBind("left", INPUT_ACTION_LEFT) @@ -50,6 +50,22 @@ else inputBind("escape", INPUT_ACTION_RAGEQUIT) end + if INPUT_GAMEPAD then + inputBind("gamepad_up", INPUT_ACTION_UP) + inputBind("gamepad_down", INPUT_ACTION_DOWN) + inputBind("gamepad_left", INPUT_ACTION_LEFT) + inputBind("gamepad_right", INPUT_ACTION_RIGHT) + + inputBind("gamepad_a", INPUT_ACTION_ACCEPT) + inputBind("gamepad_b", INPUT_ACTION_CANCEL) + inputBind("gamepad_back", INPUT_ACTION_RAGEQUIT) + + inputBind("gamepad_lstick_up", INPUT_ACTION_UP) + inputBind("gamepad_lstick_down", INPUT_ACTION_DOWN) + inputBind("gamepad_lstick_left", INPUT_ACTION_LEFT) + inputBind("gamepad_lstick_right", INPUT_ACTION_RIGHT) + end + if INPUT_POINTER then inputBind("mouse_x", INPUT_ACTION_POINTERX) inputBind("mouse_y", INPUT_ACTION_POINTERY) diff --git a/assets/scene/minesweeper.lua b/assets/scene/minesweeper.lua index 8c75607..bcafd1e 100644 --- a/assets/scene/minesweeper.lua +++ b/assets/scene/minesweeper.lua @@ -171,12 +171,31 @@ function borderDraw(x, y, innerWidth, innerHeight) ) end +x = 0 +y = 0 + function sceneDispose() end function sceneUpdate() + if inputIsDown(INPUT_ACTION_RIGHT) then + x = x + 1 + end + + if inputIsDown(INPUT_ACTION_LEFT) then + x = x - 1 + end + + if inputIsDown(INPUT_ACTION_DOWN) then + y = y + 1 + end + + if inputIsDown(INPUT_ACTION_UP) then + y = y - 1 + end end + function sceneRender() -- Update camera cameraPushMatrix(camera) @@ -185,7 +204,7 @@ function sceneRender() spriteBatchPush( nil, - 0, 0, 32, 32, + x, y, x + 32, y + 32, colorBlue() ) diff --git a/src/dusk/script/module/moduleplatform.h b/src/dusk/script/module/moduleplatform.h index d4b8b18..a45f569 100644 --- a/src/dusk/script/module/moduleplatform.h +++ b/src/dusk/script/module/moduleplatform.h @@ -8,18 +8,20 @@ #pragma once #include "script/scriptcontext.h" #include "assert/assert.h" +#include "script/module/moduleplatformplatform.h" #ifndef DUSK_TARGET_SYSTEM #error "DUSK_TARGET_SYSTEM must be defined" #endif -#define PLATFORM_VALUE "PLATFORM = '" DUSK_TARGET_SYSTEM "'\n" +#define MODULE_PLATFORM_VALUE "PLATFORM = '" DUSK_TARGET_SYSTEM "'\n" void modulePlatform(scriptcontext_t *ctx) { assertNotNull(ctx, "Script context cannot be NULL"); - scriptContextExec(ctx, PLATFORM_VALUE); - #if DOLPHIN - scriptContextExec(ctx, "DOLPHIN = true\n"); + scriptContextExec(ctx, MODULE_PLATFORM_VALUE); + + #ifdef modulePlatformPlatform + modulePlatformPlatform(ctx); #endif } \ No newline at end of file diff --git a/src/duskdolphin/script/module/moduleplatformdolphin.h b/src/duskdolphin/script/module/moduleplatformdolphin.h new file mode 100644 index 0000000..759f0f4 --- /dev/null +++ b/src/duskdolphin/script/module/moduleplatformdolphin.h @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "script/scriptcontext.h" + +void modulePlatformDolphin(scriptcontext_t *ctx) { + scriptContextExec(ctx, "DOLPHIN = true\n"); +} \ No newline at end of file diff --git a/src/duskdolphin/script/module/moduleplatformplatform.h b/src/duskdolphin/script/module/moduleplatformplatform.h new file mode 100644 index 0000000..b02e99e --- /dev/null +++ b/src/duskdolphin/script/module/moduleplatformplatform.h @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "moduleplatformdolphin.h" + +#define modulePlatformPlatform modulePlatformDolphin \ No newline at end of file diff --git a/src/dusklinux/input/inputlinux.c b/src/dusklinux/input/inputlinux.c index bdaba27..350672e 100644 --- a/src/dusklinux/input/inputlinux.c +++ b/src/dusklinux/input/inputlinux.c @@ -9,30 +9,30 @@ inputbuttondata_t INPUT_BUTTON_DATA[] = { #ifdef DUSK_INPUT_GAMEPAD - { .name = "a", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_A } }, - { .name = "b", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_B } }, - { .name = "x", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_X } }, - { .name = "y", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_Y } }, - { .name = "start", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_START } }, - { .name = "back", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_BACK } }, - { .name = "up", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_UP } }, - { .name = "down", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_DOWN } }, - { .name = "left", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_LEFT } }, - { .name = "right", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_RIGHT } }, - { .name = "l1", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_LEFTSHOULDER } }, - { .name = "r1", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER } }, - { .name = "l3", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_LEFTSTICK } }, - { .name = "r3", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_RIGHTSTICK } }, - { .name = "lstick_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = true } } }, - { .name = "lstick_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = false } } }, - { .name = "lstick_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = true } } }, - { .name = "lstick_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = false } } }, - { .name = "rstick_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_RIGHTY, .positive = true } } }, - { .name = "rstick_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_RIGHTY, .positive = false } } }, - { .name = "rstick_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_RIGHTX, .positive = true } } }, - { .name = "rstick_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_RIGHTX, .positive = false } } }, - { .name = "l2", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_TRIGGERLEFT, .positive = true } } }, - { .name = "r2", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_TRIGGERRIGHT, .positive = true } } }, + { .name = "gamepad_a", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_A } }, + { .name = "gamepad_b", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_B } }, + { .name = "gamepad_x", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_X } }, + { .name = "gamepad_y", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_Y } }, + { .name = "gamepad_start", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_START } }, + { .name = "gamepad_back", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_BACK } }, + { .name = "gamepad_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_UP } }, + { .name = "gamepad_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_DOWN } }, + { .name = "gamepad_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_LEFT } }, + { .name = "gamepad_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_RIGHT } }, + { .name = "gamepad_l1", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_LEFTSHOULDER } }, + { .name = "gamepad_r1", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER } }, + { .name = "gamepad_l3", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_LEFTSTICK } }, + { .name = "gamepad_r3", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_RIGHTSTICK } }, + { .name = "gamepad_lstick_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = true } } }, + { .name = "gamepad_lstick_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = false } } }, + { .name = "gamepad_lstick_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = true } } }, + { .name = "gamepad_lstick_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = false } } }, + { .name = "gamepad_rstick_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_RIGHTY, .positive = true } } }, + { .name = "gamepad_rstick_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_RIGHTY, .positive = false } } }, + { .name = "gamepad_rstick_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_RIGHTX, .positive = true } } }, + { .name = "gamepad_rstick_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_RIGHTX, .positive = false } } }, + { .name = "gamepad_l2", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_TRIGGERLEFT, .positive = true } } }, + { .name = "gamepad_r2", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_TRIGGERRIGHT, .positive = true } } }, #endif diff --git a/src/dusklinux/script/module/moduleplatformlinux.h b/src/dusklinux/script/module/moduleplatformlinux.h new file mode 100644 index 0000000..6dfd383 --- /dev/null +++ b/src/dusklinux/script/module/moduleplatformlinux.h @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "script/scriptcontext.h" + +void modulePlatformLinux(scriptcontext_t *ctx) { + scriptContextExec(ctx, "LINUX = true\n"); +} \ No newline at end of file diff --git a/src/dusklinux/script/module/moduleplatformplatform.h b/src/dusklinux/script/module/moduleplatformplatform.h new file mode 100644 index 0000000..4fb3c6e --- /dev/null +++ b/src/dusklinux/script/module/moduleplatformplatform.h @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "moduleplatformlinux.h" + +#define modulePlatformPlatform modulePlatformLinux \ No newline at end of file diff --git a/src/duskpsp/script/module/moduleplatformplatform.h b/src/duskpsp/script/module/moduleplatformplatform.h new file mode 100644 index 0000000..d718a08 --- /dev/null +++ b/src/duskpsp/script/module/moduleplatformplatform.h @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "moduleplatformpsp.h" + +#define modulePlatformPlatform modulePlatformPSP \ No newline at end of file diff --git a/src/duskpsp/script/module/moduleplatformpsp.h b/src/duskpsp/script/module/moduleplatformpsp.h new file mode 100644 index 0000000..4030e5c --- /dev/null +++ b/src/duskpsp/script/module/moduleplatformpsp.h @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "script/scriptcontext.h" + +void modulePlatformPSP(scriptcontext_t *ctx) { + scriptContextExec(ctx, "PSP = true\n"); +} \ No newline at end of file