aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/singletons
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-08-01 00:17:32 +0200
committer hop311 <hop3114@gmail.com>2024-08-02 22:54:08 +0200
commit06b76612b28183f0a047dac3a4127120d2af1b39 (patch)
tree9e7af8634eafc8461bd02697dd48ae36ca924858 /extension/src/openvic-extension/singletons
parent8431914a6971cbacfb20bba13a4113d9ac4d5153 (diff)
Use UTF8 encoding and simplify godot string conversionutf8-fix
Fixes #180: Province names do not convert non-ascii characters to Unicode
Diffstat (limited to 'extension/src/openvic-extension/singletons')
-rw-r--r--extension/src/openvic-extension/singletons/AssetManager.cpp13
-rw-r--r--extension/src/openvic-extension/singletons/GameSingleton.cpp29
-rw-r--r--extension/src/openvic-extension/singletons/LoadLocalisation.cpp4
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.cpp115
-rw-r--r--extension/src/openvic-extension/singletons/ModelSingleton.cpp65
-rw-r--r--extension/src/openvic-extension/singletons/PopulationMenu.cpp10
6 files changed, 120 insertions, 116 deletions
diff --git a/extension/src/openvic-extension/singletons/AssetManager.cpp b/extension/src/openvic-extension/singletons/AssetManager.cpp
index 6646c8b..eec1ada 100644
--- a/extension/src/openvic-extension/singletons/AssetManager.cpp
+++ b/extension/src/openvic-extension/singletons/AssetManager.cpp
@@ -9,9 +9,6 @@
using namespace godot;
using namespace OpenVic;
-using OpenVic::Utilities::godot_to_std_string;
-using OpenVic::Utilities::std_to_godot_string;
-
void AssetManager::_bind_methods() {
OV_BIND_METHOD(AssetManager::get_image, { "path", "load_flags" }, DEFVAL(LOAD_FLAG_CACHE_IMAGE));
OV_BIND_METHOD(AssetManager::get_texture, { "path", "load_flags" }, DEFVAL(LOAD_FLAG_CACHE_TEXTURE));
@@ -41,8 +38,9 @@ Ref<Image> AssetManager::_load_image(StringName const& path, bool flip_y) {
GameSingleton* game_singleton = GameSingleton::get_singleton();
ERR_FAIL_NULL_V(game_singleton, nullptr);
- const String lookedup_path =
- std_to_godot_string(game_singleton->get_dataloader().lookup_image_file(godot_to_std_string(path)).string());
+ const String lookedup_path = Utilities::std_to_godot_string(
+ game_singleton->get_dataloader().lookup_image_file(Utilities::godot_to_std_string(path)).string()
+ );
ERR_FAIL_COND_V_MSG(lookedup_path.is_empty(), nullptr, vformat("Failed to look up image: %s", path));
const Ref<Image> image = Utilities::load_godot_image(lookedup_path);
@@ -145,8 +143,9 @@ Ref<Font> AssetManager::get_font(StringName const& name) {
ERR_FAIL_NULL_V(game_singleton, nullptr);
const String font_path = font_dir + name + font_ext;
- const String lookedup_font_path =
- std_to_godot_string(game_singleton->get_dataloader().lookup_file(godot_to_std_string(font_path)).string());
+ const String lookedup_font_path = Utilities::std_to_godot_string(
+ game_singleton->get_dataloader().lookup_file(Utilities::godot_to_std_string(font_path)).string()
+ );
if (lookedup_font_path.is_empty()) {
fonts.emplace(name, nullptr);
diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp
index 33d70da..4960b4f 100644
--- a/extension/src/openvic-extension/singletons/GameSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp
@@ -16,11 +16,6 @@
using namespace godot;
using namespace OpenVic;
-using OpenVic::Utilities::godot_to_std_string;
-using OpenVic::Utilities::std_to_godot_string;
-using OpenVic::Utilities::std_to_godot_string_name;
-using OpenVic::Utilities::std_view_to_godot_string;
-
/* Maximum width or height a GPU texture can have. */
static constexpr int32_t GPU_DIM_LIMIT = 0x3FFF;
@@ -110,13 +105,13 @@ GameSingleton::~GameSingleton() {
void GameSingleton::setup_logger() {
Logger::set_info_func([](std::string&& str) {
- UtilityFunctions::print(std_to_godot_string(str));
+ UtilityFunctions::print(Utilities::std_to_godot_string(str));
});
Logger::set_warning_func([](std::string&& str) {
- UtilityFunctions::push_warning(std_to_godot_string(str));
+ UtilityFunctions::push_warning(Utilities::std_to_godot_string(str));
});
Logger::set_error_func([](std::string&& str) {
- UtilityFunctions::push_error(std_to_godot_string(str));
+ UtilityFunctions::push_error(Utilities::std_to_godot_string(str));
});
}
@@ -284,7 +279,7 @@ TypedArray<Dictionary> GameSingleton::get_province_names() const {
Dictionary province_dict;
- province_dict[identifier_key] = std_view_to_godot_string(province.get_identifier());
+ province_dict[identifier_key] = Utilities::std_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();
@@ -310,14 +305,14 @@ 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 std_view_to_godot_string(mapmode->get_identifier());
+ return Utilities::std_to_godot_string(mapmode->get_identifier());
}
return String {};
}
Error GameSingleton::set_mapmode(String const& identifier) {
Mapmode const* mapmode =
- get_definition_manager().get_mapmode_manager().get_mapmode_by_identifier(godot_to_std_string(identifier));
+ 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();
@@ -500,7 +495,7 @@ Error GameSingleton::_load_flag_sheet() {
/* Generate flag type - index lookup map */
flag_type_index_map.clear();
for (std::string const& type : government_type_manager.get_flag_types()) {
- flag_type_index_map.emplace(std_to_godot_string_name(type), static_cast<int32_t>(flag_type_index_map.size()));
+ flag_type_index_map.emplace(Utilities::std_to_godot_string(type), static_cast<int32_t>(flag_type_index_map.size()));
}
flag_sheet_count = country_definition_manager.get_country_definition_count() * flag_type_index_map.size();
@@ -512,7 +507,7 @@ Error GameSingleton::_load_flag_sheet() {
Error ret = OK;
for (CountryDefinition const& country : country_definition_manager.get_country_definitions()) {
- const String country_name = std_view_to_godot_string(country.get_identifier());
+ const String country_name = Utilities::std_to_godot_string(country.get_identifier());
for (auto const& [flag_type, flag_type_index] : flag_type_index_map) {
static const String flag_directory = "gfx/flags/";
@@ -590,7 +585,7 @@ Error GameSingleton::_load_flag_sheet() {
Error GameSingleton::load_defines_compatibility_mode(PackedStringArray const& file_paths) {
Dataloader::path_vector_t roots;
for (String const& path : file_paths) {
- roots.push_back(godot_to_std_string(path));
+ roots.push_back(Utilities::godot_to_std_string(path));
}
Error err = OK;
@@ -618,9 +613,11 @@ Error GameSingleton::load_defines_compatibility_mode(PackedStringArray const& fi
}
String GameSingleton::search_for_game_path(String const& hint_path) {
- return std_to_godot_string(Dataloader::search_for_game_path(godot_to_std_string(hint_path)).string());
+ return Utilities::std_to_godot_string(
+ Dataloader::search_for_game_path(Utilities::godot_to_std_string(hint_path)).string()
+ );
}
String GameSingleton::lookup_file_path(String const& path) const {
- return std_to_godot_string(get_dataloader().lookup_file(godot_to_std_string(path)).string());
+ return Utilities::std_to_godot_string(get_dataloader().lookup_file(Utilities::godot_to_std_string(path)).string());
}
diff --git a/extension/src/openvic-extension/singletons/LoadLocalisation.cpp b/extension/src/openvic-extension/singletons/LoadLocalisation.cpp
index 16ebe57..55073d6 100644
--- a/extension/src/openvic-extension/singletons/LoadLocalisation.cpp
+++ b/extension/src/openvic-extension/singletons/LoadLocalisation.cpp
@@ -136,8 +136,8 @@ bool LoadLocalisation::add_message(std::string_view key, Dataloader::locale_t lo
translation, false, vformat("Failed to get translation object: %s", Dataloader::locale_names[locale])
);
}
- const StringName godot_key = Utilities::std_view_to_godot_string_name(key);
- const StringName godot_localisation = Utilities::std_view_to_godot_string_name(localisation);
+ const StringName godot_key = Utilities::std_to_godot_string(key);
+ const StringName godot_localisation = Utilities::std_to_godot_string(localisation);
if (0) {
const StringName old_localisation = translation->get_message(godot_key);
if (!old_localisation.is_empty()) {
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
index 885915c..7a5f47f 100644
--- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
@@ -13,15 +13,13 @@
using namespace godot;
using namespace OpenVic;
-using OpenVic::Utilities::std_to_godot_string;
-using OpenVic::Utilities::std_view_to_godot_string;
-
StringName const& MenuSingleton::_signal_population_menu_province_list_changed() {
static const StringName signal_population_menu_province_list_changed = "population_menu_province_list_changed";
return signal_population_menu_province_list_changed;
}
StringName const& MenuSingleton::_signal_population_menu_province_list_selected_changed() {
- static const StringName signal_population_menu_province_list_selected_changed = "population_menu_province_list_selected_changed";
+ static const StringName signal_population_menu_province_list_selected_changed =
+ "population_menu_province_list_selected_changed";
return signal_population_menu_province_list_selected_changed;
}
StringName const& MenuSingleton::_signal_population_menu_pops_changed() {
@@ -36,7 +34,7 @@ StringName const& MenuSingleton::_signal_search_cache_changed() {
String MenuSingleton::get_state_name(State const& state) const {
StateSet const& state_set = state.get_state_set();
- const String region_identifier = std_view_to_godot_string(state_set.get_region().get_identifier());
+ const String region_identifier = Utilities::std_to_godot_string(state_set.get_region().get_identifier());
String name = tr(region_identifier);
@@ -46,7 +44,7 @@ String MenuSingleton::get_state_name(State const& state) const {
if (!named) {
// Capital province name
- name = tr(GUINode::format_province_name(std_view_to_godot_string(state.get_capital()->get_identifier())));
+ name = tr(GUINode::format_province_name(Utilities::std_to_godot_string(state.get_capital()->get_identifier())));
if (!owned) {
static const StringName region_key = "REGION_NAME";
@@ -72,7 +70,7 @@ String MenuSingleton::get_state_name(State const& state) const {
String MenuSingleton::get_country_name(CountryInstance const& country) const {
if (country.get_government_type() != nullptr && !country.get_government_type()->get_identifier().empty()) {
- const String government_name_key = std_to_godot_string(StringUtils::append_string_views(
+ const String government_name_key = Utilities::std_to_godot_string(StringUtils::append_string_views(
country.get_identifier(), "_", country.get_government_type()->get_identifier()
));
@@ -83,14 +81,14 @@ String MenuSingleton::get_country_name(CountryInstance const& country) const {
}
}
- return tr(std_view_to_godot_string(country.get_identifier()));
+ return tr(Utilities::std_to_godot_string(country.get_identifier()));
}
String MenuSingleton::get_country_adjective(CountryInstance const& country) const {
static constexpr std::string_view adjective = "_ADJ";
if (country.get_government_type() != nullptr && !country.get_government_type()->get_identifier().empty()) {
- const String government_adjective_key = std_to_godot_string(StringUtils::append_string_views(
+ const String government_adjective_key = Utilities::std_to_godot_string(StringUtils::append_string_views(
country.get_identifier(), "_", country.get_government_type()->get_identifier(), adjective
));
@@ -101,7 +99,7 @@ String MenuSingleton::get_country_adjective(CountryInstance const& country) cons
}
}
- return tr(std_to_godot_string(StringUtils::append_string_views(country.get_identifier(), adjective)));
+ return tr(Utilities::std_to_godot_string(StringUtils::append_string_views(country.get_identifier(), adjective)));
}
void MenuSingleton::_bind_methods() {
@@ -209,6 +207,48 @@ MenuSingleton::~MenuSingleton() {
/* PROVINCE OVERVIEW PANEL */
+static TypedArray<Dictionary> _make_buildings_dict_array(
+ ProvinceInstance const* province
+) {
+ std::vector<BuildingInstance> const& buildings = province->get_buildings();
+
+ if (buildings.empty()) {
+ return {};
+ }
+
+ static const StringName building_info_level_key = "level";
+ static const StringName building_info_expansion_state_key = "expansion_state";
+ static const StringName building_info_start_date_key = "start_date";
+ static const StringName building_info_end_date_key = "end_date";
+ static const StringName building_info_expansion_progress_key = "expansion_progress";
+
+ /* This system relies on the province buildings all being present in the right order. It will have to
+ * be changed if we want to support variable combinations and permutations of province buildings. */
+ TypedArray<Dictionary> buildings_array;
+
+ if (buildings_array.resize(buildings.size()) == OK) {
+ for (size_t idx = 0; idx < buildings.size(); ++idx) {
+ BuildingInstance const& building = buildings[idx];
+
+ Dictionary building_dict;
+ building_dict[building_info_level_key] = static_cast<int32_t>(building.get_level());
+ building_dict[building_info_expansion_state_key] = static_cast<int32_t>(building.get_expansion_state());
+ building_dict[building_info_start_date_key] = Utilities::std_to_godot_string(building.get_start_date().to_string());
+ building_dict[building_info_end_date_key] = Utilities::std_to_godot_string(building.get_end_date().to_string());
+ building_dict[building_info_expansion_progress_key] = building.get_expansion_progress();
+
+ buildings_array[idx] = std::move(building_dict);
+ }
+ } else {
+ UtilityFunctions::push_error(
+ "Failed to resize buildings array to the correct size (", static_cast<int64_t>(buildings.size()),
+ ") for province ", Utilities::std_to_godot_string(province->get_identifier())
+ );
+ }
+
+ return buildings_array;
+}
+
Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const {
GameSingleton const* game_singleton = GameSingleton::get_singleton();
ERR_FAIL_NULL_V(game_singleton, {});
@@ -239,7 +279,7 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const {
}
Dictionary ret;
- ret[province_info_province_key] = std_view_to_godot_string(province->get_identifier());
+ ret[province_info_province_key] = Utilities::std_to_godot_string(province->get_identifier());
State const* state = province->get_state();
if (state != nullptr) {
@@ -252,25 +292,25 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const {
TerrainType const* terrain_type = province->get_terrain_type();
if (terrain_type != nullptr) {
- ret[province_info_terrain_type_key] = std_view_to_godot_string(terrain_type->get_identifier());
+ ret[province_info_terrain_type_key] = Utilities::std_to_godot_string(terrain_type->get_identifier());
}
ret[province_info_life_rating_key] = province->get_life_rating();
CountryInstance const* controller = province->get_controller();
if (controller != nullptr) {
- ret[province_info_controller_key] = std_view_to_godot_string(controller->get_identifier());
+ ret[province_info_controller_key] = Utilities::std_to_godot_string(controller->get_identifier());
}
GoodDefinition const* rgo = province->get_rgo();
if (rgo != nullptr) {
- ret[province_info_rgo_name_key] = std_view_to_godot_string(rgo->get_identifier());
+ ret[province_info_rgo_name_key] = Utilities::std_to_godot_string(rgo->get_identifier());
ret[province_info_rgo_icon_key] = static_cast<int32_t>(rgo->get_index());
}
Crime const* crime = province->get_crime();
if (crime != nullptr) {
- ret[province_info_crime_name_key] = std_view_to_godot_string(crime->get_identifier());
+ ret[province_info_crime_name_key] = Utilities::std_to_godot_string(crime->get_identifier());
ret[province_info_crime_icon_key] = static_cast<int32_t>(crime->get_icon());
}
@@ -299,49 +339,22 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const {
PackedStringArray cores_array;
if (cores_array.resize(cores.size()) == OK) {
for (size_t idx = 0; idx < cores.size(); ++idx) {
- cores_array[idx] = std_view_to_godot_string(cores.data()[idx]->get_identifier());
+ cores_array[idx] = Utilities::std_to_godot_string(cores.data()[idx]->get_identifier());
}
ret[province_info_cores_key] = std::move(cores_array);
} else {
UtilityFunctions::push_error(
"Failed to resize cores array to the correct size (", static_cast<int64_t>(cores.size()), ") for province ",
- std_view_to_godot_string(province->get_identifier())
+ Utilities::std_to_godot_string(province->get_identifier())
);
}
}
- static const StringName building_info_level_key = "level";
- static const StringName building_info_expansion_state_key = "expansion_state";
- static const StringName building_info_start_date_key = "start_date";
- static const StringName building_info_end_date_key = "end_date";
- static const StringName building_info_expansion_progress_key = "expansion_progress";
-
- std::vector<BuildingInstance> const& buildings = province->get_buildings();
- if (!buildings.empty()) {
- /* This system relies on the province buildings all being present in the right order. It will have to
- * be changed if we want to support variable combinations and permutations of province buildings. */
- TypedArray<Dictionary> buildings_array;
- if (buildings_array.resize(buildings.size()) == OK) {
- for (size_t idx = 0; idx < buildings.size(); ++idx) {
- BuildingInstance const& building = buildings[idx];
-
- Dictionary building_dict;
- building_dict[building_info_level_key] = static_cast<int32_t>(building.get_level());
- building_dict[building_info_expansion_state_key] = static_cast<int32_t>(building.get_expansion_state());
- building_dict[building_info_start_date_key] = std_to_godot_string(building.get_start_date().to_string());
- building_dict[building_info_end_date_key] = std_to_godot_string(building.get_end_date().to_string());
- building_dict[building_info_expansion_progress_key] = building.get_expansion_progress();
-
- buildings_array[idx] = std::move(building_dict);
- }
- ret[province_info_buildings_key] = std::move(buildings_array);
- } else {
- UtilityFunctions::push_error(
- "Failed to resize buildings array to the correct size (", static_cast<int64_t>(buildings.size()),
- ") for province ", std_view_to_godot_string(province->get_identifier())
- );
- }
+ TypedArray<Dictionary> building_dict_array = _make_buildings_dict_array(province);
+ if (!building_dict_array.is_empty()) {
+ ret[province_info_buildings_key] = std::move(building_dict_array);
}
+
return ret;
}
@@ -363,7 +376,7 @@ String MenuSingleton::get_province_building_identifier(int32_t building_index) c
building_index < 0 || building_index >= province_building_types.size(), {},
vformat("Invalid province building index: %d", building_index)
);
- return std_view_to_godot_string(province_building_types[building_index]->get_identifier());
+ return Utilities::std_to_godot_string(province_building_types[building_index]->get_identifier());
}
Error MenuSingleton::expand_selected_province_building(int32_t building_index) {
@@ -505,7 +518,7 @@ Error MenuSingleton::generate_search_cache() {
search_panel.entry_cache.reserve(provinces.size() + state_sets.size() + countries.size());
for (ProvinceInstance const& province : provinces) {
- String identifier = std_view_to_godot_string(province.get_identifier());
+ String identifier = Utilities::std_to_godot_string(province.get_identifier());
String display_name = tr(GUINode::format_province_name(identifier));
String search_name = display_name.to_lower();
@@ -534,7 +547,7 @@ Error MenuSingleton::generate_search_cache() {
search_panel.entry_cache.push_back({
&country, std::move(display_name), std::move(search_name),
- std_view_to_godot_string(country.get_identifier()).to_lower()
+ Utilities::std_to_godot_string(country.get_identifier()).to_lower()
});
}
}
diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.cpp b/extension/src/openvic-extension/singletons/ModelSingleton.cpp
index ebdc7e8..f51ae77 100644
--- a/extension/src/openvic-extension/singletons/ModelSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/ModelSingleton.cpp
@@ -13,10 +13,6 @@
using namespace godot;
using namespace OpenVic;
-using OpenVic::Utilities::godot_to_std_string;
-using OpenVic::Utilities::std_to_godot_string;
-using OpenVic::Utilities::std_view_to_godot_string;
-
void ModelSingleton::_bind_methods() {
OV_BIND_METHOD(ModelSingleton::get_units);
OV_BIND_METHOD(ModelSingleton::get_cultural_gun_model, { "culture" });
@@ -47,7 +43,7 @@ GFX::Actor const* ModelSingleton::get_actor(std::string_view name, bool error_on
game_singleton->get_definition_manager().get_ui_manager().get_cast_object_by_identifier<GFX::Actor>(name);
if (error_on_fail) {
- ERR_FAIL_NULL_V_MSG(actor, nullptr, vformat("Failed to find actor \"%s\"", std_view_to_godot_string(name)));
+ ERR_FAIL_NULL_V_MSG(actor, nullptr, vformat("Failed to find actor \"%s\"", Utilities::std_to_godot_string(name)));
}
return actor;
@@ -62,7 +58,7 @@ GFX::Actor const* ModelSingleton::get_cultural_actor(
ERR_FAIL_COND_V_MSG(
culture.empty() || name.empty(), nullptr, vformat(
"Failed to find actor \"%s\" for culture \"%s\" - neither can be empty",
- std_view_to_godot_string(name), std_view_to_godot_string(culture)
+ Utilities::std_to_godot_string(name), Utilities::std_to_godot_string(culture)
)
);
@@ -90,8 +86,8 @@ GFX::Actor const* ModelSingleton::get_cultural_actor(
ERR_FAIL_NULL_V_MSG(
actor, nullptr, vformat(
- "Failed to find actor \"%s\" for culture \"%s\"", std_view_to_godot_string(name),
- std_view_to_godot_string(culture)
+ "Failed to find actor \"%s\" for culture \"%s\"", Utilities::std_to_godot_string(name),
+ Utilities::std_to_godot_string(culture)
)
);
@@ -109,7 +105,7 @@ Dictionary ModelSingleton::get_animation_dict(GFX::Actor::Animation const& anima
Dictionary dict;
- dict[file_key] = std_view_to_godot_string(animation.get_file());
+ dict[file_key] = Utilities::std_to_godot_string(animation.get_file());
dict[time_key] = animation.get_scroll_time().to_float();
animation_cache.emplace(&animation, dict);
@@ -132,7 +128,7 @@ Dictionary ModelSingleton::get_model_dict(GFX::Actor const& actor) {
Dictionary dict;
- dict[file_key] = std_view_to_godot_string(actor.get_model_file());
+ dict[file_key] = Utilities::std_to_godot_string(actor.get_model_file());
dict[scale_key] = actor.get_scale().to_float();
const auto set_animation = [this, &dict](StringName const& key, std::optional<GFX::Actor::Animation> const& animation) {
@@ -164,13 +160,14 @@ Dictionary ModelSingleton::get_model_dict(GFX::Actor const& actor) {
ERR_CONTINUE_MSG(
attachment_actor == nullptr, vformat(
"Failed to find \"%s\" attachment actor for actor \"%s\"",
- std_view_to_godot_string(attachment.get_actor_name()), std_view_to_godot_string(actor.get_name())
+ Utilities::std_to_godot_string(attachment.get_actor_name()),
+ Utilities::std_to_godot_string(actor.get_name())
)
);
Dictionary attachment_dict;
- attachment_dict[attachment_node_key] = std_view_to_godot_string(attachment.get_attach_node());
+ attachment_dict[attachment_node_key] = Utilities::std_to_godot_string(attachment.get_attach_node());
attachment_dict[attachment_model_key] = get_model_dict(*attachment_actor);
attachments_array[idx] = std::move(attachment_dict);
@@ -184,7 +181,7 @@ Dictionary ModelSingleton::get_model_dict(GFX::Actor const& actor) {
} else {
UtilityFunctions::push_error(
"Failed to resize attachments array to the correct size (", static_cast<int64_t>(attachments.size()),
- ") for model for actor \"", std_view_to_godot_string(actor.get_name()), "\""
+ ") for model for actor \"", Utilities::std_to_godot_string(actor.get_name()), "\""
);
}
}
@@ -225,7 +222,7 @@ bool ModelSingleton::add_unit_dict(
/* Last unit to enter the province is shown on top. */
_UnitInstanceGroup const& unit = *units.back();
- ERR_FAIL_COND_V_MSG(unit.empty(), false, vformat("Empty unit \"%s\"", std_view_to_godot_string(unit.get_name())));
+ ERR_FAIL_COND_V_MSG(unit.empty(), false, vformat("Empty unit \"%s\"", Utilities::std_to_godot_string(unit.get_name())));
CountryDefinition const* country = unit.get_country()->get_country_definition();
@@ -233,7 +230,7 @@ bool ModelSingleton::add_unit_dict(
UnitType const* display_unit_type = unit.get_display_unit_type();
ERR_FAIL_NULL_V_MSG(
display_unit_type, false, vformat(
- "Failed to get display unit type for unit \"%s\"", std_view_to_godot_string(unit.get_name())
+ "Failed to get display unit type for unit \"%s\"", Utilities::std_to_godot_string(unit.get_name())
)
);
@@ -255,9 +252,9 @@ bool ModelSingleton::add_unit_dict(
} else {
UtilityFunctions::push_error(
"Mount sprite and attach node must both be set or both be empty - regiment type \"",
- std_view_to_godot_string(regiment_type->get_identifier()), "\" has mount \"",
- std_view_to_godot_string(regiment_type->get_sprite_mount()), "\" and attach node \"",
- std_view_to_godot_string(regiment_type->get_sprite_mount_attach_node()), "\""
+ Utilities::std_to_godot_string(regiment_type->get_identifier()), "\" has mount \"",
+ Utilities::std_to_godot_string(regiment_type->get_sprite_mount()), "\" and attach node \"",
+ Utilities::std_to_godot_string(regiment_type->get_sprite_mount_attach_node()), "\""
);
ret = false;
}
@@ -272,15 +269,15 @@ bool ModelSingleton::add_unit_dict(
ERR_FAIL_NULL_V_MSG(
actor, false, vformat(
"Failed to find \"%s\" actor of graphical culture type \"%s\" for unit \"%s\"",
- std_view_to_godot_string(display_unit_type->get_sprite()),
- std_view_to_godot_string(graphical_culture_type.get_identifier()),
- std_view_to_godot_string(unit.get_name())
+ Utilities::std_to_godot_string(display_unit_type->get_sprite()),
+ Utilities::std_to_godot_string(graphical_culture_type.get_identifier()),
+ Utilities::std_to_godot_string(unit.get_name())
)
);
Dictionary dict;
- dict[culture_key] = std_view_to_godot_string(graphical_culture_type.get_identifier());
+ dict[culture_key] = Utilities::std_to_godot_string(graphical_culture_type.get_identifier());
dict[model_key] = get_model_dict(*actor);
@@ -289,13 +286,13 @@ bool ModelSingleton::add_unit_dict(
if (mount_actor != nullptr) {
dict[mount_model_key] = get_model_dict(*mount_actor);
- dict[mount_attach_node_key] = std_view_to_godot_string(mount_attach_node_name);
+ dict[mount_attach_node_key] = Utilities::std_to_godot_string(mount_attach_node_name);
} else {
UtilityFunctions::push_error(vformat(
"Failed to find \"%s\" mount actor of graphical culture type \"%s\" for unit \"%s\"",
- std_view_to_godot_string(mount_actor_name),
- std_view_to_godot_string(graphical_culture_type.get_identifier()),
- std_view_to_godot_string(unit.get_name())
+ Utilities::std_to_godot_string(mount_actor_name),
+ Utilities::std_to_godot_string(graphical_culture_type.get_identifier()),
+ Utilities::std_to_godot_string(unit.get_name())
));
ret = false;
}
@@ -337,13 +334,13 @@ TypedArray<Dictionary> ModelSingleton::get_units() {
if (province.get_province_definition().is_water()) {
if (!add_unit_dict(province.get_navies(), ret)) {
UtilityFunctions::push_error(
- "Error adding navy to province \"", std_view_to_godot_string(province.get_identifier()), "\""
+ "Error adding navy to province \"", Utilities::std_to_godot_string(province.get_identifier()), "\""
);
}
} else {
if (!add_unit_dict(province.get_armies(), ret)) {
UtilityFunctions::push_error(
- "Error adding army to province \"", std_view_to_godot_string(province.get_identifier()), "\""
+ "Error adding army to province \"", Utilities::std_to_godot_string(province.get_identifier()), "\""
);
}
}
@@ -357,7 +354,7 @@ TypedArray<Dictionary> ModelSingleton::get_units() {
Dictionary ModelSingleton::get_cultural_gun_model(String const& culture) {
static constexpr std::string_view gun_actor_name = "Gun1";
- GFX::Actor const* actor = get_cultural_actor(godot_to_std_string(culture), gun_actor_name, {});
+ GFX::Actor const* actor = get_cultural_actor(Utilities::godot_to_std_string(culture), gun_actor_name, {});
ERR_FAIL_NULL_V(actor, {});
@@ -367,7 +364,7 @@ Dictionary ModelSingleton::get_cultural_gun_model(String const& culture) {
Dictionary ModelSingleton::get_cultural_helmet_model(String const& culture) {
static constexpr std::string_view helmet_actor_name = "Helmet1";
- GFX::Actor const* actor = get_cultural_actor(godot_to_std_string(culture), helmet_actor_name, {});
+ GFX::Actor const* actor = get_cultural_actor(Utilities::godot_to_std_string(culture), helmet_actor_name, {});
ERR_FAIL_NULL_V(actor, {});
@@ -438,8 +435,8 @@ bool ModelSingleton::add_building_dict(
ERR_FAIL_NULL_V_MSG(
actor, false, vformat(
"Failed to find \"%s\" actor for building \"%s\" in province \"%s\"",
- std_to_godot_string(actor_name), std_view_to_godot_string(building.get_identifier()),
- std_view_to_godot_string(province.get_identifier())
+ Utilities::std_to_godot_string(actor_name), Utilities::std_to_godot_string(building.get_identifier()),
+ Utilities::std_to_godot_string(province.get_identifier())
)
);
@@ -474,8 +471,8 @@ TypedArray<Dictionary> ModelSingleton::get_buildings() {
for (BuildingInstance const& building : province.get_buildings()) {
if (!add_building_dict(building, province, ret)) {
UtilityFunctions::push_error(
- "Error adding building \"", std_view_to_godot_string(building.get_identifier()), "\" to province \"",
- std_view_to_godot_string(province.get_identifier()), "\""
+ "Error adding building \"", Utilities::std_to_godot_string(building.get_identifier()),
+ "\" to province \"", Utilities::std_to_godot_string(province.get_identifier()), "\""
);
}
}
diff --git a/extension/src/openvic-extension/singletons/PopulationMenu.cpp b/extension/src/openvic-extension/singletons/PopulationMenu.cpp
index 65987ad..271068b 100644
--- a/extension/src/openvic-extension/singletons/PopulationMenu.cpp
+++ b/extension/src/openvic-extension/singletons/PopulationMenu.cpp
@@ -13,8 +13,6 @@
using namespace godot;
using namespace OpenVic;
-using OpenVic::Utilities::std_view_to_godot_string;
-
/* POPULATION MENU */
Error MenuSingleton::_population_menu_update_provinces() {
@@ -152,7 +150,7 @@ TypedArray<Dictionary> MenuSingleton::get_population_menu_province_list_rows(int
province_dict[type_key] = population_menu_t::LIST_ENTRY_PROVINCE;
province_dict[index_key] = index;
- province_dict[name_key] = std_view_to_godot_string(province_entry.province.get_identifier());
+ province_dict[name_key] = Utilities::std_to_godot_string(province_entry.province.get_identifier());
province_dict[size_key] = province_entry.province.get_total_population();
province_dict[change_key] = 0;
province_dict[selected_key] = province_entry.selected;
@@ -541,7 +539,7 @@ Error MenuSingleton::population_menu_update_locale_sort_cache() {
sorted_items.resize(items.size());
for (size_t idx = 0; idx < items.size(); ++idx) {
- String identifier = std_view_to_godot_string(items[idx].get_identifier());
+ String identifier = Utilities::std_to_godot_string(items[idx].get_identifier());
if constexpr (std::is_same_v<T, ProvinceInstance>) {
identifier = GUINode::format_province_name(identifier);
}
@@ -676,10 +674,10 @@ TypedArray<Dictionary> MenuSingleton::get_population_menu_pop_rows(int32_t start
pop_dict[pop_size_key] = pop->get_size();
pop_dict[pop_type_icon_key] = pop->get_type().get_sprite();
- pop_dict[pop_culture_key] = std_view_to_godot_string(pop->get_culture().get_identifier());
+ pop_dict[pop_culture_key] = Utilities::std_to_godot_string(pop->get_culture().get_identifier());
pop_dict[pop_religion_icon_key] = pop->get_religion().get_icon();
if (pop->get_location() != nullptr) {
- pop_dict[pop_location_key] = std_view_to_godot_string(pop->get_location()->get_identifier());
+ pop_dict[pop_location_key] = Utilities::std_to_godot_string(pop->get_location()->get_identifier());
}
pop_dict[pop_militancy_key] = pop->get_militancy().to_float();
pop_dict[pop_consciousness_key] = pop->get_consciousness().to_float();