mirror of
https://github.com/N64Recomp/N64ModernRuntime.git
synced 2026-05-09 18:31:55 +00:00
Add option to apply temporary config changes.
This commit is contained in:
parent
489038e54d
commit
a2688d2558
2 changed files with 20 additions and 4 deletions
|
|
@ -296,6 +296,10 @@ namespace recomp {
|
||||||
add_option_hidden_dependency(dependent_option_id, source_option_id, values);
|
add_option_hidden_dependency(dependent_option_id, source_option_id, values);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Apply any temporary values to the option.
|
||||||
|
void apply_option_value(const ConfigOption &option);
|
||||||
|
void apply_option_value(const std::string &option_id);
|
||||||
|
|
||||||
bool load_config(std::function<bool(nlohmann::json &)> validate_callback = nullptr);
|
bool load_config(std::function<bool(nlohmann::json &)> validate_callback = nullptr);
|
||||||
bool save_config();
|
bool save_config();
|
||||||
bool save_config_json(nlohmann::json config_json) const;
|
bool save_config_json(nlohmann::json config_json) const;
|
||||||
|
|
|
||||||
|
|
@ -409,13 +409,25 @@ bool Config::save_config_json(nlohmann::json config_json) const {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Config::apply_option_value(const ConfigOption &option) {
|
||||||
|
ConfigValueVariant prev_value = get_option_value(option.id);
|
||||||
|
ConfigValueVariant cur_value = get_temp_option_value(option.id);
|
||||||
|
storage.value_map[option.id] = cur_value;
|
||||||
|
try_call_option_change_callback(option.id, cur_value, prev_value, OptionChangeContext::Permanent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::apply_option_value(const std::string &option_id) {
|
||||||
|
auto option_by_id_it = schema.options_by_id.find(option_id);
|
||||||
|
if (option_by_id_it != schema.options_by_id.end()) {
|
||||||
|
apply_option_value(schema.options[option_by_id_it->second]);
|
||||||
|
modified_options.erase(option_by_id_it->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Config::save_config() {
|
bool Config::save_config() {
|
||||||
if (requires_confirmation) {
|
if (requires_confirmation) {
|
||||||
for (const auto& option : schema.options) {
|
for (const auto& option : schema.options) {
|
||||||
ConfigValueVariant prev_value = get_option_value(option.id);
|
apply_option_value(option);
|
||||||
ConfigValueVariant cur_value = get_temp_option_value(option.id);
|
|
||||||
storage.value_map[option.id] = cur_value;
|
|
||||||
try_call_option_change_callback(option.id, cur_value, prev_value, OptionChangeContext::Permanent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
modified_options.clear();
|
modified_options.clear();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue