aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/Modifier.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-09-19 17:40:09 +0200
committer GitHub <noreply@github.com>2023-09-19 17:40:09 +0200
commit9c89100e0c8854dff3174b078d235148585a8b03 (patch)
tree77f81dfd3ec85a659741e979c148b33b22595dd0 /src/openvic-simulation/Modifier.cpp
parent64d134ad20c333afa60373526d6fab27a07c6adc (diff)
parent72add97c47f0d17fc0019bb4cfec7506740a9c7d (diff)
Merge pull request #17 from OpenVicProject/dataloading-the-third
Scaffolding for `positions.txt` + modifier loading
Diffstat (limited to 'src/openvic-simulation/Modifier.cpp')
-rw-r--r--src/openvic-simulation/Modifier.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/openvic-simulation/Modifier.cpp b/src/openvic-simulation/Modifier.cpp
index d2e21c6..46bba48 100644
--- a/src/openvic-simulation/Modifier.cpp
+++ b/src/openvic-simulation/Modifier.cpp
@@ -1,6 +1,7 @@
#include "Modifier.hpp"
using namespace OpenVic;
+using namespace OpenVic::NodeTools;
ModifierEffect::ModifierEffect(const std::string_view new_identifier, bool new_positive_good)
: HasIdentifier { new_identifier }, positive_good { new_positive_good } {}
@@ -114,3 +115,23 @@ bool ModifierManager::add_modifier(const std::string_view identifier, ModifierVa
}
return modifiers.add_item({ identifier, std::move(values), icon });
}
+
+node_callback_t ModifierManager::expect_modifier_value(callback_t<ModifierValue&&> callback) const {
+ return [this, callback](ast::NodeCPtr root) -> bool {
+ ModifierValue modifier;
+ bool ret = expect_dictionary(
+ [this, &modifier](std::string_view key, ast::NodeCPtr value) -> bool {
+ ModifierEffect const* effect = get_modifier_effect_by_identifier(key);
+ if (effect != nullptr) {
+ return expect_fixed_point(
+ assign_variable_callback(modifier.values[effect])
+ )(value);
+ }
+ Logger::error("Invalid modifier effect: ", key);
+ return false;
+ }
+ )(root);
+ ret &= callback(std::move(modifier));
+ return ret;
+ };
+}