diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/io/resource_format_binary.cpp | 5 | ||||
-rw-r--r-- | core/io/resource_format_binary.h | 2 | ||||
-rw-r--r-- | core/io/resource_import.cpp | 2 | ||||
-rw-r--r-- | core/io/resource_loader.cpp | 82 | ||||
-rw-r--r-- | core/io/resource_loader.h | 6 | ||||
-rw-r--r-- | core/script_language.cpp | 1 |
6 files changed, 57 insertions, 41 deletions
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 965d11e414..f44492248e 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1005,7 +1005,7 @@ ResourceInteractiveLoaderBinary::~ResourceInteractiveLoaderBinary() { memdelete(f); } -Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(const String &p_path, Error *r_error) { +Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(const String &p_path, const String &p_original_path, Error *r_error) { if (r_error) *r_error = ERR_FILE_CANT_OPEN; @@ -1019,7 +1019,8 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(cons } Ref<ResourceInteractiveLoaderBinary> ria = memnew(ResourceInteractiveLoaderBinary); - ria->local_path = ProjectSettings::get_singleton()->localize_path(p_path); + String path = p_original_path != "" ? p_original_path : p_path; + ria->local_path = ProjectSettings::get_singleton()->localize_path(path); ria->res_path = ria->local_path; //ria->set_local_path( Globals::get_singleton()->localize_path(p_path) ); ria->open(f); diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index 1bd0d333c6..ab77c2c9d3 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -101,7 +101,7 @@ public: class ResourceFormatLoaderBinary : public ResourceFormatLoader { public: - virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, Error *r_error = NULL); + virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp index 69ff791a3a..be486a86a3 100644 --- a/core/io/resource_import.cpp +++ b/core/io/resource_import.cpp @@ -119,7 +119,7 @@ RES ResourceFormatImporter::load(const String &p_path, const String &p_original_ return RES(); } - RES res = ResourceLoader::load(pat.path, pat.type, false, r_error); + RES res = ResourceLoader::_load(pat.path, p_path, pat.type, false, r_error); #ifdef TOOLS_ENABLED if (res.is_valid()) { diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 30ae9f5681..4f266df43e 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -109,10 +109,10 @@ public: ResourceInteractiveLoaderDefault() {} }; -Ref<ResourceInteractiveLoader> ResourceFormatLoader::load_interactive(const String &p_path, Error *r_error) { +Ref<ResourceInteractiveLoader> ResourceFormatLoader::load_interactive(const String &p_path, const String &p_original_path, Error *r_error) { //either this - Ref<Resource> res = load(p_path, p_path, r_error); + Ref<Resource> res = load(p_path, p_original_path, r_error); if (res.is_null()) return Ref<ResourceInteractiveLoader>(); @@ -126,7 +126,7 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa String path = p_path; //or this must be implemented - Ref<ResourceInteractiveLoader> ril = load_interactive(p_path, r_error); + Ref<ResourceInteractiveLoader> ril = load_interactive(p_path, p_original_path, r_error); if (!ril.is_valid()) return RES(); ril->set_local_path(p_original_path); @@ -157,6 +157,34 @@ void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> * /////////////////////////////////// +RES ResourceLoader::_load(const String &p_path, const String &p_original_path, const String &p_type_hint, bool p_no_cache, Error *r_error) { + + bool found = false; + + // Try all loaders and pick the first match for the type hint + for (int i = 0; i < loader_count; i++) { + + if (!loader[i]->recognize_path(p_path, p_type_hint)) { + continue; + } + found = true; + RES res = loader[i]->load(p_path, p_original_path != String() ? p_original_path : p_path, r_error); + if (res.is_null()) { + continue; + } + + return res; + } + + if (found) { + ERR_EXPLAIN("Failed loading resource: " + p_path); + } else { + ERR_EXPLAIN("No loader found for resource: " + p_path); + } + ERR_FAIL_V(RES()); + return RES(); +} + RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) { if (r_error) @@ -183,45 +211,29 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p if (OS::get_singleton()->is_stdout_verbose()) print_line("load resource: " + path); - bool found = false; - // Try all loaders and pick the first match for the type hint - for (int i = 0; i < loader_count; i++) { + RES res = _load(path, local_path, p_type_hint, p_no_cache, r_error); - if (!loader[i]->recognize_path(path, p_type_hint)) { - continue; - } - found = true; - RES res = loader[i]->load(path, path, r_error); - if (res.is_null()) { - continue; - } - if (!p_no_cache) - res->set_path(local_path); + if (res.is_null()) { + return RES(); + } + if (!p_no_cache) + res->set_path(local_path); - if (xl_remapped) - res->set_as_translation_remapped(true); + if (xl_remapped) + res->set_as_translation_remapped(true); #ifdef TOOLS_ENABLED - res->set_edited(false); - if (timestamp_on_load) { - uint64_t mt = FileAccess::get_modified_time(path); - //printf("mt %s: %lli\n",remapped_path.utf8().get_data(),mt); - res->set_last_modified_time(mt); - } -#endif - - return res; + res->set_edited(false); + if (timestamp_on_load) { + uint64_t mt = FileAccess::get_modified_time(path); + //printf("mt %s: %lli\n",remapped_path.utf8().get_data(),mt); + res->set_last_modified_time(mt); } +#endif - if (found) { - ERR_EXPLAIN("Failed loading resource: " + path); - } else { - ERR_EXPLAIN("No loader found for resource: " + path); - } - ERR_FAIL_V(RES()); - return RES(); + return res; } Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) { @@ -262,7 +274,7 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_ if (!loader[i]->recognize_path(path, p_type_hint)) continue; found = true; - Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(path, r_error); + Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(path, local_path, r_error); if (ril.is_null()) continue; if (!p_no_cache) diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 91f0c939bf..a71a568569 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -57,7 +57,7 @@ public: class ResourceFormatLoader { public: - virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, Error *r_error = NULL); + virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); virtual void get_recognized_extensions(List<String> *p_extensions) const = 0; virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; @@ -96,6 +96,10 @@ class ResourceLoader { static SelfList<Resource>::List remapped_list; + friend class ResourceFormatImporter; + //internal load function + static RES _load(const String &p_path, const String &p_original_path, const String &p_type_hint, bool p_no_cache, Error *r_error); + public: static Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, Error *r_error = NULL); static RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, Error *r_error = NULL); diff --git a/core/script_language.cpp b/core/script_language.cpp index f2be15897e..bde80a30bc 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -55,7 +55,6 @@ void Script::_bind_methods() { ClassDB::bind_method(D_METHOD("set_source_code", "source"), &Script::set_source_code); ClassDB::bind_method(D_METHOD("reload", "keep_state"), &Script::reload, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("has_method", "method_name"), &Script::has_method); ClassDB::bind_method(D_METHOD("has_script_signal", "signal_name"), &Script::has_script_signal); ClassDB::bind_method(D_METHOD("is_tool"), &Script::is_tool); |