diff options
author | hop311 <hop3114@gmail.com> | 2024-04-20 23:28:36 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-04-20 23:30:06 +0200 |
commit | acad20f397b818a124890ae18ee59c4be5bd718d (patch) | |
tree | d8f3beec1a8fa98908f24c2e5da93fc064926182 /extension/src/openvic-extension/singletons | |
parent | 1ab95a6827c1525d0b48d6d28205f0b1e512bd9d (diff) |
Update openvic-simulation to OpenVicProject/OpenVic-Simulation@8f97145
Diffstat (limited to 'extension/src/openvic-extension/singletons')
-rw-r--r-- | extension/src/openvic-extension/singletons/GameSingleton.cpp | 10 | ||||
-rw-r--r-- | extension/src/openvic-extension/singletons/GameSingleton.hpp | 1 |
2 files changed, 8 insertions, 3 deletions
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<float>(get_map_width()) / static_cast<float>(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. */ |