Universalize UID support in all resource types

Ensures all resource types support UIDs in a project.

This is required to fix:
* Scripts and many other resource types can't be referenced by UID and when refactored the references are lost.
* Path export properties can't use UID for unsupported types.
* Refactoring problems when files are moved outside the editor (this PR effectively fixes it).
* Editor properly refreshing paths if they changed externally while opened (as example, git update).
  This needs to be addressed in a subsequent PR, but this one effectively sets the prerequisites.

Resource types that do not support UID will get a .uid file appended to them (this includes .gd, .gdshader, .gdextension, etc. files).
This commit is contained in:
Juan
2024-09-23 10:42:18 +02:00
committed by Rémi Verschelde
parent 0f5f3bc954
commit d57846087b
11 changed files with 61 additions and 1 deletions

View File

@@ -112,10 +112,21 @@ String ResourceFormatLoader::get_resource_script_class(const String &p_path) con
ResourceUID::ID ResourceFormatLoader::get_resource_uid(const String &p_path) const {
int64_t uid = ResourceUID::INVALID_ID;
GDVIRTUAL_CALL(_get_resource_uid, p_path, uid);
if (has_custom_uid_support()) {
GDVIRTUAL_CALL(_get_resource_uid, p_path, uid);
} else {
Ref<FileAccess> file = FileAccess::open(p_path + ".uid", FileAccess::READ);
if (file.is_valid()) {
uid = ResourceUID::get_singleton()->text_to_id(file->get_line());
}
}
return uid;
}
bool ResourceFormatLoader::has_custom_uid_support() const {
return GDVIRTUAL_IS_OVERRIDDEN(_get_resource_uid);
}
void ResourceFormatLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
if (p_type.is_empty() || handles_type(p_type)) {
get_recognized_extensions(p_extensions);
@@ -1159,6 +1170,21 @@ ResourceUID::ID ResourceLoader::get_resource_uid(const String &p_path) {
return ResourceUID::INVALID_ID;
}
bool ResourceLoader::has_custom_uid_support(const String &p_path) {
String local_path = _validate_local_path(p_path);
for (int i = 0; i < loader_count; i++) {
if (!loader[i]->recognize_path(local_path)) {
continue;
}
if (loader[i]->has_custom_uid_support()) {
return true;
}
}
return false;
}
String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_remapped) {
String new_path = p_path;