class_resourceformatloader.rst 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the ResourceFormatLoader.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_ResourceFormatLoader:
  6. ResourceFormatLoader
  7. ====================
  8. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`GDNativeLibraryResourceLoader<class_GDNativeLibraryResourceLoader>`, :ref:`ResourceFormatDDS<class_ResourceFormatDDS>`, :ref:`ResourceFormatImporter<class_ResourceFormatImporter>`, :ref:`ResourceFormatLoaderBMFont<class_ResourceFormatLoaderBMFont>`, :ref:`ResourceFormatLoaderBinary<class_ResourceFormatLoaderBinary>`, :ref:`ResourceFormatLoaderDynamicFont<class_ResourceFormatLoaderDynamicFont>`, :ref:`ResourceFormatLoaderGDScript<class_ResourceFormatLoaderGDScript>`, :ref:`ResourceFormatLoaderImage<class_ResourceFormatLoaderImage>`, :ref:`ResourceFormatLoaderNativeScript<class_ResourceFormatLoaderNativeScript>`, :ref:`ResourceFormatLoaderShader<class_ResourceFormatLoaderShader>`, :ref:`ResourceFormatLoaderStreamTexture<class_ResourceFormatLoaderStreamTexture>`, :ref:`ResourceFormatLoaderText<class_ResourceFormatLoaderText>`, :ref:`ResourceFormatLoaderTextureLayered<class_ResourceFormatLoaderTextureLayered>`, :ref:`ResourceFormatLoaderTheora<class_ResourceFormatLoaderTheora>`, :ref:`ResourceFormatLoaderVideoStreamGDNative<class_ResourceFormatLoaderVideoStreamGDNative>`, :ref:`ResourceFormatLoaderWebm<class_ResourceFormatLoaderWebm>`, :ref:`ResourceFormatPKM<class_ResourceFormatPKM>`, :ref:`ResourceFormatPVR<class_ResourceFormatPVR>`, :ref:`TranslationLoaderPO<class_TranslationLoaderPO>`
  10. **Category:** Core
  11. Brief Description
  12. -----------------
  13. Loads a specific resource type from a file.
  14. Methods
  15. -------
  16. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  17. | void | :ref:`get_dependencies<class_ResourceFormatLoader_method_get_dependencies>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` add_types **)** virtual |
  18. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`PoolStringArray<class_PoolStringArray>` | :ref:`get_recognized_extensions<class_ResourceFormatLoader_method_get_recognized_extensions>` **(** **)** virtual |
  20. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`String<class_String>` | :ref:`get_resource_type<class_ResourceFormatLoader_method_get_resource_type>` **(** :ref:`String<class_String>` path **)** virtual |
  22. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`bool<class_bool>` | :ref:`handles_type<class_ResourceFormatLoader_method_handles_type>` **(** :ref:`String<class_String>` typename **)** virtual |
  24. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`Variant<class_Variant>` | :ref:`load<class_ResourceFormatLoader_method_load>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` original_path **)** virtual |
  26. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`int<class_int>` | :ref:`rename_dependencies<class_ResourceFormatLoader_method_rename_dependencies>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` renames **)** virtual |
  28. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. Description
  30. -----------
  31. 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.
  32. 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>`.
  33. 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 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.
  34. Method Descriptions
  35. -------------------
  36. .. _class_ResourceFormatLoader_method_get_dependencies:
  37. - void **get_dependencies** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` add_types **)** virtual
  38. 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. Note that custom resource types defined by scripts aren't known by the :ref:`ClassDB<class_ClassDB>`, so you might just return ``"Resource"`` for them.
  39. ----
  40. .. _class_ResourceFormatLoader_method_get_recognized_extensions:
  41. - :ref:`PoolStringArray<class_PoolStringArray>` **get_recognized_extensions** **(** **)** virtual
  42. Gets the list of extensions for files this loader is able to read.
  43. ----
  44. .. _class_ResourceFormatLoader_method_get_resource_type:
  45. - :ref:`String<class_String>` **get_resource_type** **(** :ref:`String<class_String>` path **)** virtual
  46. Gets the class name of the resource associated with the given path. If the loader cannot handle it, it should return ``""``. Note that custom resource types defined by scripts aren't known by the :ref:`ClassDB<class_ClassDB>`, so you might just return ``"Resource"`` for them.
  47. ----
  48. .. _class_ResourceFormatLoader_method_handles_type:
  49. - :ref:`bool<class_bool>` **handles_type** **(** :ref:`String<class_String>` typename **)** virtual
  50. Tells which resource class this loader can load. Note that custom resource types defined by scripts aren't known by the :ref:`ClassDB<class_ClassDB>`, so you might just handle ``"Resource"`` for them.
  51. ----
  52. .. _class_ResourceFormatLoader_method_load:
  53. - :ref:`Variant<class_Variant>` **load** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` original_path **)** virtual
  54. 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. Returns a :ref:`Resource<class_Resource>` object on success, or an :ref:`Error<enum_@GlobalScope_Error>` constant in case of failure.
  55. ----
  56. .. _class_ResourceFormatLoader_method_rename_dependencies:
  57. - :ref:`int<class_int>` **rename_dependencies** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` renames **)** virtual
  58. If implemented, renames dependencies within the given resource and saves it. ``renames`` is a dictionary ``{ String => String }`` mapping old dependency paths to new paths.
  59. Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success, or an :ref:`Error<enum_@GlobalScope_Error>` constant in case of failure.