Add console command to list settings and show current and default values
This commit is contained in:
@@ -2340,7 +2340,20 @@ DEF_CONSOLE_CMD(ConListSettings)
|
|||||||
|
|
||||||
if (argc > 2) return false;
|
if (argc > 2) return false;
|
||||||
|
|
||||||
IConsoleListSettings((argc == 2) ? argv[1] : nullptr);
|
IConsoleListSettings((argc == 2) ? argv[1] : nullptr, false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_CONSOLE_CMD(ConListSettingsDefaults)
|
||||||
|
{
|
||||||
|
if (argc == 0) {
|
||||||
|
IConsoleHelp("List settings and also show default value. Usage: 'list_settings_def [<pre-filter>]'");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc > 2) return false;
|
||||||
|
|
||||||
|
IConsoleListSettings((argc == 2) ? argv[1] : nullptr, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3711,6 +3724,7 @@ void IConsoleStdLibRegister()
|
|||||||
IConsole::CmdRegister("setting", ConSetting);
|
IConsole::CmdRegister("setting", ConSetting);
|
||||||
IConsole::CmdRegister("setting_newgame", ConSettingNewgame);
|
IConsole::CmdRegister("setting_newgame", ConSettingNewgame);
|
||||||
IConsole::CmdRegister("list_settings", ConListSettings);
|
IConsole::CmdRegister("list_settings", ConListSettings);
|
||||||
|
IConsole::CmdRegister("list_settings_def", ConListSettingsDefaults);
|
||||||
IConsole::CmdRegister("gamelog", ConGamelogPrint);
|
IConsole::CmdRegister("gamelog", ConGamelogPrint);
|
||||||
IConsole::CmdRegister("rescan_newgrf", ConRescanNewGRF);
|
IConsole::CmdRegister("rescan_newgrf", ConRescanNewGRF);
|
||||||
IConsole::CmdRegister("list_dirs", ConListDirs);
|
IConsole::CmdRegister("list_dirs", ConListDirs);
|
||||||
|
@@ -379,15 +379,14 @@ char *OneOfManySettingDesc::FormatSingleValue(char *buf, const char *last, uint
|
|||||||
return strecpy(buf, this->many[id].c_str(), last);
|
return strecpy(buf, this->many[id].c_str(), last);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneOfManySettingDesc::FormatValue(char *buf, const char *last, const void *object) const
|
void OneOfManySettingDesc::FormatIntValue(char *buf, const char *last, uint32 value) const
|
||||||
{
|
{
|
||||||
uint id = (uint)this->Read(object);
|
this->FormatSingleValue(buf, last, value);
|
||||||
this->FormatSingleValue(buf, last, id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManyOfManySettingDesc::FormatValue(char *buf, const char *last, const void *object) const
|
void ManyOfManySettingDesc::FormatIntValue(char *buf, const char *last, uint32 value) const
|
||||||
{
|
{
|
||||||
uint bitmask = (uint)this->Read(object);
|
uint bitmask = (uint)value;
|
||||||
if (bitmask == 0) {
|
if (bitmask == 0) {
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
return;
|
return;
|
||||||
@@ -766,13 +765,17 @@ static void IniSaveSettings(IniFile &ini, const SettingTable &settings_table, co
|
|||||||
void IntSettingDesc::FormatValue(char *buf, const char *last, const void *object) const
|
void IntSettingDesc::FormatValue(char *buf, const char *last, const void *object) const
|
||||||
{
|
{
|
||||||
uint32 i = (uint32)this->Read(object);
|
uint32 i = (uint32)this->Read(object);
|
||||||
seprintf(buf, last, IsSignedVarMemType(this->save.conv) ? "%d" : "%u", i);
|
this->FormatIntValue(buf, last, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoolSettingDesc::FormatValue(char *buf, const char *last, const void *object) const
|
void IntSettingDesc::FormatIntValue(char *buf, const char *last, uint32 value) const
|
||||||
{
|
{
|
||||||
bool val = this->Read(object) != 0;
|
seprintf(buf, last, IsSignedVarMemType(this->save.conv) ? "%d" : "%u", value);
|
||||||
strecpy(buf, val ? "true" : "false", last);
|
}
|
||||||
|
|
||||||
|
void BoolSettingDesc::FormatIntValue(char *buf, const char *last, uint32 value) const
|
||||||
|
{
|
||||||
|
strecpy(buf, (value != 0) ? "true" : "false", last);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IntSettingDesc::IsSameValue(const IniItem *item, void *object) const
|
bool IntSettingDesc::IsSameValue(const IniItem *item, void *object) const
|
||||||
@@ -2862,7 +2865,7 @@ void IConsoleGetSetting(const char *name, bool force_newgame)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void IConsoleListSettingsTable(const SettingTable &table, const char *prefilter)
|
static void IConsoleListSettingsTable(const SettingTable &table, const char *prefilter, bool show_defaults)
|
||||||
{
|
{
|
||||||
for (auto &sd : table) {
|
for (auto &sd : table) {
|
||||||
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) continue;
|
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) continue;
|
||||||
@@ -2870,7 +2873,15 @@ static void IConsoleListSettingsTable(const SettingTable &table, const char *pre
|
|||||||
if ((sd->flags & SF_NO_NEWGAME) && _game_mode == GM_MENU) continue;
|
if ((sd->flags & SF_NO_NEWGAME) && _game_mode == GM_MENU) continue;
|
||||||
char value[80];
|
char value[80];
|
||||||
sd->FormatValue(value, lastof(value), &GetGameSettings());
|
sd->FormatValue(value, lastof(value), &GetGameSettings());
|
||||||
IConsolePrintF(CC_DEFAULT, "%s = %s", sd->name, value);
|
if (show_defaults && sd->IsIntSetting()) {
|
||||||
|
const IntSettingDesc *int_setting = sd->AsIntSetting();
|
||||||
|
char defvalue[80];
|
||||||
|
int_setting->FormatIntValue(defvalue, lastof(defvalue), int_setting->def);
|
||||||
|
TextColour colour = (int_setting->Read(&GetGameSettings()) != int_setting->def) ? CC_WARNING : CC_DEFAULT;
|
||||||
|
IConsolePrintF(colour, "%s = %s (default: %s)", sd->name, value, defvalue);
|
||||||
|
} else {
|
||||||
|
IConsolePrintF(CC_DEFAULT, "%s = %s", sd->name, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2879,18 +2890,18 @@ static void IConsoleListSettingsTable(const SettingTable &table, const char *pre
|
|||||||
*
|
*
|
||||||
* @param prefilter If not \c nullptr, only list settings with names that begin with \a prefilter prefix
|
* @param prefilter If not \c nullptr, only list settings with names that begin with \a prefilter prefix
|
||||||
*/
|
*/
|
||||||
void IConsoleListSettings(const char *prefilter)
|
void IConsoleListSettings(const char *prefilter, bool show_defaults)
|
||||||
{
|
{
|
||||||
IConsolePrintF(CC_WARNING, "All settings with their current value:");
|
IConsolePrintF(CC_WARNING, "All settings with their current %s:", show_defaults ? "and default values" : "value");
|
||||||
|
|
||||||
for (auto &table : _generic_setting_tables) {
|
for (auto &table : _generic_setting_tables) {
|
||||||
IConsoleListSettingsTable(table, prefilter);
|
IConsoleListSettingsTable(table, prefilter, show_defaults);
|
||||||
}
|
}
|
||||||
for (auto &table : _private_setting_tables) {
|
for (auto &table : _private_setting_tables) {
|
||||||
IConsoleListSettingsTable(table, prefilter);
|
IConsoleListSettingsTable(table, prefilter, show_defaults);
|
||||||
}
|
}
|
||||||
for (auto &table : _secrets_setting_tables) {
|
for (auto &table : _secrets_setting_tables) {
|
||||||
IConsoleListSettingsTable(table, prefilter);
|
IConsoleListSettingsTable(table, prefilter, show_defaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
IConsolePrintF(CC_WARNING, "Use 'setting' command to change a value");
|
IConsolePrintF(CC_WARNING, "Use 'setting' command to change a value");
|
||||||
|
@@ -19,7 +19,7 @@ struct IniFile;
|
|||||||
void IConsoleSetSetting(const char *name, const char *value, bool force_newgame = false);
|
void IConsoleSetSetting(const char *name, const char *value, bool force_newgame = false);
|
||||||
void IConsoleSetSetting(const char *name, int32 value);
|
void IConsoleSetSetting(const char *name, int32 value);
|
||||||
void IConsoleGetSetting(const char *name, bool force_newgame = false);
|
void IConsoleGetSetting(const char *name, bool force_newgame = false);
|
||||||
void IConsoleListSettings(const char *prefilter);
|
void IConsoleListSettings(const char *prefilter, bool show_defaults);
|
||||||
|
|
||||||
void LoadFromConfig(bool minimal = false);
|
void LoadFromConfig(bool minimal = false);
|
||||||
void SaveToConfig();
|
void SaveToConfig();
|
||||||
|
@@ -220,6 +220,7 @@ struct IntSettingDesc : SettingDesc {
|
|||||||
|
|
||||||
virtual size_t ParseValue(const char *str) const;
|
virtual size_t ParseValue(const char *str) const;
|
||||||
void FormatValue(char *buf, const char *last, const void *object) const override;
|
void FormatValue(char *buf, const char *last, const void *object) const override;
|
||||||
|
virtual void FormatIntValue(char *buf, const char *last, uint32 value) const;
|
||||||
void ParseValue(const IniItem *item, void *object) const override;
|
void ParseValue(const IniItem *item, void *object) const override;
|
||||||
bool IsSameValue(const IniItem *item, void *object) const override;
|
bool IsSameValue(const IniItem *item, void *object) const override;
|
||||||
int32 Read(const void *object) const;
|
int32 Read(const void *object) const;
|
||||||
@@ -239,7 +240,7 @@ struct BoolSettingDesc : IntSettingDesc {
|
|||||||
|
|
||||||
bool IsBoolSetting() const override { return true; }
|
bool IsBoolSetting() const override { return true; }
|
||||||
size_t ParseValue(const char *str) const override;
|
size_t ParseValue(const char *str) const override;
|
||||||
void FormatValue(char *buf, const char *last, const void *object) const override;
|
void FormatIntValue(char *buf, const char *last, uint32 value) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** One of many setting. */
|
/** One of many setting. */
|
||||||
@@ -264,7 +265,7 @@ struct OneOfManySettingDesc : IntSettingDesc {
|
|||||||
char *FormatSingleValue(char *buf, const char *last, uint id) const;
|
char *FormatSingleValue(char *buf, const char *last, uint id) const;
|
||||||
|
|
||||||
size_t ParseValue(const char *str) const override;
|
size_t ParseValue(const char *str) const override;
|
||||||
void FormatValue(char *buf, const char *last, const void *object) const override;
|
void FormatIntValue(char *buf, const char *last, uint32 value) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Many of many setting. */
|
/** Many of many setting. */
|
||||||
@@ -278,7 +279,7 @@ struct ManyOfManySettingDesc : OneOfManySettingDesc {
|
|||||||
virtual ~ManyOfManySettingDesc() {}
|
virtual ~ManyOfManySettingDesc() {}
|
||||||
|
|
||||||
size_t ParseValue(const char *str) const override;
|
size_t ParseValue(const char *str) const override;
|
||||||
void FormatValue(char *buf, const char *last, const void *object) const override;
|
void FormatIntValue(char *buf, const char *last, uint32 value) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** String settings. */
|
/** String settings. */
|
||||||
|
Reference in New Issue
Block a user