Working on cmd bind

This commit is contained in:
2025-09-07 23:53:21 -05:00
parent e32d1f0900
commit 16a0403fd4
22 changed files with 86 additions and 768 deletions

View File

@@ -8,6 +8,17 @@
#include "input.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "util/string.h"
char_t INPUT_BIND_NAMES[INPUT_BIND_COUNT][16] = {
[INPUT_BIND_UP] = "UP",
[INPUT_BIND_DOWN] = "DOWN",
[INPUT_BIND_LEFT] = "LEFT",
[INPUT_BIND_RIGHT] = "RIGHT",
[INPUT_BIND_ACCEPT] = "ACCEPT",
[INPUT_BIND_CANCEL] = "CANCEL",
[INPUT_BIND_CONSOLE] = "CONSOLE"
};
input_t INPUT;
@@ -72,4 +83,14 @@ bool_t inputPressed(const inputbind_t bind) {
bool_t inputReleased(const inputbind_t bind) {
return !inputIsDown(bind) && inputWasDown(bind);
}
inputbind_t inputBindGetByName(const char_t *name) {
assertNotNull(name, "name must not be NULL");
for(inputbind_t i = 0; i < INPUT_BIND_COUNT; i++) {
if(stringCompareInsensitive(INPUT_BIND_NAMES[i], name) == 0) {
return i;
}
}
return INPUT_BIND_COUNT;
}

View File

@@ -64,6 +64,7 @@ typedef struct {
inputbinddata_t binds[INPUT_BIND_COUNT];
} input_t;
extern char_t INPUT_BIND_NAMES[INPUT_BIND_COUNT][16];
extern input_t INPUT;
/**
@@ -123,4 +124,12 @@ bool_t inputPressed(const inputbind_t bind);
* @param bind The input bind to check.
* @return true if the bind was released this frame, false otherwise.
*/
bool_t inputReleased(const inputbind_t bind);
bool_t inputReleased(const inputbind_t bind);
/**
* Gets an input bind by its name.
*
* @param name The name of the input bind.
* @return The input bind, or INPUT_BIND_COUNT if not found.
*/
inputbind_t inputBindGetByName(const char_t *name);