diff options
author | hop311 <hop3114@gmail.com> | 2024-01-08 23:19:39 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-01-08 23:19:39 +0100 |
commit | 83802dfead4938e6f98b4b9961b286e06ab78b18 (patch) | |
tree | b0b404a1826d455767b16d3e3ae1d6bf7516e06d /src/openvic-simulation/misc | |
parent | 79b8b73304753fedab822e6aa859fa15673f52cc (diff) |
Added map_callback and expect_item_dictionary_reserve_length
Diffstat (limited to 'src/openvic-simulation/misc')
-rw-r--r-- | src/openvic-simulation/misc/Event.cpp | 6 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Modifier.cpp | 12 |
2 files changed, 9 insertions, 9 deletions
diff --git a/src/openvic-simulation/misc/Event.cpp b/src/openvic-simulation/misc/Event.cpp index eb5f7da..d6750c1 100644 --- a/src/openvic-simulation/misc/Event.cpp +++ b/src/openvic-simulation/misc/Event.cpp @@ -196,7 +196,9 @@ bool EventManager::load_event_file(IssueManager const& issue_manager, ast::NodeC bool EventManager::load_on_action_file(ast::NodeCPtr root) { bool ret = expect_dictionary([this](std::string_view identifier, ast::NodeCPtr node) -> bool { OnAction::weight_map_t weighted_events; - bool ret = expect_dictionary([this, &identifier, &weighted_events](std::string_view weight_str, ast::NodeCPtr event_node) -> bool { + bool ret = expect_dictionary_reserve_length( + weighted_events, + [this, &identifier, &weighted_events](std::string_view weight_str, ast::NodeCPtr event_node) -> bool { bool ret = false; uint64_t weight = StringUtils::string_to_uint64(weight_str, &ret); if (!ret) { @@ -208,7 +210,7 @@ bool EventManager::load_on_action_file(ast::NodeCPtr root) { ret &= expect_event_identifier(assign_variable_callback_pointer(event))(event_node); if (event != nullptr) { - ret &= weighted_events.emplace(event, weight).second; + ret &= map_callback(weighted_events, event)(weight); } else { Logger::warning( "Non-existing event ", event->get_identifier(), " loaded on action ", identifier, "with weight", diff --git a/src/openvic-simulation/misc/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp index c83fcf0..2d95f0d 100644 --- a/src/openvic-simulation/misc/Modifier.cpp +++ b/src/openvic-simulation/misc/Modifier.cpp @@ -372,12 +372,7 @@ key_value_callback_t ModifierManager::_modifier_effect_callback( ) const { const auto add_modifier_cb = [this, &modifier, effect_validator](ModifierEffect const* effect, ast::NodeCPtr value) -> bool { if (effect_validator(*effect)) { - if (!modifier.values.contains(effect)) { - return expect_fixed_point(assign_variable_callback(modifier.values[effect]))(value); - } else { - Logger::error("Duplicate modifier effect: ", effect->get_identifier()); - return false; - } + return expect_fixed_point(map_callback(modifier.values, effect))(value); } else { Logger::error("Failed to validate modifier effect: ", effect->get_identifier()); return false; @@ -424,7 +419,10 @@ node_callback_t ModifierManager::expect_validated_modifier_value_and_default( ) const { return [this, modifier_callback, default_callback, effect_validator](ast::NodeCPtr root) -> bool { ModifierValue modifier; - bool ret = expect_dictionary(_modifier_effect_callback(modifier, default_callback, effect_validator))(root); + bool ret = expect_dictionary_reserve_length( + modifier.values, + _modifier_effect_callback(modifier, default_callback, effect_validator) + )(root); ret &= modifier_callback(std::move(modifier)); return ret; }; |