editor_import_export.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /*************************************************************************/
  2. /* editor_import_export.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef EDITOR_IMPORT_EXPORT_H
  30. #define EDITOR_IMPORT_EXPORT_H
  31. #include "resource.h"
  32. #include "scene/main/node.h"
  33. #include "scene/resources/texture.h"
  34. class EditorExportPlatform;
  35. class FileAccess;
  36. class EditorProgress;
  37. class EditorImportPlugin : public Reference {
  38. OBJ_TYPE( EditorImportPlugin, Reference);
  39. protected:
  40. static void _bind_methods();
  41. public:
  42. static String validate_source_path(const String& p_path);
  43. static String expand_source_path(const String& p_path);
  44. virtual String get_name() const;
  45. virtual String get_visible_name() const;
  46. virtual void import_dialog(const String& p_from="");
  47. virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
  48. virtual Vector<uint8_t> custom_export(const String& p_path,const Ref<EditorExportPlatform> &p_platform);
  49. EditorImportPlugin();
  50. };
  51. class EditorExportPlugin : public Reference {
  52. OBJ_TYPE( EditorExportPlugin, Reference);
  53. protected:
  54. static void _bind_methods();
  55. public:
  56. virtual Vector<uint8_t> custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform);
  57. EditorExportPlugin();
  58. };
  59. class EditorExportPlatform : public Reference {
  60. OBJ_TYPE( EditorExportPlatform,Reference );
  61. public:
  62. typedef Error (*EditorExportSaveFunction)(void *p_userdata,const String& p_path, const Vector<uint8_t>& p_data,int p_file,int p_total);
  63. protected:
  64. virtual Vector<uint8_t> get_exported_file(String& p_fname) const;
  65. virtual Vector<StringName> get_dependencies(bool p_bundles) const;
  66. struct TempData {
  67. uint64_t pos;
  68. uint64_t ofs;
  69. uint64_t size;
  70. };
  71. struct PackData {
  72. FileAccess *ftmp;
  73. FileAccess *f;
  74. Vector<TempData> file_ofs;
  75. EditorProgress *ep;
  76. int count;
  77. };
  78. static Error save_pack_file(void *p_userdata,const String& p_path, const Vector<uint8_t>& p_data,int p_file,int p_total);
  79. public:
  80. enum ImageCompression {
  81. IMAGE_COMPRESSION_NONE,
  82. IMAGE_COMPRESSION_INDEXED, // used for older hardware
  83. IMAGE_COMPRESSION_BC, // directx compression format
  84. IMAGE_COMPRESSION_PVRTC, // powervr compression format
  85. IMAGE_COMPRESSION_PVRTC_SQUARE, // powervr compression format, square (ios)
  86. IMAGE_COMPRESSION_ETC1, // ericsson compression format (alpha is uncompressed)
  87. IMAGE_COMPRESSION_ETC2, // ericsson new compression format (can handle alpha)
  88. };
  89. Error export_project_files(EditorExportSaveFunction p_func, void* p_udata,bool p_make_bundles);
  90. Error save_pack(FileAccess *p_where, bool p_make_bundles=false);
  91. virtual String get_name() const =0;
  92. virtual ImageCompression get_image_compression() const=0;
  93. virtual Ref<Texture> get_logo() const =0;
  94. virtual bool poll_devices() { return false; }
  95. virtual int get_device_count() const { return 0; }
  96. virtual String get_device_name(int p_device) const { return ""; }
  97. virtual String get_device_info(int p_device) const { return ""; }
  98. virtual Error run(int p_device,bool p_dumb=false) { return OK; }
  99. virtual bool can_export(String *r_error=NULL) const=0;
  100. virtual bool requieres_password(bool p_debug) const { return false; }
  101. virtual String get_binary_extension() const=0;
  102. virtual Error export_project(const String& p_path,bool p_debug,bool p_dumb=false)=0;
  103. EditorExportPlatform() {};
  104. };
  105. class EditorExportPlatformPC : public EditorExportPlatform {
  106. OBJ_TYPE( EditorExportPlatformPC,EditorExportPlatform );
  107. public:
  108. enum ExportMode {
  109. EXPORT_EXE,
  110. EXPORT_PACK,
  111. EXPORT_COPY,
  112. EXPORT_BUNDLES
  113. };
  114. private:
  115. String binary_extension;
  116. String platform;
  117. String custom_release_binary;
  118. String custom_debug_binary;
  119. String release_binary32;
  120. String debug_binary32;
  121. String release_binary64;
  122. String debug_binary64;
  123. String name;
  124. bool use64;
  125. Ref<Texture> logo;
  126. ExportMode export_mode;
  127. protected:
  128. bool _set(const StringName& p_name, const Variant& p_value);
  129. bool _get(const StringName& p_name,Variant &r_ret) const;
  130. void _get_property_list( List<PropertyInfo> *p_list) const;
  131. public:
  132. virtual String get_name() const { return name; }
  133. virtual Ref<Texture> get_logo() const { return logo; }
  134. virtual ImageCompression get_image_compression() const { return IMAGE_COMPRESSION_BC; }
  135. virtual String get_binary_extension() const { return binary_extension; }
  136. virtual Error export_project(const String& p_path,bool p_debug,bool p_dumb=false);
  137. virtual void set_release_binary32(const String& p_binary) { release_binary32=p_binary; }
  138. virtual void set_debug_binary32(const String& p_binary) { debug_binary32=p_binary; }
  139. virtual void set_release_binary64(const String& p_binary) { release_binary64=p_binary; }
  140. virtual void set_debug_binary64(const String& p_binary) { debug_binary64=p_binary; }
  141. virtual void set_name(const String& p_name) { name=p_name; }
  142. virtual void set_logo(const Ref<Texture>& p_logo) { logo=p_logo; }
  143. virtual bool can_export(String *r_error=NULL) const;
  144. void set_binary_extension(const String& p_extension);
  145. EditorExportPlatformPC();
  146. };
  147. class EditorImportExport : public Node {
  148. OBJ_TYPE(EditorImportExport,Node);
  149. public:
  150. enum FileAction {
  151. ACTION_NONE,
  152. ACTION_COPY,
  153. ACTION_BUNDLE
  154. };
  155. enum ExportFilter {
  156. EXPORT_SELECTED,
  157. EXPORT_RESOURCES,
  158. EXPORT_ALL,
  159. };
  160. enum ImageAction {
  161. IMAGE_ACTION_NONE,
  162. IMAGE_ACTION_COMPRESS_DISK,
  163. IMAGE_ACTION_COMPRESS_RAM,
  164. };
  165. enum ScriptAction {
  166. SCRIPT_ACTION_NONE,
  167. SCRIPT_ACTION_COMPILE,
  168. SCRIPT_ACTION_ENCRYPT
  169. };
  170. protected:
  171. struct ImageGroup {
  172. ImageAction action;
  173. bool make_atlas;
  174. float lossy_quality;
  175. int shrink;
  176. };
  177. Vector<Ref<EditorExportPlugin> > export_plugins;
  178. Vector<Ref<EditorImportPlugin> > plugins;
  179. Map<String,int> by_idx;
  180. ImageAction image_action;
  181. float image_action_compress_quality;
  182. int image_shrink;
  183. Set<String> image_formats;
  184. ExportFilter export_filter;
  185. String export_custom_filter;
  186. Map<StringName,FileAction> files;
  187. Map<StringName,Ref<EditorExportPlatform> > exporters;
  188. Map<StringName,ImageGroup> image_groups;
  189. Map<StringName,StringName> image_group_files;
  190. Vector<String> diff_packs;
  191. ScriptAction script_action;
  192. String script_key;
  193. static EditorImportExport* singleton;
  194. static void _bind_methods();
  195. public:
  196. static EditorImportExport* get_singleton() { return singleton; }
  197. void add_import_plugin(const Ref<EditorImportPlugin>& p_plugin);
  198. void remove_import_plugin(const Ref<EditorImportPlugin>& p_plugin);
  199. int get_import_plugin_count() const;
  200. Ref<EditorImportPlugin> get_import_plugin(int p_idx) const;
  201. Ref<EditorImportPlugin> get_import_plugin_by_name(const String& p_string) const;
  202. void add_export_plugin(const Ref<EditorExportPlugin>& p_plugin);
  203. int get_export_plugin_count() const;
  204. Ref<EditorExportPlugin> get_export_plugin(int p_idx) const;
  205. bool poll_export_platforms();
  206. void set_export_file_action(const StringName& p_export_file, FileAction p_action);
  207. FileAction get_export_file_action(const StringName& p_export_file) const;
  208. void get_export_file_list(List<StringName> *p_export_files);
  209. void add_export_platform(const Ref<EditorExportPlatform>& p_export);
  210. Ref<EditorExportPlatform> get_export_platform(const StringName& p_platform);
  211. void get_export_platforms(List<StringName> *r_platforms);
  212. void set_export_filter(ExportFilter p_enable);
  213. ExportFilter get_export_filter() const;
  214. void set_export_custom_filter(const String& p_custom_filter);
  215. String get_export_custom_filter() const;
  216. void set_export_image_action(ImageAction p_action);
  217. ImageAction get_export_image_action() const;
  218. void set_export_image_shrink(int p_shrink);
  219. int get_export_image_shrink() const;
  220. void set_export_image_quality(float p_quality);
  221. float get_export_image_quality() const;
  222. Vector<String>& get_diff_packs() { return diff_packs; }
  223. void image_export_group_create(const StringName& p_name);
  224. void image_export_group_remove(const StringName& p_name);
  225. bool image_export_has_group(const StringName& p_name) const;
  226. void image_export_get_groups(List<StringName> *r_name) const;
  227. void image_export_group_set_image_action(const StringName& p_export_group,ImageAction p_action);
  228. ImageAction image_export_group_get_image_action(const StringName& p_export_group) const;
  229. void image_export_group_set_make_atlas(const StringName& p_export_group,bool p_make);
  230. bool image_export_group_get_make_atlas(const StringName& p_export_group) const;
  231. void image_export_group_set_shrink(const StringName& p_export_group,int p_amount);
  232. int image_export_group_get_shrink(const StringName& p_export_group) const;
  233. void image_export_group_set_lossy_quality(const StringName& p_export_group,float p_quality);
  234. float image_export_group_get_lossy_quality(const StringName& p_export_group) const;
  235. void image_add_to_export_group(const StringName& p_image,const StringName& p_export_group);
  236. StringName image_get_export_group(const StringName& p_image) const;
  237. void image_export_get_images_in_group(const StringName& p_group, List<StringName> *r_images) const;
  238. Set<String>& get_image_formats() { return image_formats; }
  239. void script_set_action(ScriptAction p_action);
  240. ScriptAction script_get_action() const;
  241. void script_set_encryption_key(const String& p_key);
  242. String script_get_encryption_key() const;
  243. void load_config();
  244. void save_config();
  245. EditorImportExport();
  246. };
  247. VARIANT_ENUM_CAST(EditorImportExport::ImageAction);
  248. VARIANT_ENUM_CAST(EditorImportExport::ScriptAction);
  249. #endif // EDITOR_IMPORT_EXPORT_H