#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"
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;
#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));
- }
-}
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);
**************/
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,