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.cpp22
1 files changed, 4 insertions, 18 deletions
diff --git a/scene/main/resource_preloader.cpp b/scene/main/resource_preloader.cpp
index 43a61834eb..cd9560db61 100644
--- a/scene/main/resource_preloader.cpp
+++ b/scene/main/resource_preloader.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,7 +31,6 @@
#include "resource_preloader.h"
void ResourcePreloader::_set_resources(const Array &p_data) {
-
resources.clear();
ERR_FAIL_COND(p_data.size() != 2);
@@ -41,7 +40,6 @@ void ResourcePreloader::_set_resources(const Array &p_data) {
ERR_FAIL_COND(names.size() != resdata.size());
for (int i = 0; i < resdata.size(); i++) {
-
String name = names[i];
RES resource = resdata[i];
ERR_CONTINUE(!resource.is_valid());
@@ -52,7 +50,6 @@ void ResourcePreloader::_set_resources(const Array &p_data) {
}
Array ResourcePreloader::_get_resources() const {
-
Vector<String> names;
Array arr;
arr.resize(resources.size());
@@ -66,7 +63,6 @@ Array ResourcePreloader::_get_resources() const {
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()];
i++;
@@ -79,15 +75,12 @@ Array ResourcePreloader::_get_resources() const {
}
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;
while (true) {
-
new_name = p_name.operator String() + " " + itos(idx);
if (resources.has(new_name)) {
idx++;
@@ -99,18 +92,16 @@ void ResourcePreloader::add_resource(const StringName &p_name, const RES &p_reso
add_resource(new_name, p_resource);
} else {
-
resources[p_name] = p_resource;
}
}
void ResourcePreloader::remove_resource(const StringName &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));
RES res = resources[p_from_name];
@@ -120,17 +111,15 @@ void ResourcePreloader::rename_resource(const StringName &p_from_name, const Str
}
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());
return resources[p_name];
}
Vector<String> ResourcePreloader::_get_resource_list() const {
-
Vector<String> res;
res.resize(resources.size());
int i = 0;
@@ -142,15 +131,12 @@ Vector<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()) {
-
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);