Updated bind command
This commit is contained in:
@@ -15,16 +15,31 @@ void cmdBind(const consolecmdexec_t *exec) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(exec->argc == 1) {
|
|
||||||
consolePrint("TODO: Show binds");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
inputbutton_t button = inputButtonGetByName(exec->argv[0]);
|
inputbutton_t button = inputButtonGetByName(exec->argv[0]);
|
||||||
if(button.type == INPUT_BUTTON_TYPE_NONE) {
|
if(button.type == INPUT_BUTTON_TYPE_NONE) {
|
||||||
consolePrint("Unknown button \"%s\"", exec->argv[0]);
|
consolePrint("Unknown button \"%s\"", exec->argv[0]);
|
||||||
return;
|
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);
|
||||||
}
|
}
|
||||||
@@ -17,9 +17,7 @@
|
|||||||
#include "console/cmd/cmdset.h"
|
#include "console/cmd/cmdset.h"
|
||||||
#include "console/cmd/cmdget.h"
|
#include "console/cmd/cmdget.h"
|
||||||
#include "console/cmd/cmdquit.h"
|
#include "console/cmd/cmdquit.h"
|
||||||
// #include "console/cmd/cmdbind.h"
|
#include "console/cmd/cmdbind.h"
|
||||||
// #include "console/cmd/cmdtoggleconsole.h"
|
|
||||||
|
|
||||||
#include "display/shader/shaderunlit.h"
|
#include "display/shader/shaderunlit.h"
|
||||||
#include "display/text/text.h"
|
#include "display/text/text.h"
|
||||||
#include "display/spritebatch/spritebatch.h"
|
#include "display/spritebatch/spritebatch.h"
|
||||||
@@ -40,6 +38,7 @@ void consoleInit() {
|
|||||||
REG("echo", cmdEcho);
|
REG("echo", cmdEcho);
|
||||||
REG("quit", cmdQuit);
|
REG("quit", cmdQuit);
|
||||||
REG("exit", cmdQuit);
|
REG("exit", cmdQuit);
|
||||||
|
REG("bind", cmdBind);
|
||||||
#undef REG
|
#undef REG
|
||||||
|
|
||||||
#ifdef DUSK_CONSOLE_POSIX
|
#ifdef DUSK_CONSOLE_POSIX
|
||||||
|
|||||||
@@ -179,19 +179,15 @@ void inputBind(const inputbutton_t button, const inputaction_t act) {
|
|||||||
assertTrue(act != INPUT_ACTION_NULL, "Cannot bind to NULL action");
|
assertTrue(act != INPUT_ACTION_NULL, "Cannot bind to NULL action");
|
||||||
|
|
||||||
// Get the button data for this button.
|
// Get the button data for this button.
|
||||||
inputbuttondata_t *data = INPUT_BUTTON_DATA;
|
inputbuttondata_t *data = inputButtonGetData(button);
|
||||||
do {
|
assertNotNull(data, "Input button not found");
|
||||||
if(memoryCompare(&data->button, &button, sizeof(inputbutton_t)) == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
data++;
|
|
||||||
} while(data->name != NULL);
|
|
||||||
assertNotNull(data->name, "Input button not found");
|
|
||||||
|
|
||||||
// Bind the action.
|
// Bind the action.
|
||||||
data->action = act;
|
data->action = act;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
float_t inputDeadzone(const float_t rawValue, const float_t deadzone) {
|
float_t inputDeadzone(const float_t rawValue, const float_t deadzone) {
|
||||||
if(rawValue < deadzone) return 0.0f;
|
if(rawValue < deadzone) return 0.0f;
|
||||||
return (rawValue - deadzone) / (1.0f - deadzone);
|
return (rawValue - deadzone) / (1.0f - deadzone);
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
|
|
||||||
// inputaction_t inputActionGetByName(const char_t *name) {
|
inputaction_t inputActionGetByName(const char_t *name) {
|
||||||
// assertNotNull(name, "name must not be NULL");
|
assertNotNull(name, "name must not be NULL");
|
||||||
|
|
||||||
// for(inputaction_t i = 0; i < INPUT_ACTION_COUNT; i++) {
|
for(inputaction_t i = 0; i < INPUT_ACTION_COUNT; i++) {
|
||||||
// if(INPUT_ACTION_IDS[i] == NULL) continue;
|
if(INPUT_ACTION_IDS[i] == NULL) continue;
|
||||||
// if(stringCompareInsensitive(INPUT_ACTION_IDS[i], name) != 0) continue;
|
if(stringCompareInsensitive(INPUT_ACTION_IDS[i], name) != 0) continue;
|
||||||
// return i;
|
return i;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// return INPUT_ACTION_COUNT;
|
return INPUT_ACTION_COUNT;
|
||||||
// }
|
}
|
||||||
@@ -26,4 +26,4 @@ typedef struct {
|
|||||||
* @param name The name of the input action.
|
* @param name The name of the input action.
|
||||||
* @return The input action, or INPUT_ACTION_COUNT if not found.
|
* @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);
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
|
#include "util/memory.h"
|
||||||
|
|
||||||
inputbutton_t inputButtonGetByName(const char_t *name) {
|
inputbutton_t inputButtonGetByName(const char_t *name) {
|
||||||
assertNotNull(name, "name must not be NULL");
|
assertNotNull(name, "name must not be NULL");
|
||||||
@@ -27,3 +28,15 @@ inputbutton_t inputButtonGetByName(const char_t *name) {
|
|||||||
float_t inputButtonGetValue(const inputbutton_t button) {
|
float_t inputButtonGetValue(const inputbutton_t button) {
|
||||||
return inputButtonGetValuePlatform(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;
|
||||||
|
}
|
||||||
@@ -97,3 +97,11 @@ inputbutton_t inputButtonGetByName(const char_t *name);
|
|||||||
* @return The current value of the input button (0.0f to 1.0f).
|
* @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);
|
||||||
Reference in New Issue
Block a user