mirror of
https://github.com/N64Recomp/N64ModernRuntime.git
synced 2026-04-26 20:11:52 +00:00
Add type checks when parsing config
This commit is contained in:
parent
49e9add3bb
commit
8441e2252a
1 changed files with 4 additions and 5 deletions
|
|
@ -474,7 +474,7 @@ ConfigValueVariant Config::parse_config_option_json_value(const nlohmann::json&
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
case ConfigOptionType::Enum: {
|
case ConfigOptionType::Enum: {
|
||||||
if (is_null) {
|
if (is_null || !json_value.is_string()) {
|
||||||
return std::get<ConfigOptionEnum>(option.variant).default_value;
|
return std::get<ConfigOptionEnum>(option.variant).default_value;
|
||||||
}
|
}
|
||||||
std::string enum_string_value = json_value.get<std::string>();
|
std::string enum_string_value = json_value.get<std::string>();
|
||||||
|
|
@ -487,19 +487,18 @@ ConfigValueVariant Config::parse_config_option_json_value(const nlohmann::json&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ConfigOptionType::Number:
|
case ConfigOptionType::Number:
|
||||||
if (is_null) {
|
if (is_null || !json_value.is_number()) {
|
||||||
return std::get<ConfigOptionNumber>(option.variant).default_value;
|
return std::get<ConfigOptionNumber>(option.variant).default_value;
|
||||||
}
|
}
|
||||||
return json_value.get<double>();
|
return json_value.get<double>();
|
||||||
case ConfigOptionType::String:
|
case ConfigOptionType::String:
|
||||||
if (is_null) {
|
if (is_null || !json_value.is_string()) {
|
||||||
return std::get<ConfigOptionString>(option.variant).default_value;
|
return std::get<ConfigOptionString>(option.variant).default_value;
|
||||||
}
|
}
|
||||||
return json_value.get<std::string>();
|
return json_value.get<std::string>();
|
||||||
case ConfigOptionType::Bool:
|
case ConfigOptionType::Bool:
|
||||||
if (is_null) {
|
if (is_null || !json_value.is_boolean()) {
|
||||||
return std::get<ConfigOptionBool>(option.variant).default_value;
|
return std::get<ConfigOptionBool>(option.variant).default_value;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (json_value.is_string()) {
|
if (json_value.is_string()) {
|
||||||
std::string str_val = json_value.get<std::string>();
|
std::string str_val = json_value.get<std::string>();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue