mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-12-12 03:02:30 +00:00
feat(console): limited console implementation
This commit is contained in:
parent
9c3bc2203d
commit
384e52c7d1
31 changed files with 1370 additions and 47 deletions
|
|
@ -68,8 +68,7 @@ CVar* CVar::Register(const char* name, const char* help, uint32_t flags, const c
|
|||
var->m_flags |= 0x80;
|
||||
}
|
||||
|
||||
// TODO
|
||||
// ConsoleCommandRegister(var->m_key.GetString(), &CvarCommandHandler, category, help);
|
||||
ConsoleCommandRegister(name, CvarCommandHandler, CATEGORY(category), help);
|
||||
}
|
||||
|
||||
return var;
|
||||
|
|
@ -161,3 +160,49 @@ int32_t CVar::Update() {
|
|||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t CvarCommandHandler(const char* command, const char* arguments) {
|
||||
auto cvar = CVar::Lookup(command);
|
||||
STORM_ASSERT(cvar);
|
||||
|
||||
while (*arguments == ' ') {
|
||||
arguments++;
|
||||
}
|
||||
|
||||
if (arguments[0] != '\0') {
|
||||
cvar->Set(arguments, true, true, false, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto value = cvar->m_stringValue.GetString();
|
||||
|
||||
ConsoleWriteA("CVar \"%s\" is \"%s\"", DEFAULT_COLOR, command, value ? value : "");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t CvarListCommandHandler(const char* command, const char* arguments) {
|
||||
char text[256];
|
||||
char text2[256];
|
||||
|
||||
for (auto i = CVar::s_registeredCVars.Head(); i != nullptr; i = CVar::s_registeredCVars.Next(i)) {
|
||||
SStrPrintf(text, sizeof(text), " \"%s\" is \"%s\"", i->m_key.m_str, i->m_stringValue);
|
||||
|
||||
if (i->m_defaultValue.GetString()) {
|
||||
if (SStrCmp(i->m_stringValue.GetString(), i->m_defaultValue.GetString(), STORM_MAX_STR)) {
|
||||
SStrPrintf(text2, sizeof(text2), " (default \"%s\")", i->m_defaultValue);
|
||||
SStrPack(text, text2, sizeof(text));
|
||||
}
|
||||
}
|
||||
|
||||
if (i->m_resetValue.GetString()) {
|
||||
if (SStrCmp(i->m_stringValue.GetString(), i->m_resetValue.GetString(), STORM_MAX_STR)) {
|
||||
SStrPrintf(text2, sizeof(text2), " (reset \"%s\")", i->m_resetValue);
|
||||
SStrPack(text, text2, sizeof(text));
|
||||
}
|
||||
}
|
||||
|
||||
ConsoleWrite(text, DEFAULT_COLOR);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue