diff options
author | hop311 <hop3114@gmail.com> | 2024-04-24 20:24:56 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-04-24 20:25:35 +0200 |
commit | 0fb9d5c8fb4771ef8001efdd8de1dc2dab4bb5dc (patch) | |
tree | e0ec540f15f1a543121cf2f3ea4f0d46cd2c8f6a /extension | |
parent | 7a1167259bc2a33aab8e91c6108d9054c77408bc (diff) |
Add province names and improve zooming
Diffstat (limited to 'extension')
m--------- | extension/deps/openvic-simulation | 0 | ||||
-rw-r--r-- | extension/src/openvic-extension/singletons/GameSingleton.cpp | 35 | ||||
-rw-r--r-- | extension/src/openvic-extension/singletons/GameSingleton.hpp | 2 |
3 files changed, 37 insertions, 0 deletions
diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation -Subproject d0f8ec5484a0ea49d778c0ebb6c2ba2e6df9b7d +Subproject e286cfef29d7c431ba33cd77283e838e6fba05d diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp index 8618276..838542d 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.cpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp @@ -60,6 +60,8 @@ void GameSingleton::_bind_methods() { OV_BIND_METHOD(GameSingleton::get_province_shape_texture); OV_BIND_METHOD(GameSingleton::get_province_colour_texture); + OV_BIND_METHOD(GameSingleton::get_province_names); + OV_BIND_METHOD(GameSingleton::get_mapmode_count); OV_BIND_METHOD(GameSingleton::get_mapmode_identifier); OV_BIND_METHOD(GameSingleton::set_mapmode, { "identifier" }); @@ -243,6 +245,39 @@ Error GameSingleton::_update_colour_image() { return err; } +TypedArray<Dictionary> GameSingleton::get_province_names() const { + static const StringName identifier_key = "identifier"; + static const StringName position_key = "position"; + static const StringName rotation_key = "rotation"; + static const StringName scale_key = "scale"; + + TypedArray<Dictionary> ret; + ERR_FAIL_COND_V(ret.resize(game_manager.get_map().get_province_count()) != OK, {}); + + for (int32_t index = 0; index < game_manager.get_map().get_province_count(); ++index) { + Province const& province = game_manager.get_map().get_provinces()[index]; + + Dictionary province_dict; + + province_dict[identifier_key] = std_view_to_godot_string(province.get_identifier()); + province_dict[position_key] = Utilities::to_godot_fvec2(province.get_text_position()) / get_map_dims(); + + const float rotation = province.get_text_rotation().to_float(); + if (rotation != 0.0f) { + province_dict[rotation_key] = rotation; + } + + const float scale = province.get_text_scale().to_float(); + if (scale != 1.0f) { + province_dict[scale_key] = scale; + } + + ret[index] = std::move(province_dict); + } + + return ret; +} + int32_t GameSingleton::get_mapmode_count() const { return game_manager.get_map().get_mapmode_count(); } diff --git a/extension/src/openvic-extension/singletons/GameSingleton.hpp b/extension/src/openvic-extension/singletons/GameSingleton.hpp index 397b64c..f2b88ac 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.hpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.hpp @@ -95,6 +95,8 @@ namespace OpenVic { /* The base and stripe colours for each province. */ godot::Ref<godot::ImageTexture> get_province_colour_texture() const; + godot::TypedArray<godot::Dictionary> get_province_names() const; + int32_t get_mapmode_count() const; godot::String get_mapmode_identifier(int32_t index) const; godot::Error set_mapmode(godot::String const& identifier); |