aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2020-02-17 19:26:32 +0100
committerGitHub <noreply@github.com>2020-02-17 19:26:32 +0100
commite8a8185d24897ccf964327017effae81aa1c9d40 (patch)
tree0aec3d4406a7bcf1bea0fb9b32e3ac9dd8be5f78
parent6958071f497c8f059429343339ad3818ed3cfed1 (diff)
downloadminetest-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
-rw-r--r--src/content/subgames.cpp4
-rw-r--r--src/defaultsettings.cpp7
-rw-r--r--src/map_settings_manager.cpp1
-rw-r--r--src/settings.cpp24
-rw-r--r--src/settings.h2
5 files changed, 29 insertions, 9 deletions
diff --git a/src/content/subgames.cpp b/src/content/subgames.cpp
index 39cdc056f..bf947cf85 100644
--- a/src/content/subgames.cpp
+++ b/src/content/subgames.cpp
@@ -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;
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index 754ce3547..b6e385a90 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -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));
- }
-}
diff --git a/src/map_settings_manager.cpp b/src/map_settings_manager.cpp
index a0ff1c754..7ef4bf12e 100644
--- a/src/map_settings_manager.cpp
+++ b/src/map_settings_manager.cpp
@@ -32,6 +32,7 @@ MapSettingsManager::MapSettingsManager(Settings *user_settings,
m_user_settings(user_settings)
{
assert(m_user_settings != NULL);
+ Mapgen::setDefaultSettings(m_map_settings);
}
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);
diff --git a/src/settings.h b/src/settings.h
index b42e36d10..0c9a155db 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -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,