mirror of
https://github.com/N64Recomp/N64ModernRuntime.git
synced 2025-10-30 08:02:29 +00:00
Added bool config option type
This commit is contained in:
parent
c5e268aa0f
commit
283ebb9360
4 changed files with 48 additions and 3 deletions
|
|
@ -130,7 +130,8 @@ namespace recomp {
|
|||
None,
|
||||
Enum,
|
||||
Number,
|
||||
String
|
||||
String,
|
||||
Bool
|
||||
};
|
||||
|
||||
struct ModFileHandle {
|
||||
|
|
@ -191,7 +192,11 @@ namespace recomp {
|
|||
std::string default_value;
|
||||
};
|
||||
|
||||
typedef std::variant<ConfigOptionEnum, ConfigOptionNumber, ConfigOptionString> ConfigOptionVariant;
|
||||
struct ConfigOptionBool {
|
||||
bool default_value;
|
||||
};
|
||||
|
||||
typedef std::variant<ConfigOptionEnum, ConfigOptionNumber, ConfigOptionString, ConfigOptionBool> ConfigOptionVariant;
|
||||
|
||||
struct ConfigOption {
|
||||
std::string id;
|
||||
|
|
@ -206,7 +211,7 @@ namespace recomp {
|
|||
std::unordered_map<std::string, size_t> options_by_id;
|
||||
};
|
||||
|
||||
typedef std::variant<std::monostate, uint32_t, double, std::string> ConfigValueVariant;
|
||||
typedef std::variant<std::monostate, uint32_t, double, std::string, bool> ConfigValueVariant;
|
||||
|
||||
struct ConfigStorage {
|
||||
std::unordered_map<std::string, ConfigValueVariant> value_map;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ void recomp_get_config_u32(uint8_t* rdram, recomp_context* ctx, size_t mod_index
|
|||
else if (double* as_double = std::get_if<double>(&val)) {
|
||||
_return(ctx, uint32_t(int32_t(*as_double)));
|
||||
}
|
||||
else if (bool* as_bool = std::get_if<bool>(&val)) {
|
||||
_return(ctx, uint32_t(*as_bool));
|
||||
}
|
||||
else {
|
||||
_return(ctx, uint32_t{0});
|
||||
}
|
||||
|
|
@ -23,6 +26,9 @@ void recomp_get_config_double(uint8_t* rdram, recomp_context* ctx, size_t mod_in
|
|||
else if (double* as_double = std::get_if<double>(&val)) {
|
||||
ctx->f0.d = *as_double;
|
||||
}
|
||||
else if (bool* as_bool = std::get_if<bool>(&val)) {
|
||||
ctx->f0.d = double(*as_bool);
|
||||
}
|
||||
else {
|
||||
ctx->f0.d = 0.0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -336,6 +336,7 @@ std::unordered_map<std::string, recomp::mods::ConfigOptionType> config_option_ma
|
|||
{ "Enum", recomp::mods::ConfigOptionType::Enum},
|
||||
{ "Number", recomp::mods::ConfigOptionType::Number},
|
||||
{ "String", recomp::mods::ConfigOptionType::String},
|
||||
{ "Bool", recomp::mods::ConfigOptionType::Bool},
|
||||
};
|
||||
|
||||
recomp::mods::ModOpenError parse_manifest_config_schema_option(const nlohmann::json &config_schema_json, recomp::mods::ModManifest &ret, std::string &error_param) {
|
||||
|
|
@ -510,6 +511,21 @@ recomp::mods::ModOpenError parse_manifest_config_schema_option(const nlohmann::j
|
|||
option.variant = option_string;
|
||||
}
|
||||
break;
|
||||
case recomp::mods::ConfigOptionType::Bool:
|
||||
{
|
||||
recomp::mods::ConfigOptionBool option_bool;
|
||||
|
||||
auto default_value = config_schema_json.find(config_schema_default_key);
|
||||
if (default_value != config_schema_json.end()) {
|
||||
if (!get_to<json::boolean_t>(*default_value, option_bool.default_value)) {
|
||||
error_param = config_schema_default_key;
|
||||
return recomp::mods::ModOpenError::IncorrectConfigSchemaType;
|
||||
}
|
||||
}
|
||||
|
||||
option.variant = option_bool;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -729,6 +745,13 @@ bool parse_mod_config_storage(const std::filesystem::path &path, const std::stri
|
|||
|
||||
break;
|
||||
}
|
||||
case recomp::mods::ConfigOptionType::Bool: {
|
||||
if (option_json->is_boolean()) {
|
||||
config_storage.value_map[option.id] = option_json->get<bool>();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(false && "Unknown option type.");
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -668,6 +668,9 @@ bool save_mod_config_storage(const std::filesystem::path &path, const std::strin
|
|||
case recomp::mods::ConfigOptionType::String:
|
||||
storage_json[it.first] = std::get<std::string>(it.second);
|
||||
break;
|
||||
case recomp::mods::ConfigOptionType::Bool:
|
||||
storage_json[it.first] = std::get<bool>(it.second);
|
||||
break;
|
||||
default:
|
||||
assert(false && "Unknown config type.");
|
||||
break;
|
||||
|
|
@ -1411,6 +1414,12 @@ void recomp::mods::ModContext::set_mod_config_value(size_t mod_index, const std:
|
|||
mod.config_storage.value_map[option_id] = value;
|
||||
}
|
||||
|
||||
break;
|
||||
case ConfigOptionType::Bool:
|
||||
if (std::holds_alternative<bool>(value)) {
|
||||
mod.config_storage.value_map[option_id] = value;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
assert(false && "Unknown config option type.");
|
||||
|
|
@ -1459,6 +1468,8 @@ recomp::mods::ConfigValueVariant recomp::mods::ModContext::get_mod_config_value(
|
|||
return std::get<ConfigOptionNumber>(option.variant).default_value;
|
||||
case ConfigOptionType::String:
|
||||
return std::get<ConfigOptionString>(option.variant).default_value;
|
||||
case ConfigOptionType::Bool:
|
||||
return std::get<ConfigOptionBool>(option.variant).default_value;
|
||||
default:
|
||||
assert(false && "Unknown config option type.");
|
||||
return std::monostate();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue