Skip to content

Commit

Permalink
Support uid:// in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Nov 16, 2024
1 parent 5efd124 commit 3b6705a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
6 changes: 6 additions & 0 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ String ProjectSettings::globalize_path(const String &p_path) const {
return p_path.replace("res:/", resource_path);
}
return p_path.replace("res://", "");
} else if (p_path.begins_with("uid://")) {
const String path = ResourceUID::uid_to_path(p_path);
if (!resource_path.is_empty()) {
return path.replace("res:/", resource_path);
}
return path.replace("res://", "");
} else if (p_path.begins_with("user://")) {
String data_dir = OS::get_singleton()->get_user_data_dir();
if (!data_dir.is_empty()) {
Expand Down
8 changes: 6 additions & 2 deletions core/io/file_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void FileAccess::_set_access_type(AccessType p_access) {

Ref<FileAccess> FileAccess::create_for_path(const String &p_path) {
Ref<FileAccess> ret;
if (p_path.begins_with("res://")) {
if (p_path.begins_with("res://") || p_path.begins_with("uid://")) {
ret = create(ACCESS_RESOURCES);
} else if (p_path.begins_with("user://")) {
ret = create(ACCESS_USERDATA);
Expand Down Expand Up @@ -183,13 +183,17 @@ FileAccess::AccessType FileAccess::get_access_type() const {
}

String FileAccess::fix_path(const String &p_path) const {
//helper used by file accesses that use a single filesystem
// Helper used by file accesses that use a single filesystem.

String r_path = p_path.replace("\\", "/");

switch (_access_type) {
case ACCESS_RESOURCES: {
if (ProjectSettings::get_singleton()) {
if (r_path.begins_with("uid://")) {
r_path = ResourceUID::uid_to_path(r_path);
}

if (r_path.begins_with("res://")) {
String resource_path = ProjectSettings::get_singleton()->get_resource_path();
if (!resource_path.is_empty()) {
Expand Down
2 changes: 1 addition & 1 deletion core/io/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2617,7 +2617,7 @@ Error Image::load(const String &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.", path));
}
#endif
return ImageLoader::load_image(ResourceUID::ensure_path(p_path), this);
return ImageLoader::load_image(path, this);
}

Ref<Image> Image::load_from_file(const String &p_path) {
Expand Down
9 changes: 5 additions & 4 deletions core/io/image_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,24 @@ void ImageFormatLoaderExtension::_bind_methods() {

Error ImageLoader::load_image(const String &p_file, Ref<Image> p_image, Ref<FileAccess> p_custom, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale) {
ERR_FAIL_COND_V_MSG(p_image.is_null(), ERR_INVALID_PARAMETER, "Can't load an image: invalid Image object.");
const String file = ResourceUID::ensure_path(p_file);

Ref<FileAccess> f = p_custom;
if (f.is_null()) {
Error err;
f = FileAccess::open(p_file, FileAccess::READ, &err);
ERR_FAIL_COND_V_MSG(f.is_null(), err, vformat("Error opening file '%s'.", p_file));
f = FileAccess::open(file, FileAccess::READ, &err);
ERR_FAIL_COND_V_MSG(f.is_null(), err, vformat("Error opening file '%s'.", file));
}

String extension = p_file.get_extension();
String extension = file.get_extension();

for (int i = 0; i < loader.size(); i++) {
if (!loader[i]->recognize(extension)) {
continue;
}
Error err = loader.write[i]->load_image(p_image, f, p_flags, p_scale);
if (err != OK) {
ERR_PRINT(vformat("Error loading image: '%s'.", p_file));
ERR_PRINT(vformat("Error loading image: '%s'.", file));
}

if (err != ERR_FILE_UNRECOGNIZED) {
Expand Down
2 changes: 1 addition & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3450,7 +3450,7 @@ void Main::setup_boot_logo() {

if (show_logo) { //boot logo!
const bool boot_logo_image = GLOBAL_DEF_BASIC("application/boot_splash/show_image", true);
const String boot_logo_path = String(GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/boot_splash/image", PROPERTY_HINT_FILE, "*.png"), String())).strip_edges();
const String boot_logo_path = ResourceUID::ensure_path(GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/boot_splash/image", PROPERTY_HINT_FILE, "*.png"), String())).strip_edges();
const bool boot_logo_scale = GLOBAL_DEF_BASIC("application/boot_splash/fullsize", true);
const bool boot_logo_filter = GLOBAL_DEF_BASIC("application/boot_splash/use_filter", true);

Expand Down

0 comments on commit 3b6705a

Please sign in to comment.