Restore console, server/client stuff.

This commit is contained in:
2025-04-21 08:23:58 -05:00
parent 697b5f7ee2
commit 4aaabb3882
22 changed files with 549 additions and 47 deletions

View File

@@ -9,6 +9,7 @@
#include "assert/assert.h"
#include "util/memory.h"
#include "util/string.h"
#include "input.h"
console_t CONSOLE;
@@ -20,6 +21,8 @@ void consoleInit() {
CONSOLE.cmdGet = consoleRegCmd("get", cmdGet);
CONSOLE.cmdSet = consoleRegCmd("set", cmdSet);
consoleRegCmd("echo", cmdEcho);
consolePrint(" = Dawn Console = ");
}
consolecmd_t * consoleRegCmd(const char_t *name, consolecmdfunc_t function) {
@@ -331,37 +334,45 @@ void cmdEcho(const consolecmdexec_t *exec) {
// May move these later
void consoleUpdate() {
int32_t key = GetKeyPressed();
if(inputIsPressed(INPUT_TOGGLE_CONSOLE)) {
CONSOLE.open = !CONSOLE.open;
} else if(CONSOLE.open) {
switch(INPUT.keyPressed) {
case 0:
break;
switch(key) {
case 0:
break;
case KEY_ENTER:
consoleExec(CONSOLE.inputBuffer);
CONSOLE.inputIndex = 0;
CONSOLE.inputBuffer[0] = '\0';
break;
case KEY_ENTER:
consoleExec(CONSOLE.inputBuffer);
CONSOLE.inputIndex = 0;
CONSOLE.inputBuffer[0] = '\0';
break;
case KEY_BACKSPACE:
if(CONSOLE.inputIndex > 0) {
CONSOLE.inputIndex--;
CONSOLE.inputBuffer[CONSOLE.inputIndex] = '\0';
}
break;
case KEY_BACKSPACE:
if(CONSOLE.inputIndex > 0) {
CONSOLE.inputIndex--;
CONSOLE.inputBuffer[CONSOLE.inputIndex] = '\0';
}
break;
default:
if(key >= 32 && key <= 126 && CONSOLE.inputIndex < CONSOLE_LINE_MAX - 1) {
CONSOLE.inputBuffer[CONSOLE.inputIndex++] = (char_t)GetCharPressed();
CONSOLE.inputBuffer[CONSOLE.inputIndex] = '\0';
}
break;
default:
if(
INPUT.keyPressed >= 32 &&
INPUT.keyPressed <= 126 &&
CONSOLE.inputIndex < CONSOLE_LINE_MAX - 1
) {
CONSOLE.inputBuffer[CONSOLE.inputIndex++] = INPUT.charPressed;
CONSOLE.inputBuffer[CONSOLE.inputIndex] = '\0';
}
break;
}
}
consoleProcess();
}
void consoleDraw() {
if(!CONSOLE.open) return;
size_t i = 0;
char_t *line;
int32_t fontSize = 10;
@@ -371,7 +382,7 @@ void consoleDraw() {
i++;
continue;
}
DrawText(line, 0, i*fontSize, fontSize, BLACK);
DrawText(line, 0, i*fontSize, fontSize, YELLOW);
i++;
} while(i < CONSOLE_HISTORY_MAX);
@@ -379,6 +390,6 @@ void consoleDraw() {
CONSOLE.inputBuffer, 0,
(CONSOLE_HISTORY_MAX + 1) * fontSize,
fontSize,
BLACK
PINK
);
}