diff options
Diffstat (limited to 'extension/src/openvic-extension/classes')
5 files changed, 28 insertions, 21 deletions
diff --git a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp index 2c315a9..51a4235 100644 --- a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp +++ b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp @@ -34,7 +34,7 @@ Error GFXMaskedFlagTexture::_generate_combined_image() { set_region({ {}, button_image->get_size() }); } - if (mask_image.is_valid() && flag_image.is_valid()) { + if (mask_image.is_valid() && flag_image.is_valid() && flag_image_rect.has_area()) { const Vector2i centre_translation = (mask_image->get_size() - button_image->get_size()) / 2; for (Vector2i combined_image_point { 0, 0 }; combined_image_point.y < button_image->get_height(); ++combined_image_point.y) { for (combined_image_point.x = 0; combined_image_point.x < button_image->get_width(); ++combined_image_point.x) { @@ -46,10 +46,14 @@ Error GFXMaskedFlagTexture::_generate_combined_image() { 0 <= mask_image_point.y && mask_image_point.y < mask_image->get_height() ) { const Color mask_image_colour = mask_image->get_pixelv(mask_image_point); + // Rescale from mask_image to flag_image coordinates. - const Vector2i flag_image_point = mask_image_point * flag_image->get_size() / mask_image->get_size(); + const Vector2i flag_image_point = + flag_image_rect.position + mask_image_point * flag_image_rect.size / mask_image->get_size(); + Color flag_image_colour = flag_image->get_pixelv(flag_image_point); flag_image_colour.a = mask_image_colour.a; + button_image->set_pixelv(combined_image_point, flag_image_colour.blend(overlay_image_colour)); } else { button_image->set_pixelv(combined_image_point, overlay_image_colour); @@ -157,12 +161,12 @@ Error GFXMaskedFlagTexture::set_flag_country_and_type(Country const* new_flag_co GameSingleton* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, FAILED); - const Ref<Image> new_flag_image = game_singleton->get_flag_image(new_flag_country, new_flag_type); - ERR_FAIL_NULL_V(new_flag_image, FAILED); + flag_image_rect = game_singleton->get_flag_sheet_rect(new_flag_country->get_index(), new_flag_type); + ERR_FAIL_COND_V(!flag_image_rect.has_area(), FAILED); flag_country = new_flag_country; flag_type = new_flag_type; - flag_image = new_flag_image; + flag_image = game_singleton->get_flag_sheet_image(); } else { // TODO - use REB flag as default/error flag flag_country = nullptr; diff --git a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp index 1e85dd8..9290d5c 100644 --- a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp +++ b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp @@ -1,7 +1,7 @@ #pragma once #include <openvic-simulation/country/Country.hpp> -#include <openvic-simulation/interface/GFX.hpp> +#include <openvic-simulation/interface/GFXSprite.hpp> #include "openvic-extension/classes/GFXButtonStateTexture.hpp" @@ -14,6 +14,7 @@ namespace OpenVic { godot::StringName PROPERTY(flag_type); godot::Ref<godot::Image> overlay_image, mask_image, flag_image; + godot::Rect2i flag_image_rect; godot::Ref<godot::ImageTexture> combined_texture; godot::Error _generate_combined_image(); diff --git a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp index abeca1e..8683b10 100644 --- a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp +++ b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp @@ -2,7 +2,7 @@ #include <godot_cpp/classes/image_texture.hpp> -#include <openvic-simulation/interface/GFX.hpp> +#include <openvic-simulation/interface/GFXSprite.hpp> #include "openvic-extension/utility/Utilities.hpp" @@ -54,12 +54,14 @@ namespace OpenVic { return lhs.first < rhs.first; }); godot_pie_chart_data_t array; - for (auto const& [key, val] : sorted_dist) { + ERR_FAIL_COND_V(array.resize(sorted_dist.size()) != OK, {}); + for (size_t idx = 0; idx < array.size(); ++idx) { + auto const& [key, val] = sorted_dist[idx]; Dictionary sub_dict; sub_dict[_slice_identifier_key()] = Utilities::std_view_to_godot_string(key->get_identifier()); sub_dict[_slice_colour_key()] = Utilities::to_godot_color(key->get_colour()); sub_dict[_slice_weight_key()] = val.to_float(); - array.push_back(sub_dict); + array[idx] = std::move(sub_dict); } return array; } diff --git a/extension/src/openvic-extension/classes/GFXSpriteTexture.hpp b/extension/src/openvic-extension/classes/GFXSpriteTexture.hpp index 34ec405..4e93e62 100644 --- a/extension/src/openvic-extension/classes/GFXSpriteTexture.hpp +++ b/extension/src/openvic-extension/classes/GFXSpriteTexture.hpp @@ -2,7 +2,7 @@ #include <godot_cpp/classes/atlas_texture.hpp> -#include <openvic-simulation/interface/GFX.hpp> +#include <openvic-simulation/interface/GFXSprite.hpp> #include "openvic-extension/classes/GFXButtonStateTexture.hpp" diff --git a/extension/src/openvic-extension/classes/MapMesh.cpp b/extension/src/openvic-extension/classes/MapMesh.cpp index a557105..8db3b84 100644 --- a/extension/src/openvic-extension/classes/MapMesh.cpp +++ b/extension/src/openvic-extension/classes/MapMesh.cpp @@ -92,7 +92,7 @@ bool MapMesh::is_valid_uv_coord(godot::Vector2 const& uv) const { Array MapMesh::_create_mesh_array() const { Array arr; - arr.resize(Mesh::ARRAY_MAX); + ERR_FAIL_COND_V(arr.resize(Mesh::ARRAY_MAX) != OK, {}); const int32_t vertex_count = (subdivide_w + 2) * (subdivide_d + 2); const int32_t indice_count = (subdivide_w + 1) * (subdivide_d + 1) * 6; @@ -103,11 +103,11 @@ Array MapMesh::_create_mesh_array() const { PackedVector2Array uvs; PackedInt32Array indices; - points.resize(vertex_count); - normals.resize(vertex_count); - tangents.resize(vertex_count * 4); - uvs.resize(vertex_count); - indices.resize(indice_count); + ERR_FAIL_COND_V(points.resize(vertex_count) != OK, {}); + ERR_FAIL_COND_V(normals.resize(vertex_count) != OK, {}); + ERR_FAIL_COND_V(tangents.resize(vertex_count * 4) != OK, {}); + ERR_FAIL_COND_V(uvs.resize(vertex_count) != OK, {}); + ERR_FAIL_COND_V(indices.resize(indice_count) != OK, {}); static const Vector3 normal { 0.0f, 1.0f, 0.0f }; const Size2 uv_size { 1.0f + 2.0f * repeat_proportion, 1.0f }; @@ -153,11 +153,11 @@ Array MapMesh::_create_mesh_array() const { thisrow = point_index; } - arr[Mesh::ARRAY_VERTEX] = points; - arr[Mesh::ARRAY_NORMAL] = normals; - arr[Mesh::ARRAY_TANGENT] = tangents; - arr[Mesh::ARRAY_TEX_UV] = uvs; - arr[Mesh::ARRAY_INDEX] = indices; + arr[Mesh::ARRAY_VERTEX] = std::move(points); + arr[Mesh::ARRAY_NORMAL] = std::move(normals); + arr[Mesh::ARRAY_TANGENT] = std::move(tangents); + arr[Mesh::ARRAY_TEX_UV] = std::move(uvs); + arr[Mesh::ARRAY_INDEX] = std::move(indices); return arr; } |