diff options
author | hop311 <hop3114@gmail.com> | 2024-07-17 01:01:03 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-07-17 19:09:33 +0200 |
commit | 928c521599b2b18e8964aeb445c3ca5a55bacbd1 (patch) | |
tree | aa6e018034c4c0fd498e74707d5cc3750c0dd438 /extension/src/openvic-extension/singletons | |
parent | 114394f4d1bcf5249089b6e3632d259a195ec584 (diff) |
Use IndexedMap + helper function support
Diffstat (limited to 'extension/src/openvic-extension/singletons')
4 files changed, 31 insertions, 19 deletions
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp index b4baf40..36e5f58 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp @@ -226,19 +226,22 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { ret[province_info_total_population_key] = province->get_total_population(); - fixed_point_map_t<PopType const*> const& pop_types = province->get_pop_type_distribution(); - if (!pop_types.empty()) { - ret[province_info_pop_types_key] = GFXPieChartTexture::distribution_to_slices_array(pop_types); + GFXPieChartTexture::godot_pie_chart_data_t pop_types = + GFXPieChartTexture::distribution_to_slices_array(province->get_pop_type_distribution()); + if (!pop_types.is_empty()) { + ret[province_info_pop_types_key] = std::move(pop_types); } - fixed_point_map_t<Ideology const*> const& ideologies = province->get_ideology_distribution(); - if (!ideologies.empty()) { - ret[province_info_pop_ideologies_key] = GFXPieChartTexture::distribution_to_slices_array(ideologies); + GFXPieChartTexture::godot_pie_chart_data_t ideologies = + GFXPieChartTexture::distribution_to_slices_array(province->get_ideology_distribution()); + if (!ideologies.is_empty()) { + ret[province_info_pop_ideologies_key] = std::move(ideologies); } - fixed_point_map_t<Culture const*> const& cultures = province->get_culture_distribution(); - if (!cultures.empty()) { - ret[province_info_pop_cultures_key] = GFXPieChartTexture::distribution_to_slices_array(cultures); + GFXPieChartTexture::godot_pie_chart_data_t cultures = + GFXPieChartTexture::distribution_to_slices_array(province->get_culture_distribution()); + if (!cultures.is_empty()) { + ret[province_info_pop_cultures_key] = std::move(cultures); } std::vector<CountryDefinition const*> const& cores = province->get_cores(); diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.cpp b/extension/src/openvic-extension/singletons/ModelSingleton.cpp index 7dea1bd..5fb9cf8 100644 --- a/extension/src/openvic-extension/singletons/ModelSingleton.cpp +++ b/extension/src/openvic-extension/singletons/ModelSingleton.cpp @@ -4,6 +4,8 @@ #include <godot_cpp/variant/utility_functions.hpp> +#include <openvic-simulation/map/ProvinceInstance.hpp> + #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/utility/ClassBindings.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -180,8 +182,12 @@ Dictionary ModelSingleton::make_model_dict(GFX::Actor const& actor) const { /* Returns false if an error occurs while trying to add a unit model for the province, true otherwise. * Returning true doesn't necessarily mean a unit was added, e.g. when units is empty. */ -template<utility::is_derived_from_specialization_of<UnitInstanceGroup> T> -bool ModelSingleton::add_unit_dict(ordered_set<T*> const& units, TypedArray<Dictionary>& unit_array) const { +template<UnitType::branch_t Branch> +bool ModelSingleton::add_unit_dict( + ordered_set<UnitInstanceGroupBranched<Branch>*> const& units, TypedArray<Dictionary>& unit_array +) const { + using _UnitInstanceGroup = UnitInstanceGroupBranched<Branch>; + GameSingleton const* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, false); @@ -204,7 +210,7 @@ bool ModelSingleton::add_unit_dict(ordered_set<T*> const& units, TypedArray<Dict bool ret = true; /* Last unit to enter the province is shown on top. */ - T const& unit = *units.back(); + _UnitInstanceGroup const& unit = *units.back(); ERR_FAIL_COND_V_MSG(unit.empty(), false, vformat("Empty unit \"%s\"", std_view_to_godot_string(unit.get_name()))); CountryDefinition const* country = unit.get_country()->get_country_definition(); @@ -220,7 +226,7 @@ bool ModelSingleton::add_unit_dict(ordered_set<T*> const& units, TypedArray<Dict std::string_view actor_name = display_unit_type->get_sprite(); std::string_view mount_actor_name, mount_attach_node_name; - if constexpr (std::same_as<T, ArmyInstance>) { + if constexpr (Branch == UnitType::branch_t::LAND) { RegimentType const* regiment_type = reinterpret_cast<RegimentType const*>(display_unit_type); if (!regiment_type->get_sprite_override().empty()) { diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.hpp b/extension/src/openvic-extension/singletons/ModelSingleton.hpp index ad1a6d8..8030ffd 100644 --- a/extension/src/openvic-extension/singletons/ModelSingleton.hpp +++ b/extension/src/openvic-extension/singletons/ModelSingleton.hpp @@ -3,7 +3,8 @@ #include <godot_cpp/classes/object.hpp> #include <openvic-simulation/interface/GFXObject.hpp> -#include <openvic-simulation/military/UnitInstance.hpp> +#include <openvic-simulation/military/UnitInstanceGroup.hpp> +#include <openvic-simulation/types/OrderedContainers.hpp> namespace OpenVic { struct BuildingInstance; @@ -31,8 +32,10 @@ namespace OpenVic { godot::Dictionary make_animation_dict(GFX::Actor::Animation const& animation) const; godot::Dictionary make_model_dict(GFX::Actor const& actor) const; - template<utility::is_derived_from_specialization_of<UnitInstanceGroup> T> - bool add_unit_dict(ordered_set<T*> const& units, godot::TypedArray<godot::Dictionary>& unit_array) const; + template<UnitType::branch_t Branch> + bool add_unit_dict( + ordered_set<UnitInstanceGroupBranched<Branch>*> const& units, godot::TypedArray<godot::Dictionary>& unit_array + ) const; bool add_building_dict( BuildingInstance const& building, ProvinceInstance const& province, diff --git a/extension/src/openvic-extension/singletons/PopulationMenu.cpp b/extension/src/openvic-extension/singletons/PopulationMenu.cpp index 1237e86..db2ac53 100644 --- a/extension/src/openvic-extension/singletons/PopulationMenu.cpp +++ b/extension/src/openvic-extension/singletons/PopulationMenu.cpp @@ -407,12 +407,12 @@ void MenuSingleton::_population_menu_update_filtered_pops() { population_menu.distributions[0][&pop->get_type()] += pop->get_size(); population_menu.distributions[1][&pop->get_religion()] += pop->get_size(); population_menu.distributions[2] += - cast_map<HasIdentifierAndColour>(pop->get_ideologies() * static_cast<int32_t>(pop->get_size())); + pop->get_ideologies() * static_cast<fixed_point_t>(static_cast<int32_t>(pop->get_size())); population_menu.distributions[3][&pop->get_culture()] += pop->get_size(); population_menu.distributions[4] += cast_map<HasIdentifierAndColour>(pop->get_issues() * static_cast<int32_t>(pop->get_size())); population_menu.distributions[5] += - cast_map<HasIdentifierAndColour>(pop->get_votes() * static_cast<int32_t>(pop->get_size())); + pop->get_votes() * static_cast<fixed_point_t>(static_cast<int32_t>(pop->get_size())); } for (fixed_point_map_t<HasIdentifierAndColour const*>& distribution : population_menu.distributions) { @@ -467,7 +467,7 @@ MenuSingleton::sort_func_t MenuSingleton::_get_population_menu_sort_func(populat }; case SORT_IDEOLOGY: return [](Pop const* a, Pop const* b) -> bool { - return sorted_fixed_map_less_than(a->get_ideologies(), b->get_ideologies()); + return sorted_indexed_map_less_than(a->get_ideologies(), b->get_ideologies()); }; case SORT_ISSUES: return [](Pop const* a, Pop const* b) -> bool { |