class_resourceformatloader.rst 8.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the ResourceFormatLoader.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_ResourceFormatLoader:
  5. ResourceFormatLoader
  6. ====================
  7. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  8. **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>`
  9. **Category:** Core
  10. Brief Description
  11. -----------------
  12. Loads a specific resource type from a file.
  13. Methods
  14. -------
  15. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | void | :ref:`get_dependencies<class_ResourceFormatLoader_method_get_dependencies>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` add_types **)** virtual |
  17. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`PoolStringArray<class_PoolStringArray>` | :ref:`get_recognized_extensions<class_ResourceFormatLoader_method_get_recognized_extensions>` **(** **)** virtual |
  19. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`String<class_String>` | :ref:`get_resource_type<class_ResourceFormatLoader_method_get_resource_type>` **(** :ref:`String<class_String>` path **)** virtual |
  21. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`bool<class_bool>` | :ref:`handles_type<class_ResourceFormatLoader_method_handles_type>` **(** :ref:`String<class_String>` typename **)** virtual |
  23. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`Variant<class_Variant>` | :ref:`load<class_ResourceFormatLoader_method_load>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` original_path **)** virtual |
  25. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`int<class_int>` | :ref:`rename_dependencies<class_ResourceFormatLoader_method_rename_dependencies>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` renames **)** virtual |
  27. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. Description
  29. -----------
  30. Godot loads resources in the editor or in exported games using ResourceFormatLoaders. They get queried when you call ``load``, or when a resource with internal dependencies is loaded. Each file type may load as a different resource type, so multiple ResourceFormatLoader are registered in the engine.
  31. Extending this class allows you to define your own. You should give it a global class name with ``class_name`` for it to be registered. You may as well implement a :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`.
  32. 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. Example: it's better to import .PNG textures as .STEX first, so they can be loaded with better efficiency on the graphics card.
  33. Method Descriptions
  34. -------------------
  35. .. _class_ResourceFormatLoader_method_get_dependencies:
  36. - void **get_dependencies** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` add_types **)** virtual
  37. 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.
  38. .. _class_ResourceFormatLoader_method_get_recognized_extensions:
  39. - :ref:`PoolStringArray<class_PoolStringArray>` **get_recognized_extensions** **(** **)** virtual
  40. Gets the list of extensions for files this loader is able to read.
  41. .. _class_ResourceFormatLoader_method_get_resource_type:
  42. - :ref:`String<class_String>` **get_resource_type** **(** :ref:`String<class_String>` path **)** virtual
  43. 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.
  44. .. _class_ResourceFormatLoader_method_handles_type:
  45. - :ref:`bool<class_bool>` **handles_type** **(** :ref:`String<class_String>` typename **)** virtual
  46. 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.
  47. .. _class_ResourceFormatLoader_method_load:
  48. - :ref:`Variant<class_Variant>` **load** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` original_path **)** virtual
  49. 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 resource object if succeeded, or an ``ERR_*`` constant listed in :ref:`@GlobalScope<class_@GlobalScope>` if it failed.
  50. .. _class_ResourceFormatLoader_method_rename_dependencies:
  51. - :ref:`int<class_int>` **rename_dependencies** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` renames **)** virtual
  52. If implemented, renames dependencies within the given resource and saves it. ``renames`` is a dictionary ``{ String => String }`` mapping old dependency paths to new paths. Returns ``OK`` on success, or an ``ERR_*`` constant listed in :ref:`@GlobalScope<class_@GlobalScope>` in case of failure.