aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/Modifier.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/Modifier.hpp')
-rw-r--r--src/openvic-simulation/Modifier.hpp40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/openvic-simulation/Modifier.hpp b/src/openvic-simulation/Modifier.hpp
index 2e1b03a..0801aa5 100644
--- a/src/openvic-simulation/Modifier.hpp
+++ b/src/openvic-simulation/Modifier.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include <set>
+
#include "openvic-simulation/types/IdentifierRegistry.hpp"
namespace OpenVic {
@@ -8,26 +10,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<ModifierEffect const*, fixed_point_t>;
+ using effect_map_t = decimal_map_t<ModifierEffect const*>;
private:
effect_map_t values;
@@ -86,16 +94,24 @@ namespace OpenVic {
Date const& get_expiry_date() const;
};
+ template<typename Fn>
+ concept ModifierEffectValidator = std::predicate<Fn, ModifierEffect const&>;
+
struct ModifierManager {
private:
IdentifierRegistry<ModifierEffect> modifier_effects;
IdentifierRegistry<Modifier> modifiers;
+ /* effect_validator takes in ModifierEffect const& */
+ NodeTools::key_value_callback_t _modifier_effect_callback(ModifierValue& modifier,
+ NodeTools::key_value_callback_t default_callback,
+ ModifierEffectValidator auto effect_validator) const;
+
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);
@@ -103,19 +119,25 @@ namespace OpenVic {
bool setup_modifier_effects();
+ NodeTools::node_callback_t expect_validated_modifier_value_and_default(NodeTools::callback_t<ModifierValue&&> modifier_callback,
+ NodeTools::key_value_callback_t default_callback, ModifierEffectValidator auto effect_validator) const;
+ NodeTools::node_callback_t expect_validated_modifier_value(NodeTools::callback_t<ModifierValue&&> modifier_callback,
+ ModifierEffectValidator auto effect_validator) const;
+
NodeTools::node_callback_t expect_modifier_value_and_default(NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_value_callback_t default_callback) const;
NodeTools::node_callback_t expect_modifier_value(NodeTools::callback_t<ModifierValue&&> modifier_callback) const;
+ NodeTools::node_callback_t expect_whitelisted_modifier_value_and_default(NodeTools::callback_t<ModifierValue&&> modifier_callback, std::set<std::string, std::less<void>> const& whitelist, NodeTools::key_value_callback_t default_callback) const;
+ NodeTools::node_callback_t expect_whitelisted_modifier_value(NodeTools::callback_t<ModifierValue&&> modifier_callback, std::set<std::string, std::less<void>> const& whitelist) const;
+
NodeTools::node_callback_t expect_modifier_value_and_key_map_and_default(NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_value_callback_t default_callback, NodeTools::key_map_t&& key_map) const;
NodeTools::node_callback_t expect_modifier_value_and_key_map(NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_map_t&& key_map) const;
template<typename... Args>
- NodeTools::node_callback_t expect_modifier_value_and_key_map_and_default(
- NodeTools::callback_t<ModifierValue&&> 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<ModifierValue&&> 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<typename... Args>