diff options
author | Hop311 <Hop3114@gmail.com> | 2024-08-03 00:50:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-03 00:50:17 +0200 |
commit | fde15e554dc9ed458a838683c69d10262764db12 (patch) | |
tree | 9e7af8634eafc8461bd02697dd48ae36ca924858 /extension/src/openvic-extension/classes | |
parent | 8431914a6971cbacfb20bba13a4113d9ac4d5153 (diff) | |
parent | 06b76612b28183f0a047dac3a4127120d2af1b39 (diff) |
Merge pull request #249 from OpenVicProject/utf8-fix
Use UTF8 encoding and simplify godot string conversion
Diffstat (limited to 'extension/src/openvic-extension/classes')
7 files changed, 42 insertions, 45 deletions
diff --git a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp index c17fa0e..3714c5f 100644 --- a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp +++ b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp @@ -9,10 +9,6 @@ using namespace godot; using namespace OpenVic; -using OpenVic::Utilities::godot_to_std_string; -using OpenVic::Utilities::std_view_to_godot_string; -using OpenVic::Utilities::std_view_to_godot_string_name; - Error GFXMaskedFlagTexture::_generate_combined_image() { ERR_FAIL_NULL_V(overlay_image, FAILED); /* Whether we've already set the ImageTexture to an image of the right dimensions and format, @@ -127,11 +123,11 @@ Error GFXMaskedFlagTexture::set_gfx_masked_flag(GFX::MaskedFlag const* new_gfx_m AssetManager* asset_manager = AssetManager::get_singleton(); ERR_FAIL_NULL_V(asset_manager, FAILED); - const StringName overlay_file = std_view_to_godot_string_name(new_gfx_masked_flag->get_overlay_file()); + const StringName overlay_file = Utilities::std_to_godot_string(new_gfx_masked_flag->get_overlay_file()); const Ref<Image> new_overlay_image = asset_manager->get_image(overlay_file); ERR_FAIL_NULL_V_MSG(new_overlay_image, FAILED, vformat("Failed to load flag overlay image: %s", overlay_file)); - const StringName mask_file = std_view_to_godot_string_name(new_gfx_masked_flag->get_mask_file()); + const StringName mask_file = Utilities::std_to_godot_string(new_gfx_masked_flag->get_mask_file()); const Ref<Image> new_mask_image = asset_manager->get_image(mask_file); ERR_FAIL_NULL_V_MSG(new_mask_image, FAILED, vformat("Failed to load flag mask image: %s", mask_file)); @@ -152,14 +148,15 @@ Error GFXMaskedFlagTexture::set_gfx_masked_flag_name(String const& gfx_masked_fl ERR_FAIL_NULL_V_MSG( new_masked_flag, FAILED, vformat( "Invalid type for GFX sprite %s: %s (expected %s)", gfx_masked_flag_name, - std_view_to_godot_string(sprite->get_type()), std_view_to_godot_string(GFX::MaskedFlag::get_type_static()) + Utilities::std_to_godot_string(sprite->get_type()), + Utilities::std_to_godot_string(GFX::MaskedFlag::get_type_static()) ) ); return set_gfx_masked_flag(new_masked_flag); } String GFXMaskedFlagTexture::get_gfx_masked_flag_name() const { - return gfx_masked_flag != nullptr ? std_view_to_godot_string(gfx_masked_flag->get_name()) : String {}; + return gfx_masked_flag != nullptr ? Utilities::std_to_godot_string(gfx_masked_flag->get_name()) : String {}; } Error GFXMaskedFlagTexture::set_flag_country_and_type( @@ -197,7 +194,7 @@ Error GFXMaskedFlagTexture::set_flag_country_name_and_type( ERR_FAIL_NULL_V(game_singleton, FAILED); CountryDefinition const* new_flag_country = game_singleton->get_definition_manager().get_country_definition_manager().get_country_definition_by_identifier( - godot_to_std_string(new_flag_country_name) + Utilities::godot_to_std_string(new_flag_country_name) ); ERR_FAIL_NULL_V_MSG(new_flag_country, FAILED, vformat("Country not found: %s", new_flag_country_name)); return set_flag_country_and_type(new_flag_country, new_flag_type); @@ -216,12 +213,12 @@ Error GFXMaskedFlagTexture::set_flag_country_name(String const& new_flag_country ERR_FAIL_NULL_V(game_singleton, FAILED); CountryDefinition const* new_flag_country = game_singleton->get_definition_manager().get_country_definition_manager().get_country_definition_by_identifier( - godot_to_std_string(new_flag_country_name) + Utilities::godot_to_std_string(new_flag_country_name) ); ERR_FAIL_NULL_V_MSG(new_flag_country, FAILED, vformat("Country not found: %s", new_flag_country_name)); return set_flag_country(new_flag_country); } String GFXMaskedFlagTexture::get_flag_country_name() const { - return flag_country != nullptr ? std_view_to_godot_string(flag_country->get_identifier()) : String {}; + return flag_country != nullptr ? Utilities::std_to_godot_string(flag_country->get_identifier()) : String {}; } diff --git a/extension/src/openvic-extension/classes/GFXPieChartTexture.cpp b/extension/src/openvic-extension/classes/GFXPieChartTexture.cpp index 47e32a2..417566d 100644 --- a/extension/src/openvic-extension/classes/GFXPieChartTexture.cpp +++ b/extension/src/openvic-extension/classes/GFXPieChartTexture.cpp @@ -8,8 +8,6 @@ using namespace godot; using namespace OpenVic; -using OpenVic::Utilities::std_view_to_godot_string; - StringName const& GFXPieChartTexture::_slice_identifier_key() { static const StringName slice_identifier_key = "identifier"; return slice_identifier_key; @@ -109,7 +107,8 @@ Error GFXPieChartTexture::set_slices_array(godot_pie_chart_data_t const& new_sli for (int32_t i = 0; i < new_slices.size(); ++i) { Dictionary const& slice_dict = new_slices[i]; ERR_CONTINUE_MSG( - !slice_dict.has(_slice_colour_key()) || !slice_dict.has(_slice_weight_key()), vformat("Invalid slice keys at index %d", i) + !slice_dict.has(_slice_colour_key()) || !slice_dict.has(_slice_weight_key()), + vformat("Invalid slice keys at index %d", i) ); const slice_t slice = std::make_pair(slice_dict[_slice_colour_key()], slice_dict[_slice_weight_key()]); if (slice.second > 0.0f) { @@ -171,12 +170,13 @@ Error GFXPieChartTexture::set_gfx_pie_chart_name(String const& gfx_pie_chart_nam ERR_FAIL_NULL_V_MSG( new_pie_chart, FAILED, vformat( "Invalid type for GFX sprite %s: %s (expected %s)", gfx_pie_chart_name, - std_view_to_godot_string(sprite->get_type()), std_view_to_godot_string(GFX::PieChart::get_type_static()) + Utilities::std_to_godot_string(sprite->get_type()), + Utilities::std_to_godot_string(GFX::PieChart::get_type_static()) ) ); return set_gfx_pie_chart(new_pie_chart); } String GFXPieChartTexture::get_gfx_pie_chart_name() const { - return gfx_pie_chart != nullptr ? std_view_to_godot_string(gfx_pie_chart->get_name()) : String {}; + return gfx_pie_chart != nullptr ? Utilities::std_to_godot_string(gfx_pie_chart->get_name()) : String {}; } diff --git a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp index 3135050..9642f4e 100644 --- a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp +++ b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp @@ -85,7 +85,7 @@ namespace OpenVic { for (size_t idx = 0; idx < array.size(); ++idx) { auto const& [key, val] = sorted_dist[idx]; Dictionary sub_dict; - sub_dict[_slice_identifier_key()] = Utilities::std_view_to_godot_string(key->get_identifier()); + sub_dict[_slice_identifier_key()] = Utilities::std_to_godot_string(key->get_identifier()); sub_dict[_slice_colour_key()] = Utilities::to_godot_color(key->get_colour()); sub_dict[_slice_weight_key()] = val.to_float(); array[idx] = std::move(sub_dict); diff --git a/extension/src/openvic-extension/classes/GFXSpriteTexture.cpp b/extension/src/openvic-extension/classes/GFXSpriteTexture.cpp index b81f32e..70c9820 100644 --- a/extension/src/openvic-extension/classes/GFXSpriteTexture.cpp +++ b/extension/src/openvic-extension/classes/GFXSpriteTexture.cpp @@ -11,13 +11,12 @@ using namespace godot; using namespace OpenVic; -using OpenVic::Utilities::std_view_to_godot_string; -using OpenVic::Utilities::std_view_to_godot_string_name; - void GFXSpriteTexture::_bind_methods() { OV_BIND_METHOD(GFXSpriteTexture::clear); - OV_BIND_METHOD(GFXSpriteTexture::set_gfx_texture_sprite_name, { "gfx_texture_sprite_name", "icon" }, DEFVAL(GFX::NO_FRAMES)); + OV_BIND_METHOD( + GFXSpriteTexture::set_gfx_texture_sprite_name, { "gfx_texture_sprite_name", "icon" }, DEFVAL(GFX::NO_FRAMES) + ); OV_BIND_METHOD(GFXSpriteTexture::get_gfx_texture_sprite_name); OV_BIND_METHOD(GFXSpriteTexture::set_icon_index, { "new_icon_index" }); @@ -31,7 +30,9 @@ void GFXSpriteTexture::_bind_methods() { GFXSpriteTexture::GFXSpriteTexture() : gfx_texture_sprite { nullptr }, icon_index { GFX::NO_FRAMES }, icon_count { GFX::NO_FRAMES } {} -Ref<GFXSpriteTexture> GFXSpriteTexture::make_gfx_sprite_texture(GFX::TextureSprite const* gfx_texture_sprite, GFX::frame_t icon) { +Ref<GFXSpriteTexture> GFXSpriteTexture::make_gfx_sprite_texture( + GFX::TextureSprite const* gfx_texture_sprite, GFX::frame_t icon +) { Ref<GFXSpriteTexture> texture; texture.instantiate(); ERR_FAIL_NULL_V(texture, nullptr); @@ -56,7 +57,7 @@ Error GFXSpriteTexture::set_gfx_texture_sprite(GFX::TextureSprite const* new_gfx AssetManager* asset_manager = AssetManager::get_singleton(); ERR_FAIL_NULL_V(asset_manager, FAILED); - const StringName texture_file = std_view_to_godot_string_name(new_gfx_texture_sprite->get_texture_file()); + const StringName texture_file = Utilities::std_to_godot_string(new_gfx_texture_sprite->get_texture_file()); /* Needed for GFXButtonStateTexture, AssetManager::get_texture will re-use this image from its internal cache. */ const Ref<Image> image = asset_manager->get_image(texture_file); @@ -98,14 +99,15 @@ Error GFXSpriteTexture::set_gfx_texture_sprite_name(String const& gfx_texture_sp ERR_FAIL_NULL_V_MSG( new_texture_sprite, FAILED, vformat( "Invalid type for GFX sprite %s: %s (expected %s)", gfx_texture_sprite_name, - std_view_to_godot_string(sprite->get_type()), std_view_to_godot_string(GFX::TextureSprite::get_type_static()) + Utilities::std_to_godot_string(sprite->get_type()), + Utilities::std_to_godot_string(GFX::TextureSprite::get_type_static()) ) ); return set_gfx_texture_sprite(new_texture_sprite, icon); } String GFXSpriteTexture::get_gfx_texture_sprite_name() const { - return gfx_texture_sprite != nullptr ? std_view_to_godot_string(gfx_texture_sprite->get_name()) : String {}; + return gfx_texture_sprite != nullptr ? Utilities::std_to_godot_string(gfx_texture_sprite->get_name()) : String {}; } Error GFXSpriteTexture::set_icon_index(int32_t new_icon_index) { diff --git a/extension/src/openvic-extension/classes/GUIListBox.cpp b/extension/src/openvic-extension/classes/GUIListBox.cpp index e3bea86..9165b14 100644 --- a/extension/src/openvic-extension/classes/GUIListBox.cpp +++ b/extension/src/openvic-extension/classes/GUIListBox.cpp @@ -11,8 +11,6 @@ using namespace OpenVic; using namespace godot; using namespace OpenVic::Utilities::literals; -using OpenVic::Utilities::std_view_to_godot_string; - /* StringNames cannot be constructed until Godot has called StringName::setup(), * so we must use wrapper functions to delay their initialisation. */ StringName const& GUIListBox::_signal_scroll_index_changed() { @@ -252,7 +250,7 @@ Error GUIListBox::set_gui_listbox(GUI::ListBox const* new_gui_listbox) { gui_listbox = new_gui_listbox; - const String scrollbar_name = std_view_to_godot_string(gui_listbox->get_scrollbar_name()); + const String scrollbar_name = Utilities::std_to_godot_string(gui_listbox->get_scrollbar_name()); Error err = OK; @@ -300,7 +298,7 @@ Error GUIListBox::set_gui_listbox(GUI::ListBox const* new_gui_listbox) { } String GUIListBox::get_gui_listbox_name() const { - return gui_listbox != nullptr ? std_view_to_godot_string(gui_listbox->get_name()) : String {}; + return gui_listbox != nullptr ? Utilities::std_to_godot_string(gui_listbox->get_name()) : String {}; } GUIScrollbar* GUIListBox::get_scrollbar() const { diff --git a/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp b/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp index fe1f941..ca5e666 100644 --- a/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp +++ b/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp @@ -9,8 +9,6 @@ using namespace OpenVic; using namespace godot; -using OpenVic::Utilities::std_view_to_godot_string; - Error GUIOverlappingElementsBox::_update_child_positions() { ERR_FAIL_NULL_V(gui_overlapping_elements_box, FAILED); const int32_t child_count = get_child_count(); @@ -108,7 +106,7 @@ Error GUIOverlappingElementsBox::set_child_count(int32_t new_count) { ) ); Error err = OK; - const String gui_child_element_name = std_view_to_godot_string(gui_child_element->get_name()) + "_"; + const String gui_child_element_name = Utilities::std_to_godot_string(gui_child_element->get_name()) + "_"; do { Control* child = nullptr; const String name = gui_child_element_name + itos(child_count); @@ -155,7 +153,9 @@ Error GUIOverlappingElementsBox::set_gui_overlapping_elements_box( } String GUIOverlappingElementsBox::get_gui_overlapping_elements_box_name() const { - return gui_overlapping_elements_box != nullptr ? std_view_to_godot_string(gui_overlapping_elements_box->get_name()) : String {}; + return gui_overlapping_elements_box != nullptr + ? Utilities::std_to_godot_string(gui_overlapping_elements_box->get_name()) + : String {}; } Error GUIOverlappingElementsBox::set_gui_child_element(GUI::Element const* new_gui_child_element) { @@ -184,5 +184,5 @@ Error GUIOverlappingElementsBox::set_gui_child_element_name( } String GUIOverlappingElementsBox::get_gui_child_element_name() const { - return gui_child_element != nullptr ? std_view_to_godot_string(gui_child_element->get_name()) : String {}; + return gui_child_element != nullptr ? Utilities::std_to_godot_string(gui_child_element->get_name()) : String {}; } diff --git a/extension/src/openvic-extension/classes/GUIScrollbar.cpp b/extension/src/openvic-extension/classes/GUIScrollbar.cpp index dab74d8..ddcba7c 100644 --- a/extension/src/openvic-extension/classes/GUIScrollbar.cpp +++ b/extension/src/openvic-extension/classes/GUIScrollbar.cpp @@ -11,9 +11,6 @@ using namespace OpenVic; using namespace godot; -using OpenVic::Utilities::std_to_godot_string; -using OpenVic::Utilities::std_view_to_godot_string; - /* StringNames cannot be constructed until Godot has called StringName::setup(), * so we must use wrapper functions to delay their initialisation. */ StringName const& GUIScrollbar::signal_value_changed() { @@ -360,7 +357,7 @@ Error GUIScrollbar::set_gui_scrollbar(GUI::Scrollbar const* new_gui_scrollbar) { gui_scrollbar = new_gui_scrollbar; - const String gui_scrollbar_name = std_view_to_godot_string(gui_scrollbar->get_name()); + const String gui_scrollbar_name = Utilities::std_to_godot_string(gui_scrollbar->get_name()); orientation = gui_scrollbar->is_horizontal() ? HORIZONTAL : VERTICAL; length_override = 0.0f; @@ -374,7 +371,7 @@ Error GUIScrollbar::set_gui_scrollbar(GUI::Scrollbar const* new_gui_scrollbar) { ERR_FAIL_NULL_V_MSG(element, false, vformat( "Invalid %s element for GUIScrollbar %s - null!", target, gui_scrollbar_name )); - const String element_name = std_view_to_godot_string(element->get_name()); + const String element_name = Utilities::std_to_godot_string(element->get_name()); /* Get Sprite, convert to TextureSprite, use to make a GFXSpriteTexture. */ GFX::Sprite const* sprite = element->get_sprite(); @@ -384,8 +381,9 @@ Error GUIScrollbar::set_gui_scrollbar(GUI::Scrollbar const* new_gui_scrollbar) { GFX::TextureSprite const* texture_sprite = sprite->cast_to<GFX::TextureSprite>(); ERR_FAIL_NULL_V_MSG(texture_sprite, false, vformat( "Invalid %s element %s for GUIScrollbar %s - sprite type is %s with base type %s, expected base %s!", target, - element_name, gui_scrollbar_name, std_view_to_godot_string(sprite->get_type()), - std_view_to_godot_string(sprite->get_base_type()), std_view_to_godot_string(GFX::TextureSprite::get_type_static()) + element_name, gui_scrollbar_name, Utilities::std_to_godot_string(sprite->get_type()), + Utilities::std_to_godot_string(sprite->get_base_type()), + Utilities::std_to_godot_string(GFX::TextureSprite::get_type_static()) )); texture = GFXSpriteTexture::make_gfx_sprite_texture(texture_sprite); ERR_FAIL_NULL_V_MSG(texture, false, vformat( @@ -427,8 +425,8 @@ Error GUIScrollbar::set_gui_scrollbar(GUI::Scrollbar const* new_gui_scrollbar) { fixed_point_t step_size = gui_scrollbar->get_step_size(); if (step_size <= 0) { UtilityFunctions::push_error( - "Invalid step size ", std_to_godot_string(step_size.to_string()), " for GUIScrollbar ", gui_scrollbar_name, - " - not positive! Defaulting to 1." + "Invalid step size ", Utilities::std_to_godot_string(step_size.to_string()), " for GUIScrollbar ", + gui_scrollbar_name, " - not positive! Defaulting to 1." ); step_size = 1; ret = false; @@ -446,7 +444,9 @@ Error GUIScrollbar::set_gui_scrollbar_name(String const& gui_scene, String const if (gui_scene.is_empty() && gui_scrollbar_name.is_empty()) { return set_gui_scrollbar(nullptr); } - ERR_FAIL_COND_V_MSG(gui_scene.is_empty() || gui_scrollbar_name.is_empty(), FAILED, "GUI scene or scrollbar name is empty!"); + ERR_FAIL_COND_V_MSG( + gui_scene.is_empty() || gui_scrollbar_name.is_empty(), FAILED, "GUI scene or scrollbar name is empty!" + ); GUI::Element const* gui_element = UITools::get_gui_element(gui_scene, gui_scrollbar_name); ERR_FAIL_NULL_V(gui_element, FAILED); @@ -456,7 +456,7 @@ Error GUIScrollbar::set_gui_scrollbar_name(String const& gui_scene, String const } String GUIScrollbar::get_gui_scrollbar_name() const { - return gui_scrollbar != nullptr ? std_view_to_godot_string(gui_scrollbar->get_name()) : String {}; + return gui_scrollbar != nullptr ? Utilities::std_to_godot_string(gui_scrollbar->get_name()) : String {}; } void GUIScrollbar::set_value(int32_t new_value, bool signal) { |