Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extension/deps/openvic-simulation
19 changes: 8 additions & 11 deletions extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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));

Expand All @@ -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(
Expand Down Expand Up @@ -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);
Expand All @@ -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 {};
}
10 changes: 5 additions & 5 deletions extension/src/openvic-extension/classes/GFXPieChartTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 10 additions & 8 deletions extension/src/openvic-extension/classes/GFXSpriteTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions extension/src/openvic-extension/classes/GUIListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {};
}
22 changes: 11 additions & 11 deletions extension/src/openvic-extension/classes/GUIScrollbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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(
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
13 changes: 6 additions & 7 deletions extension/src/openvic-extension/singletons/AssetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
Loading