forked from Mirrorlandia_minetest/minetest
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:
parent
6958071f49
commit
e8a8185d24
@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "settings.h"
|
||||
#include "log.h"
|
||||
#include "util/strfnd.h"
|
||||
#include "defaultsettings.h" // for override_default_settings
|
||||
#include "defaultsettings.h" // for set_default_settings
|
||||
#include "mapgen/mapgen.h" // for MapgenParams
|
||||
#include "util/string.h"
|
||||
|
||||
@ -298,7 +298,7 @@ bool loadGameConfAndInitWorld(const std::string &path, const SubgameSpec &gamesp
|
||||
set_default_settings(g_settings);
|
||||
Settings game_defaults;
|
||||
getGameMinetestConfig(gamespec.path, game_defaults);
|
||||
override_default_settings(g_settings, &game_defaults);
|
||||
g_settings->overrideDefaults(&game_defaults);
|
||||
|
||||
infostream << "Initializing world at " << path << std::endl;
|
||||
|
||||
|
@ -498,10 +498,3 @@ void set_default_settings(Settings *settings)
|
||||
#endif
|
||||
}
|
||||
|
||||
void override_default_settings(Settings *settings, Settings *from)
|
||||
{
|
||||
std::vector<std::string> names = from->getNames();
|
||||
for (const auto &name : names) {
|
||||
settings->setDefault(name, from->get(name));
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ MapSettingsManager::MapSettingsManager(Settings *user_settings,
|
||||
m_user_settings(user_settings)
|
||||
{
|
||||
assert(m_user_settings != NULL);
|
||||
Mapgen::setDefaultSettings(m_map_settings);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
@ -222,6 +222,8 @@ public:
|
||||
**************/
|
||||
|
||||
void setDefault(const std::string &name, const FlagDesc *flagdesc, u32 flags);
|
||||
// Takes the provided setting values and uses them as new defaults
|
||||
void overrideDefaults(Settings *other);
|
||||
const FlagDesc *getFlagDescFallback(const std::string &name) const;
|
||||
|
||||
void registerChangedCallback(const std::string &name,
|
||||
|
Loading…
Reference in New Issue
Block a user