summaryrefslogtreecommitdiff
path: root/scene/main/resource_preloader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main/resource_preloader.cpp')
-rw-r--r--scene/main/resource_preloader.cpp101
1 files changed, 42 insertions, 59 deletions
diff --git a/scene/main/resource_preloader.cpp b/scene/main/resource_preloader.cpp
index 29333ff4bc..c08a6bcd5b 100644
--- a/scene/main/resource_preloader.cpp
+++ b/scene/main/resource_preloader.cpp
@@ -28,26 +28,25 @@
/*************************************************************************/
#include "resource_preloader.h"
-void ResourcePreloader::_set_resources(const Array& p_data) {
+void ResourcePreloader::_set_resources(const Array &p_data) {
resources.clear();
- ERR_FAIL_COND(p_data.size()!=2);
- PoolVector<String> names=p_data[0];
- Array resdata=p_data[1];
+ ERR_FAIL_COND(p_data.size() != 2);
+ PoolVector<String> names = p_data[0];
+ Array resdata = p_data[1];
- ERR_FAIL_COND(names.size()!=resdata.size());
+ ERR_FAIL_COND(names.size() != resdata.size());
- for(int i=0;i<resdata.size();i++) {
+ for (int i = 0; i < resdata.size(); i++) {
- String name=names[i];
+ String name = names[i];
RES resource = resdata[i];
- ERR_CONTINUE( !resource.is_valid() );
- resources[name]=resource;
+ ERR_CONTINUE(!resource.is_valid());
+ resources[name] = resource;
//add_resource(name,resource);
}
-
}
Array ResourcePreloader::_get_resources() const {
@@ -59,15 +58,15 @@ Array ResourcePreloader::_get_resources() const {
Set<String> sorted_names;
- for(Map<StringName,RES >::Element *E=resources.front();E;E=E->next()) {
+ for (Map<StringName, RES>::Element *E = resources.front(); E; E = E->next()) {
sorted_names.insert(E->key());
}
- int i=0;
- for(Set<String>::Element *E=sorted_names.front();E;E=E->next()) {
+ int i = 0;
+ for (Set<String>::Element *E = sorted_names.front(); E; E = E->next()) {
- names.set(i,E->get());
- arr[i]=resources[E->get()];
+ names.set(i, E->get());
+ arr[i] = resources[E->get()];
i++;
}
@@ -77,65 +76,54 @@ Array ResourcePreloader::_get_resources() const {
return res;
}
-
-void ResourcePreloader::add_resource(const StringName& p_name,const RES& p_resource) {
-
+void ResourcePreloader::add_resource(const StringName &p_name, const RES &p_resource) {
ERR_FAIL_COND(p_resource.is_null());
if (resources.has(p_name)) {
-
StringName new_name;
- int idx=2;
+ int idx = 2;
- while(true) {
+ while (true) {
- new_name=p_name.operator String()+" "+itos(idx);
+ new_name = p_name.operator String() + " " + itos(idx);
if (resources.has(new_name)) {
idx++;
continue;
}
break;
-
}
- add_resource(new_name,p_resource);
+ add_resource(new_name, p_resource);
} else {
- resources[p_name]=p_resource;
+ resources[p_name] = p_resource;
}
-
-
-
}
-void ResourcePreloader::remove_resource(const StringName& p_name) {
+void ResourcePreloader::remove_resource(const StringName &p_name) {
- ERR_FAIL_COND( !resources.has(p_name) );
+ ERR_FAIL_COND(!resources.has(p_name));
resources.erase(p_name);
-
}
-void ResourcePreloader::rename_resource(const StringName& p_from_name,const StringName& p_to_name) {
+void ResourcePreloader::rename_resource(const StringName &p_from_name, const StringName &p_to_name) {
- ERR_FAIL_COND( !resources.has(p_from_name) );
+ ERR_FAIL_COND(!resources.has(p_from_name));
RES res = resources[p_from_name];
resources.erase(p_from_name);
- add_resource(p_to_name,res);
-
-
-
+ add_resource(p_to_name, res);
}
-bool ResourcePreloader::has_resource(const StringName& p_name) const {
+bool ResourcePreloader::has_resource(const StringName &p_name) const {
return resources.has(p_name);
}
-RES ResourcePreloader::get_resource(const StringName& p_name) const {
+RES ResourcePreloader::get_resource(const StringName &p_name) const {
- ERR_FAIL_COND_V(!resources.has(p_name),RES());
+ ERR_FAIL_COND_V(!resources.has(p_name), RES());
return resources[p_name];
}
@@ -143,9 +131,9 @@ PoolVector<String> ResourcePreloader::_get_resource_list() const {
PoolVector<String> res;
res.resize(resources.size());
- int i=0;
- for(Map<StringName,RES >::Element *E=resources.front();E;E=E->next(),i++) {
- res.set(i,E->key());
+ int i = 0;
+ for (Map<StringName, RES>::Element *E = resources.front(); E; E = E->next(), i++) {
+ res.set(i, E->key());
}
return res;
@@ -153,31 +141,26 @@ PoolVector<String> ResourcePreloader::_get_resource_list() const {
void ResourcePreloader::get_resource_list(List<StringName> *p_list) {
- for(Map<StringName,RES >::Element *E=resources.front();E;E=E->next()) {
+ for (Map<StringName, RES>::Element *E = resources.front(); E; E = E->next()) {
p_list->push_back(E->key());
}
-
}
-
void ResourcePreloader::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_set_resources"),&ResourcePreloader::_set_resources);
- ClassDB::bind_method(D_METHOD("_get_resources"),&ResourcePreloader::_get_resources);
-
- ClassDB::bind_method(D_METHOD("add_resource","name","resource"),&ResourcePreloader::add_resource);
- ClassDB::bind_method(D_METHOD("remove_resource","name"),&ResourcePreloader::remove_resource);
- ClassDB::bind_method(D_METHOD("rename_resource","name","newname"),&ResourcePreloader::rename_resource);
- ClassDB::bind_method(D_METHOD("has_resource","name"),&ResourcePreloader::has_resource);
- ClassDB::bind_method(D_METHOD("get_resource","name"),&ResourcePreloader::get_resource);
- ClassDB::bind_method(D_METHOD("get_resource_list"),&ResourcePreloader::_get_resource_list);
-
+ ClassDB::bind_method(D_METHOD("_set_resources"), &ResourcePreloader::_set_resources);
+ ClassDB::bind_method(D_METHOD("_get_resources"), &ResourcePreloader::_get_resources);
- ADD_PROPERTY( PropertyInfo(Variant::ARRAY,"resources",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), "_set_resources", "_get_resources");
+ ClassDB::bind_method(D_METHOD("add_resource", "name", "resource"), &ResourcePreloader::add_resource);
+ ClassDB::bind_method(D_METHOD("remove_resource", "name"), &ResourcePreloader::remove_resource);
+ ClassDB::bind_method(D_METHOD("rename_resource", "name", "newname"), &ResourcePreloader::rename_resource);
+ ClassDB::bind_method(D_METHOD("has_resource", "name"), &ResourcePreloader::has_resource);
+ ClassDB::bind_method(D_METHOD("get_resource", "name"), &ResourcePreloader::get_resource);
+ ClassDB::bind_method(D_METHOD("get_resource_list"), &ResourcePreloader::_get_resource_list);
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "resources", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_resources", "_get_resources");
}
-ResourcePreloader::ResourcePreloader()
-{
+ResourcePreloader::ResourcePreloader() {
}