class_resourceformatloader.rst 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/ResourceFormatLoader.xml.
  6. .. _class_ResourceFormatLoader:
  7. ResourceFormatLoader
  8. ====================
  9. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. Loads a specific resource type from a file.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Godot loads resources in the editor or in exported games using ResourceFormatLoaders. They are queried automatically via the :ref:`ResourceLoader<class_ResourceLoader>` singleton, or when a resource with internal dependencies is loaded. Each file type may load as a different resource type, so multiple ResourceFormatLoaders are registered in the engine.
  15. Extending this class allows you to define your own loader. Be sure to respect the documented return types and values. You should give it a global class name with ``class_name`` for it to be registered. Like built-in ResourceFormatLoaders, it will be called automatically when loading resources of its handled type(s). You may also implement a :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`.
  16. \ **Note:** You can also extend :ref:`EditorImportPlugin<class_EditorImportPlugin>` if the resource type you need exists but Godot is unable to load its format. Choosing one way over another depends on if the format is suitable or not for the final exported game. For example, it's better to import ``.png`` textures as ``.stex`` (:ref:`StreamTexture<class_StreamTexture>`) first, so they can be loaded with better efficiency on the graphics card.
  17. .. rst-class:: classref-reftable-group
  18. Methods
  19. -------
  20. .. table::
  21. :widths: auto
  22. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | void | :ref:`get_dependencies<class_ResourceFormatLoader_method_get_dependencies>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` add_types **)** |virtual| |
  24. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`PoolStringArray<class_PoolStringArray>` | :ref:`get_recognized_extensions<class_ResourceFormatLoader_method_get_recognized_extensions>` **(** **)** |virtual| |
  26. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`String<class_String>` | :ref:`get_resource_type<class_ResourceFormatLoader_method_get_resource_type>` **(** :ref:`String<class_String>` path **)** |virtual| |
  28. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`bool<class_bool>` | :ref:`handles_type<class_ResourceFormatLoader_method_handles_type>` **(** :ref:`String<class_String>` typename **)** |virtual| |
  30. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Variant<class_Variant>` | :ref:`load<class_ResourceFormatLoader_method_load>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` original_path, :ref:`bool<class_bool>` no_subresource_cache **)** |virtual| |
  32. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`rename_dependencies<class_ResourceFormatLoader_method_rename_dependencies>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` renames **)** |virtual| |
  34. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. .. rst-class:: classref-section-separator
  36. ----
  37. .. rst-class:: classref-descriptions-group
  38. Method Descriptions
  39. -------------------
  40. .. _class_ResourceFormatLoader_method_get_dependencies:
  41. .. rst-class:: classref-method
  42. void **get_dependencies** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` add_types **)** |virtual|
  43. If implemented, gets the dependencies of a given resource. If ``add_types`` is ``true``, paths should be appended ``::TypeName``, where ``TypeName`` is the class name of the dependency.
  44. \ **Note:** Custom resource types defined by scripts aren't known by the :ref:`ClassDB<class_ClassDB>`, so you might just return ``"Resource"`` for them.
  45. .. rst-class:: classref-item-separator
  46. ----
  47. .. _class_ResourceFormatLoader_method_get_recognized_extensions:
  48. .. rst-class:: classref-method
  49. :ref:`PoolStringArray<class_PoolStringArray>` **get_recognized_extensions** **(** **)** |virtual|
  50. Gets the list of extensions for files this loader is able to read.
  51. .. rst-class:: classref-item-separator
  52. ----
  53. .. _class_ResourceFormatLoader_method_get_resource_type:
  54. .. rst-class:: classref-method
  55. :ref:`String<class_String>` **get_resource_type** **(** :ref:`String<class_String>` path **)** |virtual|
  56. Gets the class name of the resource associated with the given path. If the loader cannot handle it, it should return ``""``.
  57. \ **Note:** Custom resource types defined by scripts aren't known by the :ref:`ClassDB<class_ClassDB>`, so you might just return ``"Resource"`` for them.
  58. .. rst-class:: classref-item-separator
  59. ----
  60. .. _class_ResourceFormatLoader_method_handles_type:
  61. .. rst-class:: classref-method
  62. :ref:`bool<class_bool>` **handles_type** **(** :ref:`String<class_String>` typename **)** |virtual|
  63. Tells which resource class this loader can load.
  64. \ **Note:** Custom resource types defined by scripts aren't known by the :ref:`ClassDB<class_ClassDB>`, so you might just handle ``"Resource"`` for them.
  65. .. rst-class:: classref-item-separator
  66. ----
  67. .. _class_ResourceFormatLoader_method_load:
  68. .. rst-class:: classref-method
  69. :ref:`Variant<class_Variant>` **load** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` original_path, :ref:`bool<class_bool>` no_subresource_cache **)** |virtual|
  70. Loads a resource when the engine finds this loader to be compatible. If the loaded resource is the result of an import, ``original_path`` will target the source file. If ``no_subresource_cache`` is true, sub-resources should not be cached. Returns a :ref:`Resource<class_Resource>` object on success, or an :ref:`Error<enum_@GlobalScope_Error>` constant in case of failure.
  71. .. rst-class:: classref-item-separator
  72. ----
  73. .. _class_ResourceFormatLoader_method_rename_dependencies:
  74. .. rst-class:: classref-method
  75. :ref:`int<class_int>` **rename_dependencies** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` renames **)** |virtual|
  76. If implemented, renames dependencies within the given resource and saves it. ``renames`` is a dictionary ``{ String => String }`` mapping old dependency paths to new paths.
  77. Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success, or an :ref:`Error<enum_@GlobalScope_Error>` constant in case of failure.
  78. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  79. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  80. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  81. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`