From ce6e70d079f4ab18cdfa082032dc3580ab233b0e Mon Sep 17 00:00:00 2001 From: hop311 Date: Fri, 13 Oct 2023 17:34:25 +0100 Subject: TGC compatibility fixes + other cleanup --- src/openvic-simulation/Modifier.hpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/openvic-simulation/Modifier.hpp') diff --git a/src/openvic-simulation/Modifier.hpp b/src/openvic-simulation/Modifier.hpp index 2e1b03a..663d359 100644 --- a/src/openvic-simulation/Modifier.hpp +++ b/src/openvic-simulation/Modifier.hpp @@ -8,26 +8,32 @@ namespace OpenVic { struct ModifierEffect : HasIdentifier { friend struct ModifierManager; + enum class format_t { + RAW_DECIMAL, PERCENTAGE_DECIMAL, INT + }; + private: /* If true, positive values will be green and negative values will be red. * If false, the colours will be switced. */ const bool positive_good; + const format_t format; // TODO - format/precision, e.g. 80% vs 0.8 vs 0.800, 2 vs 2.0 vs 200% - ModifierEffect(std::string_view new_identifier, bool new_positive_good); + ModifierEffect(std::string_view new_identifier, bool new_positive_good, format_t new_format); public: ModifierEffect(ModifierEffect&&) = default; bool get_positive_good() const; + format_t get_format() const; }; struct ModifierValue { friend struct ModifierManager; - using effect_map_t = std::map; + using effect_map_t = decimal_map_t; private: effect_map_t values; @@ -95,7 +101,7 @@ namespace OpenVic { public: ModifierManager(); - bool add_modifier_effect(std::string_view identifier, bool province_good); + bool add_modifier_effect(std::string_view identifier, bool province_good, ModifierEffect::format_t format = ModifierEffect::format_t::PERCENTAGE_DECIMAL); IDENTIFIER_REGISTRY_ACCESSORS(modifier_effect) bool add_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon); @@ -110,12 +116,10 @@ namespace OpenVic { NodeTools::node_callback_t expect_modifier_value_and_key_map(NodeTools::callback_t modifier_callback, NodeTools::key_map_t&& key_map) const; template - NodeTools::node_callback_t expect_modifier_value_and_key_map_and_default( - NodeTools::callback_t modifier_callback, NodeTools::key_value_callback_t default_callback, NodeTools::key_map_t&& key_map, - std::string_view key, NodeTools::dictionary_entry_t::expected_count_t expected_count, NodeTools::node_callback_t callback, - Args... args) const { - NodeTools::add_key_map_entry(key_map, key, expected_count, callback); - return expect_modifier_value_and_key_map_and_default(modifier_callback, default_callback, std::move(key_map), args...); + NodeTools::node_callback_t expect_modifier_value_and_key_map_and_default(NodeTools::callback_t modifier_callback, + NodeTools::key_value_callback_t default_callback, NodeTools::key_map_t&& key_map, Args... args) const { + NodeTools::add_key_map_entries(key_map, args...); + return expect_modifier_value_and_key_map_and_default(modifier_callback, default_callback, std::move(key_map)); } template -- cgit v1.2.3-56-ga3b1