aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/singletons/GameSingleton.cpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-04-20 23:28:36 +0200
committer hop311 <hop3114@gmail.com>2024-04-20 23:30:06 +0200
commitacad20f397b818a124890ae18ee59c4be5bd718d (patch)
treed8f3beec1a8fa98908f24c2e5da93fc064926182 /extension/src/openvic-extension/singletons/GameSingleton.cpp
parent1ab95a6827c1525d0b48d6d28205f0b1e512bd9d (diff)
Update openvic-simulation to OpenVicProject/OpenVic-Simulation@8f97145
Diffstat (limited to 'extension/src/openvic-extension/singletons/GameSingleton.cpp')
-rw-r--r--extension/src/openvic-extension/singletons/GameSingleton.cpp10
1 files changed, 7 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());
}