From a57cb9eb6a2ebbd083bf8b282239979f96990d10 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 22:54:23 +0200 Subject: [PATCH] expose rumble and led to lua --- src/lua_baselib.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 4a4558feb..86c78070b 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -20,6 +20,7 @@ #include "m_random.h" #include "s_sound.h" #include "g_game.h" +#include "g_input.h" #include "hu_stuff.h" // HU_AddChatText #include "console.h" #include "k_kart.h" // SRB2Kart @@ -3018,6 +3019,56 @@ static int lib_kSetHyuCountdown(lua_State *L) return 0; } +// G_INPUT +//////////// + +static int lib_gSetPlayerGamepadIndicatorColor(lua_State *L) +{ + INT32 player = -1; + player_t *plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); // retrieve player + UINT16 color = (UINT16)luaL_checkinteger(L, 2); // skincolor + + for (int i = 0; i < MAXSPLITSCREENPLAYERS; ++i) + { + if (plr - players == displayplayers[i]) + { + player = i; + break; + } + } + + // Not a local player + if (player == -1) return 0; + + G_SetPlayerGamepadIndicatorColor(player, color); + + return 0; +} + +static int lib_gPlayerDeviceRumble(lua_State *L) +{ + INT32 player = -1; + player_t *plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); // retrieve player + UINT16 low_strength = (INT32)luaL_checkinteger(L, 2); + UINT16 high_strength = (INT32)luaL_checkinteger(L, 3); + + for (int i = 0; i < MAXSPLITSCREENPLAYERS; ++i) + { + if (plr - players == displayplayers[i]) + { + player = i; + break; + } + } + + // Not a local player + if (player == -1) return 0; + + G_PlayerDeviceRumble(player, low_strength, high_strength); + + return 0; +} + static luaL_Reg lib[] = { {"print", lib_print}, {"chatprint", lib_chatprint}, @@ -3267,6 +3318,10 @@ static luaL_Reg lib[] = { {"K_SetIndirectItemCooldown",lib_kSetIndirectItemCountdown}, {"K_SetHyudoroCooldown",lib_kSetHyuCountdown}, + //g_input + {"G_SetPlayerGamepadIndicatorColor",lib_gSetPlayerGamepadIndicatorColor}, + {"G_PlayerDeviceRumble",lib_gPlayerDeviceRumble}, + {NULL, NULL} };