diff --git a/src/data/settings.cpp b/src/data/settings.cpp index 76d20dac..36d1a605 100644 --- a/src/data/settings.cpp +++ b/src/data/settings.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -218,7 +219,18 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(Settings) { REFLECT(export_options); } +void Settings::clear() { + recent_sets.clear(); + game_settings.clear(); + stylesheet_settings.clear(); + default_stylesheet_settings = StyleSheetSettings(); + export_options.clear(); +} + void Settings::read() { + // clear current settings, otherwise we duplicate vector elements + clear(); + // (re)load settings String filename = settingsFile(); if (wxFileExists(filename)) { // settings file not existing is not an error diff --git a/src/data/settings.hpp b/src/data/settings.hpp index b4124e21..274008d6 100644 --- a/src/data/settings.hpp +++ b/src/data/settings.hpp @@ -171,6 +171,8 @@ class Settings { private: /// Name of the settings file String settingsFile(); + /// Clear settings before reading them + void clear(); DECLARE_REFLECTION(); }; diff --git a/src/util/delayed_index_maps.hpp b/src/util/delayed_index_maps.hpp index aa694391..73fc0b1a 100644 --- a/src/util/delayed_index_maps.hpp +++ b/src/util/delayed_index_maps.hpp @@ -32,6 +32,11 @@ IndexMap& DelayedIndexMaps::get(const String& name, const return item->read_data; } +template +void DelayedIndexMaps::clear() { + data.clear(); +} + // ----------------------------------------------------------------------------- : Reflection // custom reflection : it's a template class diff --git a/src/util/index_map.hpp b/src/util/index_map.hpp index fbce1c08..aaf1e4f3 100644 --- a/src/util/index_map.hpp +++ b/src/util/index_map.hpp @@ -148,6 +148,8 @@ class DelayedIndexMaps { public: /// Get the data for a specific name. Initialize the map with init_with (if it is not alread initialized) IndexMap& get(const String& name, const vector& init_with); + /// Clear the delayed index map + void clear(); private: map > > data; friend class Reader;