Cleanup: use (config) formatting for console settings functions

This commit is contained in:
rubidium42 2021-05-22 13:46:39 +02:00 committed by rubidium42
parent c3cd4a683d
commit 024e584904
1 changed files with 5 additions and 19 deletions

View File

@ -2204,26 +2204,20 @@ void IConsoleSetSetting(const char *name, int value)
*/ */
void IConsoleGetSetting(const char *name, bool force_newgame) void IConsoleGetSetting(const char *name, bool force_newgame)
{ {
char value[20];
const SettingDesc *sd = GetSettingFromName(name); const SettingDesc *sd = GetSettingFromName(name);
const void *ptr;
if (sd == nullptr) { if (sd == nullptr) {
IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name); IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
return; return;
} }
ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save); const void *object = (_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game;
if (sd->cmd == SDT_STDSTRING) { if (sd->cmd == SDT_STDSTRING) {
const void *ptr = GetVariableAddress(object, &sd->save);
IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, reinterpret_cast<const std::string *>(ptr)->c_str()); IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, reinterpret_cast<const std::string *>(ptr)->c_str());
} else { } else {
if (sd->cmd == SDT_BOOLX) { char value[20];
seprintf(value, lastof(value), (*(const bool*)ptr != 0) ? "on" : "off"); sd->FormatValue(value, lastof(value), object);
} else {
seprintf(value, lastof(value), sd->min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
}
IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s' (min: %s%d, max: %u)", IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s' (min: %s%d, max: %u)",
name, value, (sd->flags & SGF_0ISDISABLED) ? "(0) " : "", sd->min, sd->max); name, value, (sd->flags & SGF_0ISDISABLED) ? "(0) " : "", sd->min, sd->max);
} }
@ -2242,15 +2236,7 @@ void IConsoleListSettings(const char *prefilter)
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue; if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
if (prefilter != nullptr && strstr(sd->name, prefilter) == nullptr) continue; if (prefilter != nullptr && strstr(sd->name, prefilter) == nullptr) continue;
char value[80]; char value[80];
const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save); sd->FormatValue(value, lastof(value), &GetGameSettings());
if (sd->cmd == SDT_BOOLX) {
seprintf(value, lastof(value), (*(const bool *)ptr != 0) ? "on" : "off");
} else if (sd->cmd == SDT_STDSTRING) {
seprintf(value, lastof(value), "%s", reinterpret_cast<const std::string *>(ptr)->c_str());
} else {
seprintf(value, lastof(value), sd->min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
}
IConsolePrintF(CC_DEFAULT, "%s = %s", sd->name, value); IConsolePrintF(CC_DEFAULT, "%s = %s", sd->name, value);
} }