Dynamically assign script values for items and inputs
Some checks failed
Build Dusk / run-tests (push) Failing after 1m22s
Build Dusk / build-linux (push) Successful in 2m8s
Build Dusk / build-psp (push) Failing after 1m38s

This commit is contained in:
2026-01-26 08:48:17 -06:00
parent 0392dd0e7f
commit 9544d15a18
5 changed files with 55 additions and 47 deletions

View File

@@ -18,13 +18,20 @@ int moduleInputBind(lua_State *L) {
return 0;
}
if(!lua_isstring(L, 2)) {
luaL_error(L, "inputBind: Expected action name as second argument");
// Expect action ID
if(!lua_isinteger(L, 2)) {
luaL_error(L, "inputBind: Expected action ID as second argument");
return 0;
}
const char_t *strBtn = lua_tostring(L, 1);
const char_t *strAct = lua_tostring(L, 2);
const inputaction_t action = (inputaction_t)lua_tointeger(L, 2);
// Validate action
if(action < INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) {
luaL_error(L, "inputBind: Invalid action ID %d", (int)action);
return 0;
}
// Get button by name
inputbutton_t btn = inputButtonGetByName(strBtn);
@@ -33,20 +40,22 @@ int moduleInputBind(lua_State *L) {
return 0;
}
// Get action by name
inputaction_t act = inputActionGetByName(strAct);
if(act == INPUT_ACTION_COUNT) {
printf("inputBind: Unknown action name '%s'\n", strAct);
return 0;
}
inputBind(btn, act);
inputBind(btn, action);
return 0;
}
void moduleInput(scriptcontext_t *context) {
char_t buffer[128];
assertNotNull(context, "Script context cannot be NULL");
// Set input information
for(inputaction_t act = INPUT_ACTION_NULL + 1; act < INPUT_ACTION_COUNT; act++) {
const char_t *actName = INPUT_ACTION_NAMES[act];
assertStrLenMax(actName, 64, "Input action name too long for buffer");
snprintf(buffer, sizeof(buffer), "INPUT_ACTION_%s = %d\n", actName, act);
scriptContextExec(context, buffer);
}
// Input values.
scriptContextExec(context,
#if INPUT_KEYBOARD == 1