editor_export_plugin.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /**************************************************************************/
  2. /* editor_export_plugin.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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. #include "editor_export_plugin.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/io/dir_access.h"
  33. #include "core/io/file_access.h"
  34. #include "editor/editor_paths.h"
  35. #include "editor/editor_settings.h"
  36. #include "editor/export/editor_export_platform.h"
  37. #include "scene/resources/resource_format_text.h"
  38. void EditorExportPlugin::set_export_preset(const Ref<EditorExportPreset> &p_preset) {
  39. if (p_preset.is_valid()) {
  40. export_preset = p_preset;
  41. }
  42. }
  43. Ref<EditorExportPreset> EditorExportPlugin::get_export_preset() const {
  44. return export_preset;
  45. }
  46. void EditorExportPlugin::add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap) {
  47. ExtraFile ef;
  48. ef.data = p_file;
  49. ef.path = p_path;
  50. ef.remap = p_remap;
  51. extra_files.push_back(ef);
  52. }
  53. void EditorExportPlugin::add_shared_object(const String &p_path, const Vector<String> &p_tags, const String &p_target) {
  54. shared_objects.push_back(SharedObject(p_path, p_tags, p_target));
  55. }
  56. void EditorExportPlugin::add_ios_framework(const String &p_path) {
  57. ios_frameworks.push_back(p_path);
  58. }
  59. void EditorExportPlugin::add_ios_embedded_framework(const String &p_path) {
  60. ios_embedded_frameworks.push_back(p_path);
  61. }
  62. Vector<String> EditorExportPlugin::get_ios_frameworks() const {
  63. return ios_frameworks;
  64. }
  65. Vector<String> EditorExportPlugin::get_ios_embedded_frameworks() const {
  66. return ios_embedded_frameworks;
  67. }
  68. void EditorExportPlugin::add_ios_plist_content(const String &p_plist_content) {
  69. ios_plist_content += p_plist_content + "\n";
  70. }
  71. String EditorExportPlugin::get_ios_plist_content() const {
  72. return ios_plist_content;
  73. }
  74. void EditorExportPlugin::add_ios_linker_flags(const String &p_flags) {
  75. if (ios_linker_flags.length() > 0) {
  76. ios_linker_flags += ' ';
  77. }
  78. ios_linker_flags += p_flags;
  79. }
  80. String EditorExportPlugin::get_ios_linker_flags() const {
  81. return ios_linker_flags;
  82. }
  83. void EditorExportPlugin::add_ios_bundle_file(const String &p_path) {
  84. ios_bundle_files.push_back(p_path);
  85. }
  86. Vector<String> EditorExportPlugin::get_ios_bundle_files() const {
  87. return ios_bundle_files;
  88. }
  89. void EditorExportPlugin::add_ios_cpp_code(const String &p_code) {
  90. ios_cpp_code += p_code;
  91. }
  92. String EditorExportPlugin::get_ios_cpp_code() const {
  93. return ios_cpp_code;
  94. }
  95. void EditorExportPlugin::add_macos_plugin_file(const String &p_path) {
  96. macos_plugin_files.push_back(p_path);
  97. }
  98. const Vector<String> &EditorExportPlugin::get_macos_plugin_files() const {
  99. return macos_plugin_files;
  100. }
  101. void EditorExportPlugin::add_ios_project_static_lib(const String &p_path) {
  102. ios_project_static_libs.push_back(p_path);
  103. }
  104. Vector<String> EditorExportPlugin::get_ios_project_static_libs() const {
  105. return ios_project_static_libs;
  106. }
  107. void EditorExportPlugin::_export_file_script(const String &p_path, const String &p_type, const Vector<String> &p_features) {
  108. GDVIRTUAL_CALL(_export_file, p_path, p_type, p_features);
  109. }
  110. void EditorExportPlugin::_export_begin_script(const Vector<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
  111. GDVIRTUAL_CALL(_export_begin, p_features, p_debug, p_path, p_flags);
  112. }
  113. void EditorExportPlugin::_export_end_script() {
  114. GDVIRTUAL_CALL(_export_end);
  115. }
  116. // Customization
  117. bool EditorExportPlugin::_begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {
  118. bool ret = false;
  119. GDVIRTUAL_CALL(_begin_customize_resources, p_platform, p_features, ret);
  120. return ret;
  121. }
  122. Ref<Resource> EditorExportPlugin::_customize_resource(const Ref<Resource> &p_resource, const String &p_path) {
  123. Ref<Resource> ret;
  124. GDVIRTUAL_REQUIRED_CALL(_customize_resource, p_resource, p_path, ret);
  125. return ret;
  126. }
  127. bool EditorExportPlugin::_begin_customize_scenes(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {
  128. bool ret = false;
  129. GDVIRTUAL_CALL(_begin_customize_scenes, p_platform, p_features, ret);
  130. return ret;
  131. }
  132. Node *EditorExportPlugin::_customize_scene(Node *p_root, const String &p_path) {
  133. Node *ret = nullptr;
  134. GDVIRTUAL_REQUIRED_CALL(_customize_scene, p_root, p_path, ret);
  135. return ret;
  136. }
  137. uint64_t EditorExportPlugin::_get_customization_configuration_hash() const {
  138. uint64_t ret = 0;
  139. GDVIRTUAL_REQUIRED_CALL(_get_customization_configuration_hash, ret);
  140. return ret;
  141. }
  142. void EditorExportPlugin::_end_customize_scenes() {
  143. GDVIRTUAL_CALL(_end_customize_scenes);
  144. }
  145. void EditorExportPlugin::_end_customize_resources() {
  146. GDVIRTUAL_CALL(_end_customize_resources);
  147. }
  148. String EditorExportPlugin::_get_name() const {
  149. String ret;
  150. GDVIRTUAL_REQUIRED_CALL(_get_name, ret);
  151. return ret;
  152. }
  153. PackedStringArray EditorExportPlugin::_get_export_features(const Ref<EditorExportPlatform> &p_platform, bool p_debug) const {
  154. PackedStringArray ret;
  155. GDVIRTUAL_CALL(_get_export_features, p_platform, p_debug, ret);
  156. return ret;
  157. }
  158. void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) {
  159. }
  160. void EditorExportPlugin::_export_begin(const HashSet<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
  161. }
  162. void EditorExportPlugin::skip() {
  163. skipped = true;
  164. }
  165. void EditorExportPlugin::_bind_methods() {
  166. ClassDB::bind_method(D_METHOD("add_shared_object", "path", "tags", "target"), &EditorExportPlugin::add_shared_object);
  167. ClassDB::bind_method(D_METHOD("add_ios_project_static_lib", "path"), &EditorExportPlugin::add_ios_project_static_lib);
  168. ClassDB::bind_method(D_METHOD("add_file", "path", "file", "remap"), &EditorExportPlugin::add_file);
  169. ClassDB::bind_method(D_METHOD("add_ios_framework", "path"), &EditorExportPlugin::add_ios_framework);
  170. ClassDB::bind_method(D_METHOD("add_ios_embedded_framework", "path"), &EditorExportPlugin::add_ios_embedded_framework);
  171. ClassDB::bind_method(D_METHOD("add_ios_plist_content", "plist_content"), &EditorExportPlugin::add_ios_plist_content);
  172. ClassDB::bind_method(D_METHOD("add_ios_linker_flags", "flags"), &EditorExportPlugin::add_ios_linker_flags);
  173. ClassDB::bind_method(D_METHOD("add_ios_bundle_file", "path"), &EditorExportPlugin::add_ios_bundle_file);
  174. ClassDB::bind_method(D_METHOD("add_ios_cpp_code", "code"), &EditorExportPlugin::add_ios_cpp_code);
  175. ClassDB::bind_method(D_METHOD("add_macos_plugin_file", "path"), &EditorExportPlugin::add_macos_plugin_file);
  176. ClassDB::bind_method(D_METHOD("skip"), &EditorExportPlugin::skip);
  177. GDVIRTUAL_BIND(_export_file, "path", "type", "features");
  178. GDVIRTUAL_BIND(_export_begin, "features", "is_debug", "path", "flags");
  179. GDVIRTUAL_BIND(_export_end);
  180. GDVIRTUAL_BIND(_begin_customize_resources, "platform", "features");
  181. GDVIRTUAL_BIND(_customize_resource, "resource", "path");
  182. GDVIRTUAL_BIND(_begin_customize_scenes, "platform", "features");
  183. GDVIRTUAL_BIND(_customize_scene, "scene", "path");
  184. GDVIRTUAL_BIND(_get_customization_configuration_hash);
  185. GDVIRTUAL_BIND(_end_customize_scenes);
  186. GDVIRTUAL_BIND(_end_customize_resources);
  187. GDVIRTUAL_BIND(_get_export_features, "platform", "debug");
  188. GDVIRTUAL_BIND(_get_name);
  189. }
  190. EditorExportPlugin::EditorExportPlugin() {
  191. EDITOR_DEF("export/ssh/ssh", "");
  192. EDITOR_DEF("export/ssh/scp", "");
  193. }