resource_import.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*************************************************************************/
  2. /* resource_import.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef RESOURCE_IMPORT_H
  31. #define RESOURCE_IMPORT_H
  32. #include "core/io/resource_loader.h"
  33. class ResourceImporter;
  34. class ResourceFormatImporter : public ResourceFormatLoader {
  35. GDCLASS(ResourceFormatImporter, ResourceFormatLoader)
  36. struct PathAndType {
  37. String path;
  38. String type;
  39. String importer;
  40. };
  41. Error _get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid = NULL) const;
  42. static ResourceFormatImporter *singleton;
  43. Vector<Ref<ResourceImporter> > importers;
  44. public:
  45. static ResourceFormatImporter *get_singleton() { return singleton; }
  46. virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
  47. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  48. virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const;
  49. virtual bool recognize_path(const String &p_path, const String &p_for_type = String()) const;
  50. virtual bool handles_type(const String &p_type) const;
  51. virtual String get_resource_type(const String &p_path) const;
  52. virtual bool is_import_valid(const String &p_path) const;
  53. virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
  54. virtual bool can_be_imported(const String &p_path) const;
  55. virtual int get_import_order(const String &p_path) const;
  56. String get_internal_resource_path(const String &p_path) const;
  57. void get_internal_resource_path_list(const String &p_path, List<String> *r_paths);
  58. void add_importer(const Ref<ResourceImporter> &p_importer) { importers.push_back(p_importer); }
  59. void remove_importer(const Ref<ResourceImporter> &p_importer) { importers.erase(p_importer); }
  60. Ref<ResourceImporter> get_importer_by_name(const String &p_name) const;
  61. Ref<ResourceImporter> get_importer_by_extension(const String &p_extension) const;
  62. void get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter> > *r_importers);
  63. String get_import_base_path(const String &p_for_file) const;
  64. ResourceFormatImporter();
  65. };
  66. class ResourceImporter : public Reference {
  67. GDCLASS(ResourceImporter, Reference)
  68. public:
  69. virtual String get_importer_name() const = 0;
  70. virtual String get_visible_name() const = 0;
  71. virtual void get_recognized_extensions(List<String> *p_extensions) const = 0;
  72. virtual String get_save_extension() const = 0;
  73. virtual String get_resource_type() const = 0;
  74. virtual float get_priority() const { return 1.0; }
  75. virtual int get_import_order() const { return 0; }
  76. struct ImportOption {
  77. PropertyInfo option;
  78. Variant default_value;
  79. ImportOption(const PropertyInfo &p_info, const Variant &p_default) :
  80. option(p_info),
  81. default_value(p_default) {
  82. }
  83. ImportOption() {}
  84. };
  85. virtual int get_preset_count() const { return 0; }
  86. virtual String get_preset_name(int p_idx) const { return String(); }
  87. virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const = 0;
  88. virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const = 0;
  89. virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL) = 0;
  90. };
  91. #endif // RESOURCE_IMPORT_H