From f95902fdd85f86c10b9c300099c67312fc81f11b Mon Sep 17 00:00:00 2001 From: Hop311 Date: Sat, 16 Sep 2023 16:27:41 +0100 Subject: Scaffolding for `positions.txt` + modifier loading --- src/openvic-simulation/Modifier.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/openvic-simulation/Modifier.cpp') 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 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; + }; +} -- cgit v1.2.3-56-ga3b1