Add setting flag to run string setting change callbacks on config load

pull/352/head
Jonathan G Rennison 2 years ago
parent 26eca815d3
commit 87f0c20bc0

@ -662,6 +662,10 @@ void StringSettingDesc::ParseValue(const IniItem *item, void *object) const
{
std::string str = (item == nullptr) ? this->def : item->value.value_or("");
this->MakeValueValid(str);
if (this->flags & SF_RUN_CALLBACKS_ON_PARSE) {
if (this->pre_check != nullptr && !this->pre_check(str)) str = this->def;
if (this->post_callback != nullptr) this->post_callback(str);
}
this->Write(object, str);
}

@ -31,6 +31,7 @@ enum SettingFlag : uint32 {
SF_ENUM = 1 << 14, ///< the setting can take one of the values given by an array of struct SettingDescEnumEntry
SF_NO_NEWGAME = 1 << 15, ///< the setting does not apply and is not shown in a new game context
SF_DEC1SCALE = 1 << 16, ///< also display a float representation of the scale of a decimal1 scale parameter
SF_RUN_CALLBACKS_ON_PARSE = 1 << 17, ///< run callbacks when parsing from config file
};
DECLARE_ENUM_AS_BIT_SET(SettingFlag)

Loading…
Cancel
Save