diff options
Diffstat (limited to 'extension/src/openvic-extension/utility')
-rw-r--r-- | extension/src/openvic-extension/utility/UITools.cpp | 13 | ||||
-rw-r--r-- | extension/src/openvic-extension/utility/Utilities.cpp | 28 |
2 files changed, 14 insertions, 27 deletions
diff --git a/extension/src/openvic-extension/utility/UITools.cpp b/extension/src/openvic-extension/utility/UITools.cpp index cba65a4..67ea8f5 100644 --- a/extension/src/openvic-extension/utility/UITools.cpp +++ b/extension/src/openvic-extension/utility/UITools.cpp @@ -86,8 +86,7 @@ static T* new_control(GUI::Element const& element, String const& name) { if (it != orientation_map.end()) { node->set_anchors_and_offsets_preset(it->second); } else { - UtilityFunctions::push_error("Invalid orientation for GUI element ", - std_view_to_godot_string(element.get_name())); + UtilityFunctions::push_error("Invalid orientation for GUI element ", std_view_to_godot_string(element.get_name())); } node->set_position(Utilities::to_godot_fvec2(element.get_position())); node->set_h_size_flags(Control::SizeFlags::SIZE_SHRINK_BEGIN); @@ -426,12 +425,10 @@ static bool generate_element(GUI::Element const* element, String const& name, As { GUI::Window::get_type_static(), &generate_window } }; const decltype(type_map)::const_iterator it = type_map.find(element->get_type()); - if (it != type_map.end()) { - return it->second({ *element, name, asset_manager, result }); - } else { - UtilityFunctions::push_error("Invalid GUI element type: ", std_view_to_godot_string(element->get_type())); - return false; - } + ERR_FAIL_COND_V_MSG( + it == type_map.end(), false, vformat("Invalid GUI element type: %s", std_view_to_godot_string(element->get_type())) + ); + return it->second({ *element, name, asset_manager, result }); } bool UITools::generate_gui_element( diff --git a/extension/src/openvic-extension/utility/Utilities.cpp b/extension/src/openvic-extension/utility/Utilities.cpp index 8293e70..4cf515f 100644 --- a/extension/src/openvic-extension/utility/Utilities.cpp +++ b/extension/src/openvic-extension/utility/Utilities.cpp @@ -64,31 +64,23 @@ Ref<Resource> Utilities::load_resource(String const& path, String const& type_hi static Ref<Image> load_dds_image(String const& path) { gli::texture2d texture { gli::load_dds(Utilities::godot_to_std_string(path)) }; - if (texture.empty()) { - UtilityFunctions::push_error("Failed to load DDS file: ", path); - return nullptr; - } + ERR_FAIL_COND_V_MSG(texture.empty(), nullptr, vformat("Failed to load DDS file: %s", path)); static constexpr gli::format expected_format = gli::FORMAT_BGRA8_UNORM_PACK8; const bool needs_bgr_to_rgb = texture.format() == expected_format; if (!needs_bgr_to_rgb) { texture = gli::convert(texture, expected_format); - if (texture.empty()) { - UtilityFunctions::push_error("Failed to convert DDS file: ", path); - return nullptr; - } + ERR_FAIL_COND_V_MSG(texture.empty(), nullptr, vformat("Failed to convert DDS file: %s", path)); } const gli::texture2d::extent_type extent { texture.extent() }; - const int width = extent.x, height = extent.y, size = width * height * 4; + const int32_t width = extent.x, height = extent.y, size = width * height * 4; /* Only fail if there aren't enough bytes, everything seems to work fine if there are extra bytes and we ignore them */ - if (size > texture.size()) { - UtilityFunctions::push_error( - "Texture size ", static_cast<int64_t>(texture.size()), " mismatched with dims-based size ", size, " for ", path - ); - return nullptr; - } + ERR_FAIL_COND_V_MSG( + size > texture.size(), nullptr, + vformat("Texture size %d mismatched with dims-based size %d for %s", static_cast<int64_t>(texture.size()), size, path) + ); PackedByteArray pixels; pixels.resize(size); @@ -113,13 +105,11 @@ Ref<Image> Utilities::load_godot_image(String const& path) { } Ref<FontFile> Utilities::load_godot_font(String const& fnt_path, Ref<Image> const& image) { + ERR_FAIL_NULL_V(image, nullptr); Ref<FontFile> font; font.instantiate(); - const Error err = font->load_bitmap_font(fnt_path); + ERR_FAIL_COND_V_MSG(font->load_bitmap_font(fnt_path) != OK, nullptr, vformat("Failed to load font: %s", fnt_path)); font->set_texture_image(0, { font->get_fixed_size(), 0 }, 0, image); - if (err != OK) { - UtilityFunctions::push_error("Failed to load font (error ", err, "): ", fnt_path); - } return font; } |