diff options
author | hop311 <hop3114@gmail.com> | 2024-11-18 00:00:31 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-11-18 12:30:38 +0100 |
commit | 49711f0543a2bb39cafd09eeb95d4a592b98e914 (patch) | |
tree | 30d5395e7f45ba983be3d083b7b5092558c59731 /extension | |
parent | 9960ccfd404f89fbc71a1d02796253503a483c23 (diff) |
Use textured minimap + better internal mapmode handling
Diffstat (limited to 'extension')
m--------- | extension/deps/openvic-simulation | 0 | ||||
-rw-r--r-- | extension/src/openvic-extension/singletons/GameSingleton.cpp | 56 | ||||
-rw-r--r-- | extension/src/openvic-extension/singletons/GameSingleton.hpp | 7 |
3 files changed, 42 insertions, 21 deletions
diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation -Subproject 8defcd5daa1acd2c61aa1cd0a26478d472fed9b +Subproject 906823d9a6364ccee31e91f9e8ea79de8ffd7a7 diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp index f258fe1..553d17c 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.cpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp @@ -33,6 +33,10 @@ StringName const& GameSingleton::_signal_clock_state_changed() { static const StringName signal_clock_state_changed = "clock_state_changed"; return signal_clock_state_changed; } +StringName const& GameSingleton::_signal_mapmode_changed() { + static const StringName signal_mapmode_changed = "mapmode_changed"; + return signal_mapmode_changed; +} void GameSingleton::_bind_methods() { OV_BIND_SMETHOD(setup_logger); @@ -63,7 +67,9 @@ void GameSingleton::_bind_methods() { OV_BIND_METHOD(GameSingleton::get_mapmode_count); OV_BIND_METHOD(GameSingleton::get_mapmode_identifier); - OV_BIND_METHOD(GameSingleton::set_mapmode, { "identifier" }); + OV_BIND_METHOD(GameSingleton::get_mapmode_localisation_key); + OV_BIND_METHOD(GameSingleton::get_current_mapmode_index); + OV_BIND_METHOD(GameSingleton::set_mapmode, { "index" }); OV_BIND_METHOD(GameSingleton::is_parchment_mapmode_allowed); OV_BIND_METHOD(GameSingleton::get_selected_province_index); OV_BIND_METHOD(GameSingleton::set_selected_province, { "index" }); @@ -76,6 +82,7 @@ void GameSingleton::_bind_methods() { ADD_SIGNAL(MethodInfo(_signal_gamestate_updated())); ADD_SIGNAL(MethodInfo(_signal_province_selected(), PropertyInfo(Variant::INT, "index"))); ADD_SIGNAL(MethodInfo(_signal_clock_state_changed())); + ADD_SIGNAL(MethodInfo(_signal_mapmode_changed(), PropertyInfo(Variant::INT, "index"))); } GameSingleton* GameSingleton::get_singleton() { @@ -95,9 +102,11 @@ void GameSingleton::_on_clock_state_changed() { * MAP-21, MAP-23, MAP-25, MAP-32, MAP-33, MAP-34 */ GameSingleton::GameSingleton() - : game_manager { + : game_manager { std::bind(&GameSingleton::_on_gamestate_updated, this), std::bind(&GameSingleton::_on_clock_state_changed, this) - }, viewed_country { nullptr } { + }, + viewed_country { nullptr }, + mapmode { &Mapmode::ERROR_MAPMODE } { ERR_FAIL_COND(singleton != nullptr); singleton = this; } @@ -249,7 +258,7 @@ Error GameSingleton::_update_colour_image() { InstanceManager const* instance_manager = get_instance_manager(); if (instance_manager != nullptr && !get_definition_manager().get_mapmode_manager().generate_mapmode_colours( - instance_manager->get_map_instance(), mapmode_index, colour_data_array.ptrw() + instance_manager->get_map_instance(), mapmode, colour_data_array.ptrw() )) { err = FAILED; } @@ -311,28 +320,37 @@ int32_t GameSingleton::get_mapmode_count() const { } String GameSingleton::get_mapmode_identifier(int32_t index) const { - Mapmode const* mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(index); - if (mapmode != nullptr) { - return Utilities::std_to_godot_string(mapmode->get_identifier()); + Mapmode const* identifier_mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(index); + if (identifier_mapmode != nullptr) { + return Utilities::std_to_godot_string(identifier_mapmode->get_identifier()); + } + return String {}; +} + +String GameSingleton::get_mapmode_localisation_key(int32_t index) const { + Mapmode const* localisation_key_mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(index); + if (localisation_key_mapmode != nullptr) { + return Utilities::std_to_godot_string(localisation_key_mapmode->get_localisation_key()); } return String {}; } -Error GameSingleton::set_mapmode(String const& identifier) { - Mapmode const* mapmode = - get_definition_manager().get_mapmode_manager().get_mapmode_by_identifier(Utilities::godot_to_std_string(identifier)); - ERR_FAIL_NULL_V_MSG(mapmode, FAILED, vformat("Failed to find mapmode with identifier: %s", identifier)); - mapmode_index = mapmode->get_index(); - return _update_colour_image(); +int32_t GameSingleton::get_current_mapmode_index() const { + return mapmode->get_index(); +} + +Error GameSingleton::set_mapmode(int32_t index) { + Mapmode const* new_mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(index); + ERR_FAIL_NULL_V_MSG(new_mapmode, FAILED, vformat("Failed to find mapmode with index: %d", index)); + mapmode = new_mapmode; + const Error err = _update_colour_image(); + emit_signal(_signal_mapmode_changed(), mapmode->get_index()); + return err; } bool GameSingleton::is_parchment_mapmode_allowed() const { - // TODO - parchment bool per mapmode? - // TODO - move mapmode index to SIM/Map? - /* Disallows parchment mapmode for the cosmetic terrain mapmode */ - static constexpr std::string_view cosmetic_terrain_mapmode = "mapmode_terrain"; - Mapmode const* mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(mapmode_index); - return mapmode != nullptr && mapmode->get_identifier() != cosmetic_terrain_mapmode; + /* Disallows parchment mapmode, e.g. for the cosmetic terrain mapmode */ + return mapmode->is_parchment_mapmode_allowed(); } int32_t GameSingleton::get_selected_province_index() const { diff --git a/extension/src/openvic-extension/singletons/GameSingleton.hpp b/extension/src/openvic-extension/singletons/GameSingleton.hpp index e737643..aa80141 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.hpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.hpp @@ -21,7 +21,7 @@ namespace OpenVic { godot::Ref<godot::Texture2DArray> province_shape_texture; godot::Ref<godot::Image> province_colour_image; godot::Ref<godot::ImageTexture> province_colour_texture; - Mapmode::index_t mapmode_index = 0; + Mapmode const* mapmode; // This should never be null, if no mapmode is set then it'll point to Mapmode::ERROR_MAPMODE godot::Ref<godot::Texture2DArray> terrain_texture; static const godot::Vector2i PROPERTY(flag_dims); /* The size in pixels of an individual flag. */ @@ -34,6 +34,7 @@ namespace OpenVic { static godot::StringName const& _signal_gamestate_updated(); static godot::StringName const& _signal_province_selected(); static godot::StringName const& _signal_clock_state_changed(); + static godot::StringName const& _signal_mapmode_changed(); godot::Error _load_map_images(); godot::Error _load_terrain_variants(); @@ -120,7 +121,9 @@ namespace OpenVic { int32_t get_mapmode_count() const; godot::String get_mapmode_identifier(int32_t index) const; - godot::Error set_mapmode(godot::String const& identifier); + godot::String get_mapmode_localisation_key(int32_t index) const; + int32_t get_current_mapmode_index() const; + godot::Error set_mapmode(int32_t index); bool is_parchment_mapmode_allowed() const; int32_t get_selected_province_index() const; void set_selected_province(int32_t index); |