diff options
author | rubidium42 <rubidium@openttd.org> | 2021-05-22 13:46:39 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-27 18:49:43 +0200 |
commit | 024e584904bc9ee4ac63a8c84fa37a065974fcdc (patch) | |
tree | ad5f6679cc59d4d92439e60330abfa2f7df7cd36 /src | |
parent | c3cd4a683d34191ff9619ef962060abc1acc5fe3 (diff) | |
download | openttd-024e584904bc9ee4ac63a8c84fa37a065974fcdc.tar.xz |
Cleanup: use (config) formatting for console settings functions
Diffstat (limited to 'src')
-rw-r--r-- | src/settings.cpp | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/src/settings.cpp b/src/settings.cpp index 2964bad64..f5d4a9660 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -2204,26 +2204,20 @@ void IConsoleSetSetting(const char *name, int value) */ void IConsoleGetSetting(const char *name, bool force_newgame) { - char value[20]; const SettingDesc *sd = GetSettingFromName(name); - const void *ptr; - if (sd == nullptr) { IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name); 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) { + 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()); } else { - if (sd->cmd == SDT_BOOLX) { - seprintf(value, lastof(value), (*(const bool*)ptr != 0) ? "on" : "off"); - } else { - seprintf(value, lastof(value), sd->min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv)); - } - + char value[20]; + sd->FormatValue(value, lastof(value), object); 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); } @@ -2242,15 +2236,7 @@ void IConsoleListSettings(const char *prefilter) if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue; if (prefilter != nullptr && strstr(sd->name, prefilter) == nullptr) continue; char value[80]; - const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save); - - 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)); - } + sd->FormatValue(value, lastof(value), &GetGameSettings()); IConsolePrintF(CC_DEFAULT, "%s = %s", sd->name, value); } |