Exposes ResourceFormatLoader.recognize_path to scripting

This commit is contained in:
Gilles Roudière 2022-10-11 11:40:04 +02:00
parent 104af08e9d
commit 8aa904f56c
3 changed files with 16 additions and 0 deletions

View file

@ -49,6 +49,11 @@ Ref<ResourceFormatLoader> ResourceLoader::loader[ResourceLoader::MAX_LOADERS];
int ResourceLoader::loader_count = 0;
bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_for_type) const {
bool ret = false;
if (GDVIRTUAL_CALL(_recognize_path, p_path, p_for_type, ret)) {
return ret;
}
String extension = p_path.get_extension();
List<String> extensions;
@ -189,6 +194,7 @@ void ResourceFormatLoader::_bind_methods() {
BIND_ENUM_CONSTANT(CACHE_MODE_REPLACE);
GDVIRTUAL_BIND(_get_recognized_extensions);
GDVIRTUAL_BIND(_recognize_path, "path", "type");
GDVIRTUAL_BIND(_handles_type, "type");
GDVIRTUAL_BIND(_get_resource_type, "path");
GDVIRTUAL_BIND(_get_resource_uid, "path");

View file

@ -51,6 +51,7 @@ protected:
static void _bind_methods();
GDVIRTUAL0RC(Vector<String>, _get_recognized_extensions)
GDVIRTUAL2RC(bool, _recognize_path, String, StringName)
GDVIRTUAL1RC(bool, _handles_type, StringName)
GDVIRTUAL1RC(String, _get_resource_type, String)
GDVIRTUAL1RC(ResourceUID::ID, _get_resource_uid, String)

View file

@ -71,6 +71,15 @@
The [param cache_mode] property defines whether and how the cache should be used or updated when loading the resource. See [enum CacheMode] for details.
</description>
</method>
<method name="_recognize_path" qualifiers="virtual const">
<return type="bool" />
<param index="0" name="path" type="String" />
<param index="1" name="type" type="StringName" />
<description>
Tells whether or not this loader should load a resource from its resource path for a given type.
If it is not implemented, the default behavior returns whether the path's extension is within the ones provided by [method _get_recognized_extensions], and if the type is within the ones provided by [method _get_resource_type].
</description>
</method>
<method name="_rename_dependencies" qualifiers="virtual const">
<return type="int" />
<param index="0" name="path" type="String" />