summaryrefslogtreecommitdiff
path: root/src/settings.cpp
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-06-28 15:35:00 +0200
committerPatric Stout <github@truebrain.nl>2021-07-02 14:30:14 +0200
commita42251fc72d2196c26abfcc77c7fe0277798d3d4 (patch)
tree062c2687987f469c27af7d2ed3bd95e0d7dc4445 /src/settings.cpp
parent9c7a7b53a192deef9dadf7f31d68c9a76cfaf35c (diff)
downloadopenttd-a42251fc72d2196c26abfcc77c7fe0277798d3d4.tar.xz
Codechange: move network-related settings out of settings.ini
This to prepare the code to split up network-related settings into private / secrets / generic.
Diffstat (limited to 'src/settings.cpp')
-rw-r--r--src/settings.cpp43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index a7a50db11..71531b261 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -89,6 +89,21 @@ static ErrorList _settings_error_list; ///< Errors while loading minimal setting
typedef span<const SettingVariant> SettingTable;
+/**
+ * List of all the setting tables.
+ *
+ * There are a few tables that are special and not processed like the rest:
+ * - _currency_settings
+ * - _misc_settings
+ * - _company_settings
+ * - _win32_settings
+ * As such, they are not part of this list.
+ */
+static const SettingTable _setting_tables[] = {
+ _settings,
+ _network_settings,
+};
+
typedef void SettingDescProc(IniFile *ini, const SettingTable &desc, const char *grpname, void *object, bool only_startup);
typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList &list);
@@ -1542,7 +1557,11 @@ static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescP
proc(ini, _win32_settings, "win32", nullptr, only_startup);
#endif /* _WIN32 */
- proc(ini, _settings, "patches", &_settings_newgame, only_startup);
+ for (auto &table : _setting_tables) {
+ /* The name "patches" is a fallback, as every setting should sets its own group. */
+ proc(ini, table, "patches", &_settings_newgame, only_startup);
+ }
+
proc(ini, _currency_settings,"currency", &_custom_currency, only_startup);
proc(ini, _company_settings, "company", &_settings_client.company, only_startup);
@@ -1773,8 +1792,10 @@ static const SettingDesc *GetCompanySettingFromName(std::string_view name)
*/
const SettingDesc *GetSettingFromName(const std::string_view name)
{
- auto sd = GetSettingFromName(name, _settings);
- if (sd != nullptr) return sd;
+ for (auto &table : _setting_tables) {
+ auto sd = GetSettingFromName(name, table);
+ if (sd != nullptr) return sd;
+ }
return GetCompanySettingFromName(name);
}
@@ -2016,13 +2037,15 @@ void IConsoleListSettings(const char *prefilter)
{
IConsolePrint(CC_HELP, "All settings with their current value:");
- for (auto &desc : _settings) {
- const SettingDesc *sd = GetSettingDesc(desc);
- if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
- if (prefilter != nullptr && sd->name.find(prefilter) == std::string::npos) continue;
- char value[80];
- sd->FormatValue(value, lastof(value), &GetGameSettings());
- IConsolePrint(CC_DEFAULT, "{} = {}", sd->name, value);
+ for (auto &table : _setting_tables) {
+ for (auto &desc : table) {
+ const SettingDesc *sd = GetSettingDesc(desc);
+ if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
+ if (prefilter != nullptr && sd->name.find(prefilter) == std::string::npos) continue;
+ char value[80];
+ sd->FormatValue(value, lastof(value), &GetGameSettings());
+ IConsolePrint(CC_DEFAULT, "{} = {}", sd->name, value);
+ }
}
IConsolePrint(CC_HELP, "Use 'setting' command to change a value.");