mirror of
https://github.com/N64Recomp/N64ModernRuntime.git
synced 2025-10-30 08:02:29 +00:00
Fix config value parsing to allow integral values for double fields
This commit is contained in:
parent
499c69c7d9
commit
e2a4464726
2 changed files with 17 additions and 9 deletions
|
|
@ -7,6 +7,9 @@ void recomp_get_config_u32(uint8_t* rdram, recomp_context* ctx, size_t mod_index
|
|||
if (uint32_t* as_u32 = std::get_if<uint32_t>(&val)) {
|
||||
_return(ctx, *as_u32);
|
||||
}
|
||||
else if (double* as_double = std::get_if<double>(&val)) {
|
||||
_return(ctx, uint32_t(int32_t(*as_double)));
|
||||
}
|
||||
else {
|
||||
_return(ctx, uint32_t{0});
|
||||
}
|
||||
|
|
@ -14,7 +17,10 @@ void recomp_get_config_u32(uint8_t* rdram, recomp_context* ctx, size_t mod_index
|
|||
|
||||
void recomp_get_config_double(uint8_t* rdram, recomp_context* ctx, size_t mod_index) {
|
||||
recomp::mods::ConfigValueVariant val = recomp::mods::get_mod_config_value(mod_index, _arg_string<0>(rdram, ctx));
|
||||
if (double* as_double = std::get_if<double>(&val)) {
|
||||
if (uint32_t* as_u32 = std::get_if<uint32_t>(&val)) {
|
||||
ctx->f0.d = double(*as_u32);
|
||||
}
|
||||
else if (double* as_double = std::get_if<double>(&val)) {
|
||||
ctx->f0.d = *as_double;
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -427,26 +427,29 @@ recomp::mods::ModOpenError parse_manifest_config_schema_option(const nlohmann::j
|
|||
|
||||
auto min = config_schema_json.find(config_schema_min_key);
|
||||
if (min != config_schema_json.end()) {
|
||||
if (!get_to<double>(*min, option_number.min)) {
|
||||
if (!min->is_number()) {
|
||||
error_param = config_schema_min_key;
|
||||
return recomp::mods::ModOpenError::IncorrectConfigSchemaType;
|
||||
}
|
||||
option_number.min = min->template get<double>();
|
||||
}
|
||||
|
||||
auto max = config_schema_json.find(config_schema_max_key);
|
||||
if (max != config_schema_json.end()) {
|
||||
if (!get_to<double>(*max, option_number.max)) {
|
||||
if (!max->is_number()) {
|
||||
error_param = config_schema_max_key;
|
||||
return recomp::mods::ModOpenError::IncorrectConfigSchemaType;
|
||||
}
|
||||
option_number.max = max->template get<double>();
|
||||
}
|
||||
|
||||
auto step = config_schema_json.find(config_schema_step_key);
|
||||
if (step != config_schema_json.end()) {
|
||||
if (!get_to<double>(*step, option_number.step)) {
|
||||
if (!step->is_number()) {
|
||||
error_param = config_schema_step_key;
|
||||
return recomp::mods::ModOpenError::IncorrectConfigSchemaType;
|
||||
}
|
||||
option_number.step = step->template get<double>();
|
||||
}
|
||||
|
||||
auto precision = config_schema_json.find(config_schema_precision_key);
|
||||
|
|
@ -471,10 +474,11 @@ recomp::mods::ModOpenError parse_manifest_config_schema_option(const nlohmann::j
|
|||
|
||||
auto default_value = config_schema_json.find(config_schema_default_key);
|
||||
if (default_value != config_schema_json.end()) {
|
||||
if (!get_to<double>(*default_value, option_number.default_value)) {
|
||||
if (!default_value->is_number()) {
|
||||
error_param = config_schema_default_key;
|
||||
return recomp::mods::ModOpenError::IncorrectConfigSchemaType;
|
||||
}
|
||||
option_number.default_value = default_value->template get<double>();
|
||||
}
|
||||
|
||||
option.variant = option_number;
|
||||
|
|
@ -676,8 +680,6 @@ bool parse_mod_config_storage(const std::filesystem::path &path, const std::stri
|
|||
}
|
||||
|
||||
// Only parse the object for known option types based on the schema.
|
||||
int64_t value_int64;
|
||||
double value_double;
|
||||
std::string value_str;
|
||||
for (const recomp::mods::ConfigOption &option : config_schema.options) {
|
||||
auto option_json = storage_json->find(option.id);
|
||||
|
|
@ -698,8 +700,8 @@ bool parse_mod_config_storage(const std::filesystem::path &path, const std::stri
|
|||
|
||||
break;
|
||||
case recomp::mods::ConfigOptionType::Number:
|
||||
if (get_to<double>(*option_json, value_double)) {
|
||||
config_storage.value_map[option.id] = value_double;
|
||||
if (option_json->is_number()) {
|
||||
config_storage.value_map[option.id] = option_json->template get<double>();
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue