From acad20f397b818a124890ae18ee59c4be5bd718d Mon Sep 17 00:00:00 2001 From: hop311 Date: Sat, 20 Apr 2024 22:28:36 +0100 Subject: Update openvic-simulation to OpenVicProject/OpenVic-Simulation@8f97145 --- extension/src/openvic-extension/singletons/GameSingleton.cpp | 10 +++++++--- extension/src/openvic-extension/singletons/GameSingleton.hpp | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'extension/src/openvic-extension/singletons') diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp index 563f1cb..8b19dc3 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.cpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp @@ -51,6 +51,7 @@ void GameSingleton::_bind_methods() { OV_BIND_METHOD(GameSingleton::get_map_width); OV_BIND_METHOD(GameSingleton::get_map_height); + OV_BIND_METHOD(GameSingleton::get_map_dims); OV_BIND_METHOD(GameSingleton::get_map_aspect_ratio); OV_BIND_METHOD(GameSingleton::get_terrain_texture); OV_BIND_METHOD(GameSingleton::get_province_shape_image_subdivisions); @@ -133,9 +134,8 @@ Error GameSingleton::setup_game(int32_t bookmark_index) { } int32_t GameSingleton::get_province_index_from_uv_coords(Vector2 const& coords) const { - const size_t x_mod_w = UtilityFunctions::fposmod(coords.x, 1.0f) * get_map_width(); - const size_t y_mod_h = UtilityFunctions::fposmod(coords.y, 1.0f) * get_map_height(); - return game_manager.get_map().get_province_index_at(x_mod_w, y_mod_h); + const Vector2 pos = coords.posmod(1.0f) * get_map_dims(); + return game_manager.get_map().get_province_index_at(Utilities::from_godot_ivec2(pos)); } int32_t GameSingleton::get_map_width() const { @@ -146,6 +146,10 @@ int32_t GameSingleton::get_map_height() const { return game_manager.get_map().get_height(); } +Vector2i GameSingleton::get_map_dims() const { + return Utilities::to_godot_ivec2(game_manager.get_map().get_dims()); +} + float GameSingleton::get_map_aspect_ratio() const { return static_cast(get_map_width()) / static_cast(get_map_height()); } diff --git a/extension/src/openvic-extension/singletons/GameSingleton.hpp b/extension/src/openvic-extension/singletons/GameSingleton.hpp index e84e366..a741331 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.hpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.hpp @@ -61,6 +61,7 @@ namespace OpenVic { int32_t get_map_width() const; int32_t get_map_height() const; + godot::Vector2i get_map_dims() const; float get_map_aspect_ratio() const; /* The cosmetic terrain textures stored in a Texture2DArray. */ -- cgit v1.2.3-56-ga3b1