diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2020-02-17 19:26:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-17 19:26:32 +0100 |
commit | e8a8185d24897ccf964327017effae81aa1c9d40 (patch) | |
tree | 0aec3d4406a7bcf1bea0fb9b32e3ac9dd8be5f78 /src/settings.cpp | |
parent | 6958071f497c8f059429343339ad3818ed3cfed1 (diff) | |
download | minetest-e8a8185d24897ccf964327017effae81aa1c9d40.tar.gz minetest-e8a8185d24897ccf964327017effae81aa1c9d40.tar.bz2 minetest-e8a8185d24897ccf964327017effae81aa1c9d40.zip |
Settings: Fix game minetest.conf flags overriding defaults (#9404)
The game minetest.conf flags directly overwrote the global minetest.conf default values, resulting in unwanted erased mapgen flags.
* Fix set_mapgen_setting
Diffstat (limited to 'src/settings.cpp')
-rw-r--r-- | src/settings.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/settings.cpp b/src/settings.cpp index 3728fabf2..55404319e 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1048,6 +1048,30 @@ void Settings::setDefault(const std::string &name, const FlagDesc *flagdesc, setDefault(name, writeFlagString(flags, flagdesc, U32_MAX)); } +void Settings::overrideDefaults(Settings *other) +{ + for (const auto &setting : other->m_settings) { + if (setting.second.is_group) { + setGroupDefault(setting.first, setting.second.group); + continue; + } + const FlagDesc *flagdesc = getFlagDescFallback(setting.first); + if (flagdesc) { + // Flags cannot be copied directly. + // 1) Get the current set flags + u32 flags = getFlagStr(setting.first, flagdesc, nullptr); + // 2) Set the flags as defaults + other->setDefault(setting.first, flagdesc, flags); + // 3) Get the newly set flags and override the default setting value + setDefault(setting.first, flagdesc, + other->getFlagStr(setting.first, flagdesc, nullptr)); + continue; + } + // Also covers FlagDesc settings + setDefault(setting.first, setting.second.value); + } +} + const FlagDesc *Settings::getFlagDescFallback(const std::string &name) const { auto it = m_flags.find(name); |