2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* resource_loader.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:45:00 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "resource_loader.h"
|
|
|
|
#include "globals.h"
|
|
|
|
#include "os/file_access.h"
|
|
|
|
#include "os/os.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "path_remap.h"
|
|
|
|
#include "print_string.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
ResourceFormatLoader *ResourceLoader::loader[MAX_LOADERS];
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int ResourceLoader::loader_count = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Error ResourceInteractiveLoader::wait() {
|
|
|
|
|
|
|
|
Error err = poll();
|
2017-03-18 23:36:26 +00:00
|
|
|
while (err == OK) {
|
|
|
|
err = poll();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool ResourceFormatLoader::recognize(const String &p_extension) const {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
List<String> extensions;
|
|
|
|
get_recognized_extensions(&extensions);
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (E->get().nocasecmp_to(p_extension.extension()) == 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceFormatLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_type == "" || handles_type(p_type))
|
2014-02-10 01:10:30 +00:00
|
|
|
get_recognized_extensions(p_extensions);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < loader_count; i++) {
|
|
|
|
loader[i]->get_recognized_extensions_for_type(p_type, p_extensions);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceInteractiveLoader::_bind_methods() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ObjectTypeDB::bind_method(_MD("get_resource"), &ResourceInteractiveLoader::get_resource);
|
|
|
|
ObjectTypeDB::bind_method(_MD("poll"), &ResourceInteractiveLoader::poll);
|
|
|
|
ObjectTypeDB::bind_method(_MD("wait"), &ResourceInteractiveLoader::wait);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_stage"), &ResourceInteractiveLoader::get_stage);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_stage_count"), &ResourceInteractiveLoader::get_stage_count);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class ResourceInteractiveLoaderDefault : public ResourceInteractiveLoader {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
OBJ_TYPE(ResourceInteractiveLoaderDefault, ResourceInteractiveLoader);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
public:
|
2014-02-10 01:10:30 +00:00
|
|
|
Ref<Resource> resource;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
virtual void set_local_path(const String &p_local_path) { /*scene->set_filename(p_local_path);*/
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
virtual Ref<Resource> get_resource() { return resource; }
|
|
|
|
virtual Error poll() { return ERR_FILE_EOF; }
|
|
|
|
virtual int get_stage() const { return 1; }
|
|
|
|
virtual int get_stage_count() const { return 1; }
|
|
|
|
|
|
|
|
ResourceInteractiveLoaderDefault() {}
|
|
|
|
};
|
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
Ref<ResourceInteractiveLoader> ResourceFormatLoader::load_interactive(const String &p_path, Error *r_error) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//either this
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<Resource> res = load(p_path, p_path, r_error);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (res.is_null())
|
|
|
|
return Ref<ResourceInteractiveLoader>();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<ResourceInteractiveLoaderDefault> ril = Ref<ResourceInteractiveLoaderDefault>(memnew(ResourceInteractiveLoaderDefault));
|
|
|
|
ril->resource = res;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ril;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String path = p_path;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//or this must be implemented
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<ResourceInteractiveLoader> ril = load_interactive(p_path, r_error);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!ril.is_valid())
|
|
|
|
return RES();
|
|
|
|
ril->set_local_path(p_original_path);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (true) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Error err = ril->poll();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (err == ERR_FILE_EOF) {
|
2015-08-23 23:15:56 +00:00
|
|
|
if (r_error)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_error = OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ril->get_resource();
|
|
|
|
}
|
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
if (r_error)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_error = err;
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(err != OK, RES());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return RES();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//do nothing by default
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
if (r_error)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_error = ERR_CANT_OPEN;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-04 13:17:24 +00:00
|
|
|
String local_path;
|
|
|
|
if (p_path.is_rel_path())
|
2017-03-18 23:36:26 +00:00
|
|
|
local_path = "res://" + p_path;
|
2015-05-04 13:17:24 +00:00
|
|
|
else
|
|
|
|
local_path = Globals::get_singleton()->localize_path(p_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
local_path = find_complete_path(local_path, p_type_hint);
|
|
|
|
ERR_FAIL_COND_V(local_path == "", RES());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!p_no_cache && ResourceCache::has(local_path)) {
|
|
|
|
|
|
|
|
if (OS::get_singleton()->is_stdout_verbose())
|
2017-03-18 23:36:26 +00:00
|
|
|
print_line("load resource: " + local_path + " (cached)");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return RES(ResourceCache::get(local_path));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
|
|
|
|
|
|
|
|
if (OS::get_singleton()->is_stdout_verbose())
|
2017-03-18 23:36:26 +00:00
|
|
|
print_line("load resource: " + remapped_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String extension = remapped_path.extension();
|
|
|
|
bool found = false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < loader_count; i++) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!loader[i]->recognize(extension))
|
|
|
|
continue;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_type_hint != "" && !loader[i]->handles_type(p_type_hint))
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2017-03-18 23:36:26 +00:00
|
|
|
found = true;
|
|
|
|
RES res = loader[i]->load(remapped_path, local_path, r_error);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (res.is_null())
|
|
|
|
continue;
|
|
|
|
if (!p_no_cache)
|
|
|
|
res->set_path(local_path);
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
|
|
|
res->set_edited(false);
|
|
|
|
if (timestamp_on_load) {
|
|
|
|
uint64_t mt = FileAccess::get_modified_time(remapped_path);
|
|
|
|
//printf("mt %s: %lli\n",remapped_path.utf8().get_data(),mt);
|
|
|
|
res->set_last_modified_time(mt);
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-26 13:08:17 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN("Failed loading resource: " + p_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN("No loader found for resource: " + p_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
ERR_FAIL_V(RES());
|
|
|
|
return RES();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<ResourceImportMetadata> ResourceLoader::load_import_metadata(const String &p_path) {
|
|
|
|
|
2015-05-04 13:17:24 +00:00
|
|
|
String local_path;
|
|
|
|
if (p_path.is_rel_path())
|
2017-03-18 23:36:26 +00:00
|
|
|
local_path = "res://" + p_path;
|
2015-05-04 13:17:24 +00:00
|
|
|
else
|
|
|
|
local_path = Globals::get_singleton()->localize_path(p_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String extension = p_path.extension();
|
2014-02-10 01:10:30 +00:00
|
|
|
Ref<ResourceImportMetadata> ret;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < loader_count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!loader[i]->recognize(extension))
|
|
|
|
continue;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = loader[i]->load_import_metadata(local_path, ret);
|
|
|
|
if (err == OK)
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String ResourceLoader::find_complete_path(const String &p_path, const String &p_type) {
|
2014-03-14 01:57:24 +00:00
|
|
|
//this is an old vestige when the engine saved files without extension.
|
|
|
|
//remains here for compatibility with old projects and only because it
|
|
|
|
//can be sometimes nice to open files using .* from a script and have it guess
|
|
|
|
//the right extension.
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String local_path = p_path;
|
|
|
|
if (local_path.ends_with("*")) {
|
|
|
|
|
|
|
|
//find the extension for resource that ends with *
|
2017-03-18 23:36:26 +00:00
|
|
|
local_path = local_path.substr(0, local_path.length() - 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
List<String> extensions;
|
2017-03-18 23:36:26 +00:00
|
|
|
get_recognized_extensions_for_type(p_type, &extensions);
|
2014-02-10 01:10:30 +00:00
|
|
|
List<String> candidates;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String path = local_path + E->get();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-02-25 12:31:47 +00:00
|
|
|
if (PathRemap::get_singleton()->has_remap(path) || FileAccess::exists(path)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
candidates.push_back(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (candidates.size() == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return "";
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (candidates.size() == 1 || p_type == "") {
|
2014-02-10 01:10:30 +00:00
|
|
|
return candidates.front()->get();
|
|
|
|
} else {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<String>::Element *E = candidates.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String rt = get_resource_type(E->get());
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ObjectTypeDB::is_type(rt, p_type)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return E->get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return local_path;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
if (r_error)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_error = ERR_CANT_OPEN;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-04 13:17:24 +00:00
|
|
|
String local_path;
|
|
|
|
if (p_path.is_rel_path())
|
2017-03-18 23:36:26 +00:00
|
|
|
local_path = "res://" + p_path;
|
2015-05-04 13:17:24 +00:00
|
|
|
else
|
|
|
|
local_path = Globals::get_singleton()->localize_path(p_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
local_path = find_complete_path(local_path, p_type_hint);
|
|
|
|
ERR_FAIL_COND_V(local_path == "", Ref<ResourceInteractiveLoader>());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!p_no_cache && ResourceCache::has(local_path)) {
|
|
|
|
|
|
|
|
if (OS::get_singleton()->is_stdout_verbose())
|
2017-03-18 23:36:26 +00:00
|
|
|
print_line("load resource: " + local_path + " (cached)");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-29 23:22:00 +00:00
|
|
|
Ref<Resource> res_cached = ResourceCache::get(local_path);
|
|
|
|
Ref<ResourceInteractiveLoaderDefault> ril = Ref<ResourceInteractiveLoaderDefault>(memnew(ResourceInteractiveLoaderDefault));
|
|
|
|
|
|
|
|
ril->resource = res_cached;
|
|
|
|
return ril;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (OS::get_singleton()->is_stdout_verbose())
|
|
|
|
print_line("load resource: ");
|
|
|
|
|
|
|
|
String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String extension = remapped_path.extension();
|
|
|
|
bool found = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < loader_count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!loader[i]->recognize(extension))
|
|
|
|
continue;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_type_hint != "" && !loader[i]->handles_type(p_type_hint))
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2017-03-18 23:36:26 +00:00
|
|
|
found = true;
|
|
|
|
Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(remapped_path, r_error);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (ril.is_null())
|
|
|
|
continue;
|
|
|
|
if (!p_no_cache)
|
|
|
|
ril->set_local_path(local_path);
|
|
|
|
|
|
|
|
return ril;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN("Failed loading resource: " + p_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN("No loader found for resource: " + p_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
ERR_FAIL_V(Ref<ResourceInteractiveLoader>());
|
|
|
|
return Ref<ResourceInteractiveLoader>();
|
|
|
|
}
|
|
|
|
|
2016-07-20 00:40:05 +00:00
|
|
|
void ResourceLoader::add_resource_format_loader(ResourceFormatLoader *p_format_loader, bool p_at_front) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND(loader_count >= MAX_LOADERS);
|
2016-07-20 00:40:05 +00:00
|
|
|
if (p_at_front) {
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = loader_count; i > 0; i--) {
|
|
|
|
loader[i] = loader[i - 1];
|
2016-07-20 00:40:05 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
loader[0] = p_format_loader;
|
2016-07-20 00:40:05 +00:00
|
|
|
loader_count++;
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
loader[loader_count++] = p_format_loader;
|
2016-07-20 00:40:05 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
String local_path;
|
|
|
|
if (p_path.is_rel_path())
|
2017-03-18 23:36:26 +00:00
|
|
|
local_path = "res://" + p_path;
|
2015-08-23 23:15:56 +00:00
|
|
|
else
|
|
|
|
local_path = Globals::get_singleton()->localize_path(p_path);
|
|
|
|
|
|
|
|
String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String extension = remapped_path.extension();
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < loader_count; i++) {
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
if (!loader[i]->recognize(extension))
|
|
|
|
continue;
|
|
|
|
//if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
|
|
|
|
// continue;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
loader[i]->get_dependencies(remapped_path, p_dependencies, p_add_types);
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error ResourceLoader::get_export_data(const String &p_path, ExportData &r_export_data) {
|
2017-02-13 01:52:02 +00:00
|
|
|
|
|
|
|
String local_path;
|
|
|
|
if (p_path.is_rel_path())
|
2017-03-18 23:36:26 +00:00
|
|
|
local_path = "res://" + p_path;
|
2017-02-13 01:52:02 +00:00
|
|
|
else
|
|
|
|
local_path = Globals::get_singleton()->localize_path(p_path);
|
|
|
|
|
|
|
|
String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String extension = remapped_path.extension();
|
2017-02-13 01:52:02 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < loader_count; i++) {
|
2017-02-13 01:52:02 +00:00
|
|
|
|
|
|
|
if (!loader[i]->recognize(extension))
|
|
|
|
continue;
|
|
|
|
//if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
|
|
|
|
// continue;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return loader[i]->get_export_data(p_path, r_export_data);
|
2017-02-13 01:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ERR_UNAVAILABLE;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String, String> &p_map) {
|
2015-05-04 13:17:24 +00:00
|
|
|
|
|
|
|
String local_path;
|
|
|
|
if (p_path.is_rel_path())
|
2017-03-18 23:36:26 +00:00
|
|
|
local_path = "res://" + p_path;
|
2015-05-04 13:17:24 +00:00
|
|
|
else
|
|
|
|
local_path = Globals::get_singleton()->localize_path(p_path);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String extension = remapped_path.extension();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < loader_count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!loader[i]->recognize(extension))
|
|
|
|
continue;
|
|
|
|
//if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
|
|
|
|
// continue;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return loader[i]->rename_dependencies(p_path, p_map);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
return OK; // ??
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String ResourceLoader::guess_full_filename(const String &p_path, const String &p_type) {
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2015-05-04 13:17:24 +00:00
|
|
|
String local_path;
|
|
|
|
if (p_path.is_rel_path())
|
2017-03-18 23:36:26 +00:00
|
|
|
local_path = "res://" + p_path;
|
2015-05-04 13:17:24 +00:00
|
|
|
else
|
|
|
|
local_path = Globals::get_singleton()->localize_path(p_path);
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return find_complete_path(local_path, p_type);
|
2014-03-14 01:57:24 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String ResourceLoader::get_resource_type(const String &p_path) {
|
|
|
|
|
2015-05-04 13:17:24 +00:00
|
|
|
String local_path;
|
|
|
|
if (p_path.is_rel_path())
|
2017-03-18 23:36:26 +00:00
|
|
|
local_path = "res://" + p_path;
|
2015-05-04 13:17:24 +00:00
|
|
|
else
|
|
|
|
local_path = Globals::get_singleton()->localize_path(p_path);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
|
2017-03-18 23:36:26 +00:00
|
|
|
String extension = remapped_path.extension();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < loader_count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String result = loader[i]->get_resource_type(local_path);
|
2017-03-18 23:36:26 +00:00
|
|
|
if (result != "")
|
2014-02-10 01:10:30 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
ResourceLoadErrorNotify ResourceLoader::err_notify = NULL;
|
|
|
|
void *ResourceLoader::err_notify_ud = NULL;
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
DependencyErrorNotify ResourceLoader::dep_err_notify = NULL;
|
|
|
|
void *ResourceLoader::dep_err_notify_ud = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool ResourceLoader::abort_on_missing_resource = true;
|
|
|
|
bool ResourceLoader::timestamp_on_load = false;
|