1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

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
This commit is contained in:
SmallJoker 2020-02-17 19:26:32 +01:00 committed by GitHub
parent 6958071f49
commit e8a8185d24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 9 deletions

View file

@ -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);