mirror of
https://github.com/N64Recomp/N64ModernRuntime.git
synced 2025-10-30 08:02:29 +00:00
backwards compat bool options from enum options with allowing some string variants
This commit is contained in:
parent
d46ed007a5
commit
995cdf2ad4
3 changed files with 34 additions and 1 deletions
|
|
@ -15,6 +15,9 @@
|
|||
|
||||
namespace recomp {
|
||||
namespace config {
|
||||
|
||||
bool check_config_option_bool_string(const std::string& str);
|
||||
|
||||
enum class ConfigOptionType {
|
||||
None,
|
||||
Enum,
|
||||
|
|
|
|||
|
|
@ -485,6 +485,10 @@ ConfigValueVariant Config::parse_config_option_json_value(const nlohmann::json&
|
|||
return std::get<ConfigOptionBool>(option.variant).default_value;
|
||||
break;
|
||||
}
|
||||
if (json_value.is_string()) {
|
||||
std::string str_val = json_value.get<std::string>();
|
||||
return check_config_option_bool_string(str_val);
|
||||
}
|
||||
return json_value.get<bool>();
|
||||
}
|
||||
}
|
||||
|
|
@ -662,7 +666,7 @@ std::string Config::get_enum_option_details(size_t option_index) const {
|
|||
if (!enum_option_details.contains(option_index)) {
|
||||
return std::string();
|
||||
}
|
||||
return enum_option_details[option_index];
|
||||
return enum_option_details.at(option_index);
|
||||
}
|
||||
|
||||
bool Config::is_config_option_hidden(size_t option_index) const {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,32 @@ static bool case_insensitive_compare(const std::string& a, const std::string& b)
|
|||
}
|
||||
|
||||
namespace recomp::config {
|
||||
bool check_config_option_bool_string(const std::string& str) {
|
||||
static const std::string false_strings[] = {
|
||||
"false",
|
||||
"off",
|
||||
"no",
|
||||
};
|
||||
static const std::string true_strings[] = {
|
||||
"true",
|
||||
"on",
|
||||
"yes",
|
||||
};
|
||||
|
||||
for (const auto& false_str : false_strings) {
|
||||
if (case_insensitive_compare(str, false_str)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& true_str : true_strings) {
|
||||
if (case_insensitive_compare(str, true_str)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ConfigOptionEnum
|
||||
std::vector<ConfigOptionEnumOption>::const_iterator ConfigOptionEnum::find_option_from_string(const std::string& option_key) const {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue