aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/utility/Utilities.cpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-12-28 21:19:12 +0100
committer hop311 <hop3114@gmail.com>2023-12-28 21:22:27 +0100
commitd04d0247479b229407048a37cd0ad60933aa3bf1 (patch)
treecb3671592c2d1e7697371510f455de7e99f75a12 /extension/src/openvic-extension/utility/Utilities.cpp
parentc21e9b7a529aebcf0148a6671377c3e8478fafdf (diff)
Use `ERR_FAIL_*` macros where possible
Diffstat (limited to 'extension/src/openvic-extension/utility/Utilities.cpp')
-rw-r--r--extension/src/openvic-extension/utility/Utilities.cpp28
1 files changed, 9 insertions, 19 deletions
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;
}