Updated bind command

This commit is contained in:
2026-04-20 12:59:25 -05:00
parent 340084dac3
commit a0fad441d0
7 changed files with 59 additions and 28 deletions
+21 -6
View File
@@ -15,16 +15,31 @@ void cmdBind(const consolecmdexec_t *exec) {
return;
}
if(exec->argc == 1) {
consolePrint("TODO: Show binds");
return;
}
inputbutton_t button = inputButtonGetByName(exec->argv[0]);
if(button.type == INPUT_BUTTON_TYPE_NONE) {
consolePrint("Unknown button \"%s\"", exec->argv[0]);
return;
}
inputBind(button, exec->argv[1]);
if(exec->argc == 1) {
// Get the button data for this button.
inputbuttondata_t *data = inputButtonGetData(button);
assertNotNull(data, "Input button not found");
inputaction_t act = data->action;
if(act == INPUT_ACTION_NULL || act >= INPUT_ACTION_COUNT) {
consolePrint("%s is not bound.", data->name);
} else {
consolePrint("%s is bound to %s.", data->name, INPUT_ACTION_IDS[act]);
}
return;
}
inputaction_t action = inputActionGetByName(exec->argv[1]);
if(action == INPUT_ACTION_COUNT) {
consolePrint("Unknown action \"%s\"", exec->argv[1]);
return;
}
inputBind(button, action);
}
+2 -3
View File
@@ -17,9 +17,7 @@
#include "console/cmd/cmdset.h"
#include "console/cmd/cmdget.h"
#include "console/cmd/cmdquit.h"
// #include "console/cmd/cmdbind.h"
// #include "console/cmd/cmdtoggleconsole.h"
#include "console/cmd/cmdbind.h"
#include "display/shader/shaderunlit.h"
#include "display/text/text.h"
#include "display/spritebatch/spritebatch.h"
@@ -40,6 +38,7 @@ void consoleInit() {
REG("echo", cmdEcho);
REG("quit", cmdQuit);
REG("exit", cmdQuit);
REG("bind", cmdBind);
#undef REG
#ifdef DUSK_CONSOLE_POSIX
+4 -8
View File
@@ -179,19 +179,15 @@ void inputBind(const inputbutton_t button, const inputaction_t act) {
assertTrue(act != INPUT_ACTION_NULL, "Cannot bind to NULL action");
// Get the button data for this button.
inputbuttondata_t *data = INPUT_BUTTON_DATA;
do {
if(memoryCompare(&data->button, &button, sizeof(inputbutton_t)) == 0) {
break;
}
data++;
} while(data->name != NULL);
assertNotNull(data->name, "Input button not found");
inputbuttondata_t *data = inputButtonGetData(button);
assertNotNull(data, "Input button not found");
// Bind the action.
data->action = act;
}
float_t inputDeadzone(const float_t rawValue, const float_t deadzone) {
if(rawValue < deadzone) return 0.0f;
return (rawValue - deadzone) / (1.0f - deadzone);
+9 -9
View File
@@ -9,14 +9,14 @@
#include "assert/assert.h"
#include "util/string.h"
// inputaction_t inputActionGetByName(const char_t *name) {
// assertNotNull(name, "name must not be NULL");
inputaction_t inputActionGetByName(const char_t *name) {
assertNotNull(name, "name must not be NULL");
// for(inputaction_t i = 0; i < INPUT_ACTION_COUNT; i++) {
// if(INPUT_ACTION_IDS[i] == NULL) continue;
// if(stringCompareInsensitive(INPUT_ACTION_IDS[i], name) != 0) continue;
// return i;
// }
for(inputaction_t i = 0; i < INPUT_ACTION_COUNT; i++) {
if(INPUT_ACTION_IDS[i] == NULL) continue;
if(stringCompareInsensitive(INPUT_ACTION_IDS[i], name) != 0) continue;
return i;
}
// return INPUT_ACTION_COUNT;
// }
return INPUT_ACTION_COUNT;
}
+1 -1
View File
@@ -26,4 +26,4 @@ typedef struct {
* @param name The name of the input action.
* @return The input action, or INPUT_ACTION_COUNT if not found.
*/
// inputaction_t inputActionGetByName(const char_t *name);
inputaction_t inputActionGetByName(const char_t *name);
+13
View File
@@ -9,6 +9,7 @@
#include "input.h"
#include "assert/assert.h"
#include "util/string.h"
#include "util/memory.h"
inputbutton_t inputButtonGetByName(const char_t *name) {
assertNotNull(name, "name must not be NULL");
@@ -26,4 +27,16 @@ inputbutton_t inputButtonGetByName(const char_t *name) {
float_t inputButtonGetValue(const inputbutton_t button) {
return inputButtonGetValuePlatform(button);
}
inputbuttondata_t * inputButtonGetData(const inputbutton_t button) {
inputbuttondata_t *data = INPUT_BUTTON_DATA;
do {
if(memoryCompare(&data->button, &button, sizeof(inputbutton_t)) == 0) {
return data;
}
data++;
} while(data->name != NULL);
return NULL;
}
+9 -1
View File
@@ -96,4 +96,12 @@ inputbutton_t inputButtonGetByName(const char_t *name);
* @param button The input button.
* @return The current value of the input button (0.0f to 1.0f).
*/
float_t inputButtonGetValue(const inputbutton_t button);
float_t inputButtonGetValue(const inputbutton_t button);
/**
* Gets the button data for a specific input button.
*
* @param button The input button to get the data for.
* @return The button data, or NULL if not found.
*/
inputbuttondata_t * inputButtonGetData(const inputbutton_t button);