11#include " GameSingleton.hpp"
22
3+ #include < cstdint>
34#include < functional>
5+ #include < type_safe/strong_typedef.hpp>
46
57#include < godot_cpp/classes/time.hpp>
68#include < godot_cpp/core/error_macros.hpp>
79#include < godot_cpp/variant/packed_string_array.hpp>
810#include < godot_cpp/variant/utility_functions.hpp>
911
1012#include < openvic-simulation/dataloader/ModManager.hpp>
13+ #include < openvic-simulation/DefinitionManager.hpp>
14+ #include < openvic-simulation/map/Crime.hpp>
15+ #include < openvic-simulation/types/TypedIndices.hpp>
1116#include < openvic-simulation/utility/Containers.hpp>
1217#include < openvic-simulation/utility/Logger.hpp>
1318
@@ -203,19 +208,21 @@ TypedArray<Dictionary> GameSingleton::get_bookmark_info() const {
203208}
204209
205210Error GameSingleton::setup_game (int32_t bookmark_index) {
206- Bookmark const * bookmark =
207- game_manager.get_definition_manager ().get_history_manager ().get_bookmark_manager ().get_bookmark_by_index (bookmark_index
208- );
211+ DefinitionManager const & definition_manager = game_manager.get_definition_manager ();
212+ Bookmark const * bookmark = definition_manager.get_history_manager ()
213+ .get_bookmark_manager ()
214+ .get_bookmark_by_index (bookmark_index_t (bookmark_index));
209215 ERR_FAIL_NULL_V_MSG (bookmark, FAILED, Utilities::format (" Failed to get bookmark with index: %d" , bookmark_index));
210- bool ret = game_manager.setup_instance (bookmark);
216+ bool ret = game_manager.setup_instance (* bookmark);
211217
212218 // TODO - remove this temporary crime assignment
213219 InstanceManager* instance_manager = get_instance_manager ();
214220 ERR_FAIL_NULL_V_MSG (instance_manager, FAILED, " Failed to setup instance manager!" );
221+
222+ CrimeManager const & crime_manager = definition_manager.get_crime_manager ();
215223 for (ProvinceInstance& province : instance_manager->get_map_instance ().get_province_instances ()) {
216- province.set_crime (get_definition_manager ().get_crime_manager ().get_crime_modifier_by_index (
217- province.index % get_definition_manager ().get_crime_manager ().get_crime_modifier_count ()
218- ));
224+ const crime_index_t crime_index = crime_index_t (type_safe::get (province.index ) % crime_manager.get_crime_modifier_count ());
225+ province.set_crime (crime_manager.get_crime_modifier_by_index (crime_index));
219226 }
220227
221228 ret &= MenuSingleton::get_singleton ()->_population_menu_update_provinces () == OK;
@@ -314,17 +321,18 @@ Ref<ImageTexture> GameSingleton::get_flag_sheet_texture() const {
314321 return flag_sheet_texture;
315322}
316323
317- int32_t GameSingleton::get_flag_sheet_index (int32_t country_index, StringName const & flag_type) const {
324+ int32_t GameSingleton::get_flag_sheet_index (const country_index_t country_index, StringName const & flag_type) const {
325+ const uint64_t index = static_cast <uint64_t >(type_safe::get (country_index));
318326 ERR_FAIL_COND_V_MSG (
319- country_index < 0 ||
320- country_index >= get_definition_manager ().get_country_definition_manager ().get_country_definition_count (),
321- -1 , Utilities::format (" Invalid country index: %d" , country_index )
327+ index < 0 ||
328+ index >= get_definition_manager ().get_country_definition_manager ().get_country_definition_count (),
329+ -1 , Utilities::format (" Invalid country index: %d" , index )
322330 );
323331
324332 const typename decltype (flag_type_index_map)::const_iterator it = flag_type_index_map.find (flag_type);
325333 ERR_FAIL_COND_V_MSG (it == flag_type_index_map.end (), -1 , Utilities::format (" Invalid flag type %s" , flag_type));
326334
327- return flag_type_index_map.size () * country_index + it->second ;
335+ return flag_type_index_map.size () * index + it->second ;
328336}
329337
330338Rect2i GameSingleton::get_flag_sheet_rect (int32_t flag_index) const {
@@ -335,7 +343,7 @@ Rect2i GameSingleton::get_flag_sheet_rect(int32_t flag_index) const {
335343 return { Vector2i { flag_index % flag_sheet_dims.x , flag_index / flag_sheet_dims.x } * flag_dims, flag_dims };
336344}
337345
338- Rect2i GameSingleton::get_flag_sheet_rect (int32_t country_index, StringName const & flag_type) const {
346+ Rect2i GameSingleton::get_flag_sheet_rect (const country_index_t country_index, StringName const & flag_type) const {
339347 return get_flag_sheet_rect (get_flag_sheet_index (country_index, flag_type));
340348}
341349
@@ -408,9 +416,7 @@ TypedArray<Dictionary> GameSingleton::get_province_names() const {
408416 TypedArray<Dictionary> ret;
409417 ERR_FAIL_COND_V (ret.resize (map_definition.get_province_definition_count ()) != OK, {});
410418
411- for (int32_t index = 0 ; index < map_definition.get_province_definition_count (); ++index) {
412- ProvinceDefinition const & province = map_definition.get_province_definitions ()[index];
413-
419+ for (ProvinceDefinition const & province : map_definition.get_province_definitions ()) {
414420 Dictionary province_dict;
415421
416422 province_dict[identifier_key] = convert_to<String>(province.get_identifier ());
@@ -426,7 +432,7 @@ TypedArray<Dictionary> GameSingleton::get_province_names() const {
426432 province_dict[scale_key] = scale;
427433 }
428434
429- ret[index] = std::move (province_dict);
435+ ret[type_safe::get (province. index ) ] = std::move (province_dict);
430436 }
431437
432438 return ret;
@@ -437,31 +443,37 @@ int32_t GameSingleton::get_mapmode_count() const {
437443}
438444
439445String GameSingleton::get_mapmode_identifier (int32_t index) const {
440- Mapmode const * identifier_mapmode = get_definition_manager ().get_mapmode_manager ().get_mapmode_by_index (index);
446+ Mapmode const * identifier_mapmode = get_definition_manager ()
447+ .get_mapmode_manager ()
448+ .get_mapmode_by_index (map_mode_index_t (index));
441449 if (identifier_mapmode != nullptr ) {
442450 return convert_to<String>(identifier_mapmode->get_identifier ());
443451 }
444452 return String {};
445453}
446454
447455String GameSingleton::get_mapmode_localisation_key (int32_t index) const {
448- Mapmode const * localisation_key_mapmode = get_definition_manager ().get_mapmode_manager ().get_mapmode_by_index (index);
456+ Mapmode const * localisation_key_mapmode = get_definition_manager ()
457+ .get_mapmode_manager ()
458+ .get_mapmode_by_index (map_mode_index_t (index));
449459 if (localisation_key_mapmode != nullptr ) {
450460 return convert_to<String>(localisation_key_mapmode->get_localisation_key ());
451461 }
452462 return String {};
453463}
454464
455465int32_t GameSingleton::get_current_mapmode_index () const {
456- return mapmode->index ;
466+ return type_safe::get ( mapmode->index ) ;
457467}
458468
459469Error GameSingleton::set_mapmode (int32_t index) {
460- Mapmode const * new_mapmode = get_definition_manager ().get_mapmode_manager ().get_mapmode_by_index (index);
470+ Mapmode const * new_mapmode = get_definition_manager ()
471+ .get_mapmode_manager ()
472+ .get_mapmode_by_index (map_mode_index_t (index));
461473 ERR_FAIL_NULL_V_MSG (new_mapmode, FAILED, Utilities::format (" Failed to find mapmode with index: %d" , index));
462474 mapmode = new_mapmode;
463475 const Error err = _update_colour_image ();
464- emit_signal (_signal_mapmode_changed (), mapmode->index );
476+ emit_signal (_signal_mapmode_changed (), static_cast < uint64_t >( type_safe::get ( mapmode->index )) );
465477 return err;
466478}
467479
0 commit comments