Fix #12147: reset all saved settings to their default before loading a game (#12210)

This commit is contained in:
Patric Stout
2024-03-02 16:05:43 +01:00
committed by GitHub
parent aff09306de
commit 8f22066b9a
3 changed files with 39 additions and 4 deletions

View File

@@ -137,6 +137,11 @@ struct SettingDesc {
* @return true iff the value is the default value.
*/
virtual bool IsDefaultValue(void *object) const = 0;
/**
* Reset the setting to its default value.
*/
virtual void ResetToDefault(void *object) const = 0;
};
/** Base integer type, including boolean, settings. Only these are shown in the settings UI. */
@@ -236,6 +241,7 @@ struct IntSettingDesc : SettingDesc {
void ParseValue(const IniItem *item, void *object) const override;
bool IsSameValue(const IniItem *item, void *object) const override;
bool IsDefaultValue(void *object) const override;
void ResetToDefault(void *object) const override;
int32_t Read(const void *object) const;
private:
@@ -332,6 +338,7 @@ struct StringSettingDesc : SettingDesc {
void ParseValue(const IniItem *item, void *object) const override;
bool IsSameValue(const IniItem *item, void *object) const override;
bool IsDefaultValue(void *object) const override;
void ResetToDefault(void *object) const override;
const std::string &Read(const void *object) const;
private:
@@ -350,6 +357,7 @@ struct ListSettingDesc : SettingDesc {
void ParseValue(const IniItem *item, void *object) const override;
bool IsSameValue(const IniItem *item, void *object) const override;
bool IsDefaultValue(void *object) const override;
void ResetToDefault(void *object) const override;
};
/** Placeholder for settings that have been removed, but might still linger in the savegame. */
@@ -361,6 +369,7 @@ struct NullSettingDesc : SettingDesc {
void ParseValue(const IniItem *, void *) const override { NOT_REACHED(); }
bool IsSameValue(const IniItem *, void *) const override { NOT_REACHED(); }
bool IsDefaultValue(void *) const override { NOT_REACHED(); }
void ResetToDefault(void *) const override { NOT_REACHED(); }
};
typedef std::variant<IntSettingDesc, BoolSettingDesc, OneOfManySettingDesc, ManyOfManySettingDesc, StringSettingDesc, ListSettingDesc, NullSettingDesc> SettingVariant;