aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/Modifier.cpp
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-09-16 17:27:41 +0200
committer Hop311 <hop3114@gmail.com>2023-09-16 17:28:01 +0200
commitf95902fdd85f86c10b9c300099c67312fc81f11b (patch)
tree1655119602f39a366de8248cb4651321b6dfdda0 /src/openvic-simulation/Modifier.cpp
parent64d134ad20c333afa60373526d6fab27a07c6adc (diff)
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;
+ };
+}