diff options
author | Hop311 <Hop3114@gmail.com> | 2024-09-10 20:14:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-10 20:14:49 +0200 |
commit | dc0b0ede2368b43ab6c91a5e24d76ec34e91cf46 (patch) | |
tree | 732102566650ae717c43db5c2381fb72ce8ed88c /extension/src/openvic-extension/singletons/GameSingleton.cpp | |
parent | cfad2d9e2011a5b930efa14e07ce9caf25d9459a (diff) | |
parent | 6d4b8b087b62b5487d72cc6c2265b3e00afb9c8a (diff) |
Merge pull request #266 from OpenVicProject/ranking
Ranking + army topbar info
Diffstat (limited to 'extension/src/openvic-extension/singletons/GameSingleton.cpp')
-rw-r--r-- | extension/src/openvic-extension/singletons/GameSingleton.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp index 24d8a73..f258fe1 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.cpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp @@ -69,6 +69,8 @@ void GameSingleton::_bind_methods() { OV_BIND_METHOD(GameSingleton::set_selected_province, { "index" }); OV_BIND_METHOD(GameSingleton::unset_selected_province); + OV_BIND_METHOD(GameSingleton::set_viewed_country_by_province_index, { "province_index" }); + OV_BIND_METHOD(GameSingleton::update_clock); ADD_SIGNAL(MethodInfo(_signal_gamestate_updated())); @@ -95,7 +97,7 @@ void GameSingleton::_on_clock_state_changed() { GameSingleton::GameSingleton() : game_manager { std::bind(&GameSingleton::_on_gamestate_updated, this), std::bind(&GameSingleton::_on_clock_state_changed, this) - } { + }, viewed_country { nullptr } { ERR_FAIL_COND(singleton != nullptr); singleton = this; } @@ -139,6 +141,10 @@ Error GameSingleton::setup_game(int32_t bookmark_index) { ERR_FAIL_NULL_V(menu_singleton, FAILED); ret &= menu_singleton->_population_menu_update_provinces() == OK; + // TODO - replace with actual starting country + set_viewed_country(instance_manager->get_country_instance_manager().get_country_instance_by_identifier("ENG")); + ERR_FAIL_NULL_V(viewed_country, FAILED); + return ERR(ret); } @@ -349,6 +355,27 @@ void GameSingleton::unset_selected_province() { set_selected_province(ProvinceDefinition::NULL_INDEX); } +void GameSingleton::set_viewed_country(CountryInstance const* new_viewed_country) { + if (viewed_country != new_viewed_country) { + viewed_country = new_viewed_country; + + Logger::info("Set viewed country to: ", viewed_country != nullptr ? viewed_country->get_identifier() : "NULL"); + + _on_gamestate_updated(); + } +} + +void GameSingleton::set_viewed_country_by_province_index(int32_t province_index) { + InstanceManager* instance_manager = get_instance_manager(); + ERR_FAIL_NULL(instance_manager); + + ProvinceInstance const* province_instance = + instance_manager->get_map_instance().get_province_instance_by_index(province_index); + ERR_FAIL_NULL(province_instance); + + set_viewed_country(province_instance->get_owner()); +} + Error GameSingleton::update_clock() { return ERR(game_manager.update_clock()); } |