Merge pull request #61096 from leogeier/expose-adding-resource-loaders-savers

This commit is contained in:
Rémi Verschelde 2022-06-30 15:02:05 +02:00 committed by GitHub
commit c5ad34d6cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 0 deletions

View file

@ -83,6 +83,14 @@ Vector<String> ResourceLoader::get_recognized_extensions_for_type(const String &
return ret; return ret;
} }
void ResourceLoader::add_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader, bool p_at_front) {
::ResourceLoader::add_resource_format_loader(p_format_loader, p_at_front);
}
void ResourceLoader::remove_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader) {
::ResourceLoader::remove_resource_format_loader(p_format_loader);
}
void ResourceLoader::set_abort_on_missing_resources(bool p_abort) { void ResourceLoader::set_abort_on_missing_resources(bool p_abort) {
::ResourceLoader::set_abort_on_missing_resources(p_abort); ::ResourceLoader::set_abort_on_missing_resources(p_abort);
} }
@ -119,6 +127,8 @@ void ResourceLoader::_bind_methods() {
ClassDB::bind_method(D_METHOD("load", "path", "type_hint", "cache_mode"), &ResourceLoader::load, DEFVAL(""), DEFVAL(CACHE_MODE_REUSE)); ClassDB::bind_method(D_METHOD("load", "path", "type_hint", "cache_mode"), &ResourceLoader::load, DEFVAL(""), DEFVAL(CACHE_MODE_REUSE));
ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type", "type"), &ResourceLoader::get_recognized_extensions_for_type); ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type", "type"), &ResourceLoader::get_recognized_extensions_for_type);
ClassDB::bind_method(D_METHOD("add_resource_format_loader", "format_loader", "at_front"), &ResourceLoader::add_resource_format_loader, DEFVAL(false));
ClassDB::bind_method(D_METHOD("remove_resource_format_loader", "format_loader"), &ResourceLoader::remove_resource_format_loader);
ClassDB::bind_method(D_METHOD("set_abort_on_missing_resources", "abort"), &ResourceLoader::set_abort_on_missing_resources); 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("get_dependencies", "path"), &ResourceLoader::get_dependencies);
ClassDB::bind_method(D_METHOD("has_cached", "path"), &ResourceLoader::has_cached); ClassDB::bind_method(D_METHOD("has_cached", "path"), &ResourceLoader::has_cached);
@ -153,11 +163,21 @@ Vector<String> ResourceSaver::get_recognized_extensions(const Ref<Resource> &p_r
return ret; return ret;
} }
void ResourceSaver::add_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver, bool p_at_front) {
::ResourceSaver::add_resource_format_saver(p_format_saver, p_at_front);
}
void ResourceSaver::remove_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver) {
::ResourceSaver::remove_resource_format_saver(p_format_saver);
}
ResourceSaver *ResourceSaver::singleton = nullptr; ResourceSaver *ResourceSaver::singleton = nullptr;
void ResourceSaver::_bind_methods() { void ResourceSaver::_bind_methods() {
ClassDB::bind_method(D_METHOD("save", "path", "resource", "flags"), &ResourceSaver::save, DEFVAL((uint32_t)FLAG_NONE)); ClassDB::bind_method(D_METHOD("save", "path", "resource", "flags"), &ResourceSaver::save, DEFVAL((uint32_t)FLAG_NONE));
ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &ResourceSaver::get_recognized_extensions); ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &ResourceSaver::get_recognized_extensions);
ClassDB::bind_method(D_METHOD("add_resource_format_saver", "format_saver", "at_front"), &ResourceSaver::add_resource_format_saver, DEFVAL(false));
ClassDB::bind_method(D_METHOD("remove_resource_format_saver", "format_saver"), &ResourceSaver::remove_resource_format_saver);
BIND_ENUM_CONSTANT(FLAG_NONE); BIND_ENUM_CONSTANT(FLAG_NONE);
BIND_ENUM_CONSTANT(FLAG_RELATIVE_PATHS); BIND_ENUM_CONSTANT(FLAG_RELATIVE_PATHS);

View file

@ -77,6 +77,8 @@ public:
Ref<Resource> load(const String &p_path, const String &p_type_hint = "", CacheMode p_cache_mode = CACHE_MODE_REUSE); Ref<Resource> load(const String &p_path, const String &p_type_hint = "", CacheMode p_cache_mode = CACHE_MODE_REUSE);
Vector<String> get_recognized_extensions_for_type(const String &p_type); Vector<String> get_recognized_extensions_for_type(const String &p_type);
void add_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader, bool p_at_front);
void remove_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader);
void set_abort_on_missing_resources(bool p_abort); void set_abort_on_missing_resources(bool p_abort);
PackedStringArray get_dependencies(const String &p_path); PackedStringArray get_dependencies(const String &p_path);
bool has_cached(const String &p_path); bool has_cached(const String &p_path);
@ -109,6 +111,8 @@ public:
Error save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags); Error save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags);
Vector<String> get_recognized_extensions(const Ref<Resource> &p_resource); Vector<String> get_recognized_extensions(const Ref<Resource> &p_resource);
void add_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver, bool p_at_front);
void remove_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver);
ResourceSaver() { singleton = this; } ResourceSaver() { singleton = this; }
}; };

View file

@ -11,6 +11,15 @@
<link title="OS Test Demo">https://godotengine.org/asset-library/asset/677</link> <link title="OS Test Demo">https://godotengine.org/asset-library/asset/677</link>
</tutorials> </tutorials>
<methods> <methods>
<method name="add_resource_format_loader">
<return type="void" />
<argument index="0" name="format_loader" type="ResourceFormatLoader" />
<argument index="1" name="at_front" type="bool" default="false" />
<description>
Registers a new [ResourceFormatLoader]. The ResourceLoader will use the ResourceFormatLoader as described in [method load].
This method is performed implictly for ResourceFormatLoaders written in GDScript (see [ResourceFormatLoader] for more information).
</description>
</method>
<method name="exists"> <method name="exists">
<return type="bool" /> <return type="bool" />
<argument index="0" name="path" type="String" /> <argument index="0" name="path" type="String" />
@ -89,6 +98,13 @@
Loads the resource using threads. If [code]use_sub_threads[/code] is [code]true[/code], multiple threads will be used to load the resource, which makes loading faster, but may affect the main thread (and thus cause game slowdowns). Loads the resource using threads. If [code]use_sub_threads[/code] is [code]true[/code], multiple threads will be used to load the resource, which makes loading faster, but may affect the main thread (and thus cause game slowdowns).
</description> </description>
</method> </method>
<method name="remove_resource_format_loader">
<return type="void" />
<argument index="0" name="format_loader" type="ResourceFormatLoader" />
<description>
Unregisters the given [ResourceFormatLoader].
</description>
</method>
<method name="set_abort_on_missing_resources"> <method name="set_abort_on_missing_resources">
<return type="void" /> <return type="void" />
<argument index="0" name="abort" type="bool" /> <argument index="0" name="abort" type="bool" />

View file

@ -10,6 +10,15 @@
<tutorials> <tutorials>
</tutorials> </tutorials>
<methods> <methods>
<method name="add_resource_format_saver">
<return type="void" />
<argument index="0" name="format_saver" type="ResourceFormatSaver" />
<argument index="1" name="at_front" type="bool" default="false" />
<description>
Registers a new [ResourceFormatSaver]. The ResourceSaver will use the ResourceFormatSaver as described in [method save].
This method is performed implictly for ResourceFormatSavers written in GDScript (see [ResourceFormatSaver] for more information).
</description>
</method>
<method name="get_recognized_extensions"> <method name="get_recognized_extensions">
<return type="PackedStringArray" /> <return type="PackedStringArray" />
<argument index="0" name="type" type="Resource" /> <argument index="0" name="type" type="Resource" />
@ -17,6 +26,13 @@
Returns the list of extensions available for saving a resource of a given type. Returns the list of extensions available for saving a resource of a given type.
</description> </description>
</method> </method>
<method name="remove_resource_format_saver">
<return type="void" />
<argument index="0" name="format_saver" type="ResourceFormatSaver" />
<description>
Unregisters the given [ResourceFormatSaver].
</description>
</method>
<method name="save"> <method name="save">
<return type="int" enum="Error" /> <return type="int" enum="Error" />
<argument index="0" name="path" type="String" /> <argument index="0" name="path" type="String" />