summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Cranford <chris@hibernate.org>2024-05-28 22:38:09 -0400
committerChris Cranford <chris@hibernate.org>2024-05-29 18:43:56 -0400
commitf76b7ed5fc8e881e419ca297acdad69684659ca2 (patch)
tree9243932dd0035259fbe0172f4efc07664ecb6def
parentbe56cab58c056c074d1e02cd0b38641204e39f41 (diff)
downloadredot-engine-f76b7ed5fc8e881e419ca297acdad69684659ca2.tar.gz
Expose `get_cached_ref` from `ResourceCache`
-rw-r--r--core/core_bind.cpp6
-rw-r--r--core/core_bind.h1
-rw-r--r--doc/classes/ResourceLoader.xml8
3 files changed, 15 insertions, 0 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index 0996db9d89..8c0f8ffdb1 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -114,6 +114,11 @@ bool ResourceLoader::has_cached(const String &p_path) {
return ResourceCache::has(local_path);
}
+Ref<Resource> ResourceLoader::get_cached_ref(const String &p_path) {
+ String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ return ResourceCache::get_ref(local_path);
+}
+
bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
return ::ResourceLoader::exists(p_path, p_type_hint);
}
@@ -134,6 +139,7 @@ void ResourceLoader::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_abort_on_missing_resources", "abort"), &ResourceLoader::set_abort_on_missing_resources);
ClassDB::bind_method(D_METHOD("get_dependencies", "path"), &ResourceLoader::get_dependencies);
ClassDB::bind_method(D_METHOD("has_cached", "path"), &ResourceLoader::has_cached);
+ ClassDB::bind_method(D_METHOD("get_cached_ref", "path"), &ResourceLoader::get_cached_ref);
ClassDB::bind_method(D_METHOD("exists", "path", "type_hint"), &ResourceLoader::exists, DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_resource_uid", "path"), &ResourceLoader::get_resource_uid);
diff --git a/core/core_bind.h b/core/core_bind.h
index 148e0ad83e..61d68a3548 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -83,6 +83,7 @@ public:
void set_abort_on_missing_resources(bool p_abort);
PackedStringArray get_dependencies(const String &p_path);
bool has_cached(const String &p_path);
+ Ref<Resource> get_cached_ref(const String &p_path);
bool exists(const String &p_path, const String &p_type_hint = "");
ResourceUID::ID get_resource_uid(const String &p_path);
diff --git a/doc/classes/ResourceLoader.xml b/doc/classes/ResourceLoader.xml
index 1961ca2b0e..ce41c4fd4c 100644
--- a/doc/classes/ResourceLoader.xml
+++ b/doc/classes/ResourceLoader.xml
@@ -31,6 +31,14 @@
[b]Note:[/b] If you use [method Resource.take_over_path], this method will return [code]true[/code] for the taken path even if the resource wasn't saved (i.e. exists only in resource cache).
</description>
</method>
+ <method name="get_cached_ref">
+ <return type="Resource" />
+ <param index="0" name="path" type="String" />
+ <description>
+ Returns the cached resource reference for the given [param path].
+ [b]Note:[/b] If the resource is not cached, the returned [Resource] will be invalid.
+ </description>
+ </method>
<method name="get_dependencies">
<return type="PackedStringArray" />
<param index="0" name="path" type="String" />