Working on cmd bind
This commit is contained in:
35
src/console/cmd/cmdbind.h
Normal file
35
src/console/cmd/cmdbind.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "console/console.h"
|
||||
#include "input/input.h"
|
||||
|
||||
void cmdBind(const consolecmdexec_t *exec) {
|
||||
if(exec->argc < 1) {
|
||||
consolePrint("Expected 1 argument: <key> <command]");
|
||||
return;
|
||||
}
|
||||
|
||||
if(exec->argc == 1) {
|
||||
consolePrint("TODO: Show binds");
|
||||
// consolePrint("Current binds:");
|
||||
// inputbinddata_t *data = INPUT.binds;
|
||||
// do {
|
||||
|
||||
// } while(data < INPUT.binds + INPUT_BIND_COUNT);
|
||||
return;
|
||||
}
|
||||
|
||||
inputbind_t bind = inputBindGetByName(exec->argv[1]);
|
||||
if(bind == INPUT_BIND_COUNT) {
|
||||
consolePrint("Unknown bind \"%s\"", exec->argv[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
consolePrint("test");
|
||||
}
|
@@ -14,6 +14,7 @@
|
||||
#include "console/cmd/cmdset.h"
|
||||
#include "console/cmd/cmdget.h"
|
||||
#include "console/cmd/cmdexec.h"
|
||||
#include "console/cmd/cmdbind.h"
|
||||
#include "input/input.h"
|
||||
|
||||
console_t CONSOLE;
|
||||
@@ -27,6 +28,7 @@ void consoleInit() {
|
||||
consoleRegCmd("quit", cmdQuit);
|
||||
consoleRegCmd("echo", cmdEcho);
|
||||
consoleRegCmd("exec", cmdExec);
|
||||
consoleRegCmd("bind", cmdBind);
|
||||
|
||||
consolePrint(" = Dawn Console = ");
|
||||
|
||||
@@ -284,7 +286,7 @@ void consoleExec(const char_t *line) {
|
||||
}
|
||||
|
||||
if(exec->cmd == NULL) {
|
||||
consolePrint("Command not found", exec->command);
|
||||
consolePrint("Command \"%s\" not found", exec->command);
|
||||
exec = NULL;
|
||||
state = CONSOLE_EXEC_STATE_INITIAL;
|
||||
break;
|
||||
|
@@ -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;
|
||||
}
|
@@ -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);
|
@@ -27,6 +27,12 @@ int stringCompare(const char_t *str1, const char_t *str2) {
|
||||
return strcmp(str1, str2);
|
||||
}
|
||||
|
||||
int stringCompareInsensitive(const char_t *str1, const char_t *str2) {
|
||||
assertNotNull(str1, "str1 must not be NULL");
|
||||
assertNotNull(str2, "str2 must not be NULL");
|
||||
return strcasecmp(str1, str2);
|
||||
}
|
||||
|
||||
void stringTrim(char_t *str) {
|
||||
assertNotNull(str, "str must not be NULL");
|
||||
|
||||
|
@@ -36,6 +36,16 @@ void stringCopy(char_t *dest, const char_t *src, const size_t destSize);
|
||||
*/
|
||||
int stringCompare(const char_t *str1, const char_t *str2);
|
||||
|
||||
/**
|
||||
* Compares two strings, ignoring case.
|
||||
*
|
||||
* @param str1 The first string.
|
||||
* @param str2 The second string.
|
||||
* @return 0 if the strings are equal, -1 if str1 is less than str2, 1 if str1
|
||||
* is greater than str2.
|
||||
*/
|
||||
int stringCompareInsensitive(const char_t *str1, const char_t *str2);
|
||||
|
||||
/**
|
||||
* Trims whitespace from the beginning and end of a string.
|
||||
*
|
||||
|
Reference in New Issue
Block a user