Resource UID fixes and improvements

This commit is contained in:
kobewi
2024-11-14 16:37:54 +01:00
parent 76fa7b2914
commit 0dabcd9941
3 changed files with 28 additions and 6 deletions

View File

@@ -2611,23 +2611,25 @@ Image::AlphaMode Image::detect_alpha() const {
}
Error Image::load(const String &p_path) {
String path = ResourceUID::ensure_path(p_path);
#ifdef DEBUG_ENABLED
if (p_path.begins_with("res://") && ResourceLoader::exists(p_path)) {
WARN_PRINT(vformat("Loaded resource as image file, this will not work on export: '%s'. Instead, import the image file as an Image resource and load it normally as a resource.", p_path));
if (path.begins_with("res://") && ResourceLoader::exists(path)) {
WARN_PRINT(vformat("Loaded resource as image file, this will not work on export: '%s'. Instead, import the image file as an Image resource and load it normally as a resource.", path));
}
#endif
return ImageLoader::load_image(p_path, this);
return ImageLoader::load_image(ResourceUID::ensure_path(p_path), this);
}
Ref<Image> Image::load_from_file(const String &p_path) {
String path = ResourceUID::ensure_path(p_path);
#ifdef DEBUG_ENABLED
if (p_path.begins_with("res://") && ResourceLoader::exists(p_path)) {
WARN_PRINT(vformat("Loaded resource as image file, this will not work on export: '%s'. Instead, import the image file as an Image resource and load it normally as a resource.", p_path));
if (path.begins_with("res://") && ResourceLoader::exists(path)) {
WARN_PRINT(vformat("Loaded resource as image file, this will not work on export: '%s'. Instead, import the image file as an Image resource and load it normally as a resource.", path));
}
#endif
Ref<Image> image;
image.instantiate();
Error err = ImageLoader::load_image(p_path, image);
Error err = ImageLoader::load_image(path, image);
if (err != OK) {
ERR_FAIL_V_MSG(Ref<Image>(), vformat("Failed to load image. Error %d", err));
}