Store default settings values

7344-support-launching-the-example-suite^2
elsid 2 years ago
parent 6936c3a1c8
commit 8e487c283c
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -141,6 +141,9 @@ namespace Settings
parser.loadSettingsFile(additionalDefaults, mDefaultSettings, false, true);
}
if (!loadEditorSettings)
Settings::Values::initDefaults();
// Load "settings.cfg" or "openmw-cs.cfg" from the last config dir as user settings. This path will be used to
// save modified settings.
auto settingspath = paths.back() / userSettingsFile;

@ -23,10 +23,25 @@ namespace Settings
: mCategory(category)
, mName(name)
, mSanitizer(std::move(sanitizer))
, mValue(sanitize(Settings::Manager::get<T>(name, category)))
, mValue(sanitize(Settings::Manager::get<T>(mName, mCategory)))
{
}
SettingValue(SettingValue&& other)
: mCategory(other.mCategory)
, mName(other.mName)
, mSanitizer(std::move(other.mSanitizer))
, mDefaultValue(std::move(other.mValue))
, mValue(sanitize(Settings::Manager::get<T>(mName, mCategory)))
{
}
SettingValue(const SettingValue& other) = delete;
SettingValue& operator=(const SettingValue& other) = delete;
SettingValue& operator=(SettingValue&& other) = delete;
const T& get() const { return mValue; }
operator const T&() const { return mValue; }
@ -39,10 +54,13 @@ namespace Settings
Settings::Manager::set(mName, mCategory, mValue);
}
void reset() { set(mDefaultValue); }
private:
const std::string_view mCategory;
const std::string_view mName;
const std::unique_ptr<const Sanitizer<T>> mSanitizer;
std::unique_ptr<const Sanitizer<T>> mSanitizer;
T mDefaultValue{};
T mValue{};
T sanitize(const T& value) const

@ -1,12 +1,24 @@
#include "values.hpp"
#include <stdexcept>
namespace Settings
{
Values* Values::sValues = nullptr;
void Values::init()
void Values::initDefaults()
{
if (Values::sValues != nullptr)
throw std::logic_error("Default settings already initialized");
static Values values;
Values::sValues = &values;
}
void Values::init()
{
if (Values::sValues == nullptr)
throw std::logic_error("Default settings are not initialized");
static Values values(std::move(*Values::sValues));
Values::sValues = &values;
}
}

@ -58,6 +58,8 @@ namespace Settings
StereoViewCategory mStereoView;
PostProcessingCategory mPostProcessing;
static void initDefaults();
static void init();
private:
@ -195,7 +197,6 @@ namespace Settings
{
return values().mPostProcessing;
}
}
#endif

Loading…
Cancel
Save