Skip to content
Permalink
Browse files

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
  • Loading branch information
SmallJoker committed Feb 17, 2020
1 parent 6958071 commit e8a8185d24897ccf964327017effae81aa1c9d40
Showing with 29 additions and 9 deletions.
  1. +2 −2 src/content/subgames.cpp
  2. +0 −7 src/defaultsettings.cpp
  3. +1 −0 src/map_settings_manager.cpp
  4. +24 −0 src/settings.cpp
  5. +2 −0 src/settings.h
@@ -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 @@ class Settings {
**************/

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,

0 comments on commit e8a8185

Please sign in to comment.
You can’t perform that action at this time.