editor_export_plugin.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*************************************************************************/
  2. /* editor_export_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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. #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/export/editor_export_platform.h"
  36. #include "scene/resources/resource_format_text.h"
  37. void EditorExportPlugin::set_export_preset(const Ref<EditorExportPreset> &p_preset) {
  38. if (p_preset.is_valid()) {
  39. export_preset = p_preset;
  40. }
  41. }
  42. Ref<EditorExportPreset> EditorExportPlugin::get_export_preset() const {
  43. return export_preset;
  44. }
  45. void EditorExportPlugin::add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap) {
  46. ExtraFile ef;
  47. ef.data = p_file;
  48. ef.path = p_path;
  49. ef.remap = p_remap;
  50. extra_files.push_back(ef);
  51. }
  52. void EditorExportPlugin::add_shared_object(const String &p_path, const Vector<String> &p_tags, const String &p_target) {
  53. shared_objects.push_back(SharedObject(p_path, p_tags, p_target));
  54. }
  55. void EditorExportPlugin::add_ios_framework(const String &p_path) {
  56. ios_frameworks.push_back(p_path);
  57. }
  58. void EditorExportPlugin::add_ios_embedded_framework(const String &p_path) {
  59. ios_embedded_frameworks.push_back(p_path);
  60. }
  61. Vector<String> EditorExportPlugin::get_ios_frameworks() const {
  62. return ios_frameworks;
  63. }
  64. Vector<String> EditorExportPlugin::get_ios_embedded_frameworks() const {
  65. return ios_embedded_frameworks;
  66. }
  67. void EditorExportPlugin::add_ios_plist_content(const String &p_plist_content) {
  68. ios_plist_content += p_plist_content + "\n";
  69. }
  70. String EditorExportPlugin::get_ios_plist_content() const {
  71. return ios_plist_content;
  72. }
  73. void EditorExportPlugin::add_ios_linker_flags(const String &p_flags) {
  74. if (ios_linker_flags.length() > 0) {
  75. ios_linker_flags += ' ';
  76. }
  77. ios_linker_flags += p_flags;
  78. }
  79. String EditorExportPlugin::get_ios_linker_flags() const {
  80. return ios_linker_flags;
  81. }
  82. void EditorExportPlugin::add_ios_bundle_file(const String &p_path) {
  83. ios_bundle_files.push_back(p_path);
  84. }
  85. Vector<String> EditorExportPlugin::get_ios_bundle_files() const {
  86. return ios_bundle_files;
  87. }
  88. void EditorExportPlugin::add_ios_cpp_code(const String &p_code) {
  89. ios_cpp_code += p_code;
  90. }
  91. String EditorExportPlugin::get_ios_cpp_code() const {
  92. return ios_cpp_code;
  93. }
  94. void EditorExportPlugin::add_macos_plugin_file(const String &p_path) {
  95. macos_plugin_files.push_back(p_path);
  96. }
  97. const Vector<String> &EditorExportPlugin::get_macos_plugin_files() const {
  98. return macos_plugin_files;
  99. }
  100. void EditorExportPlugin::add_ios_project_static_lib(const String &p_path) {
  101. ios_project_static_libs.push_back(p_path);
  102. }
  103. Vector<String> EditorExportPlugin::get_ios_project_static_libs() const {
  104. return ios_project_static_libs;
  105. }
  106. void EditorExportPlugin::_export_file_script(const String &p_path, const String &p_type, const Vector<String> &p_features) {
  107. GDVIRTUAL_CALL(_export_file, p_path, p_type, p_features);
  108. }
  109. void EditorExportPlugin::_export_begin_script(const Vector<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
  110. GDVIRTUAL_CALL(_export_begin, p_features, p_debug, p_path, p_flags);
  111. }
  112. void EditorExportPlugin::_export_end_script() {
  113. GDVIRTUAL_CALL(_export_end);
  114. }
  115. void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) {
  116. }
  117. void EditorExportPlugin::_export_begin(const HashSet<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
  118. }
  119. void EditorExportPlugin::skip() {
  120. skipped = true;
  121. }
  122. void EditorExportPlugin::_bind_methods() {
  123. ClassDB::bind_method(D_METHOD("add_shared_object", "path", "tags", "target"), &EditorExportPlugin::add_shared_object);
  124. ClassDB::bind_method(D_METHOD("add_ios_project_static_lib", "path"), &EditorExportPlugin::add_ios_project_static_lib);
  125. ClassDB::bind_method(D_METHOD("add_file", "path", "file", "remap"), &EditorExportPlugin::add_file);
  126. ClassDB::bind_method(D_METHOD("add_ios_framework", "path"), &EditorExportPlugin::add_ios_framework);
  127. ClassDB::bind_method(D_METHOD("add_ios_embedded_framework", "path"), &EditorExportPlugin::add_ios_embedded_framework);
  128. ClassDB::bind_method(D_METHOD("add_ios_plist_content", "plist_content"), &EditorExportPlugin::add_ios_plist_content);
  129. ClassDB::bind_method(D_METHOD("add_ios_linker_flags", "flags"), &EditorExportPlugin::add_ios_linker_flags);
  130. ClassDB::bind_method(D_METHOD("add_ios_bundle_file", "path"), &EditorExportPlugin::add_ios_bundle_file);
  131. ClassDB::bind_method(D_METHOD("add_ios_cpp_code", "code"), &EditorExportPlugin::add_ios_cpp_code);
  132. ClassDB::bind_method(D_METHOD("add_macos_plugin_file", "path"), &EditorExportPlugin::add_macos_plugin_file);
  133. ClassDB::bind_method(D_METHOD("skip"), &EditorExportPlugin::skip);
  134. GDVIRTUAL_BIND(_export_file, "path", "type", "features");
  135. GDVIRTUAL_BIND(_export_begin, "features", "is_debug", "path", "flags");
  136. GDVIRTUAL_BIND(_export_end);
  137. }
  138. EditorExportPlugin::EditorExportPlugin() {
  139. }
  140. ///////////////////////
  141. void EditorExportTextSceneToBinaryPlugin::_export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) {
  142. String extension = p_path.get_extension().to_lower();
  143. if (extension != "tres" && extension != "tscn") {
  144. return;
  145. }
  146. bool convert = GLOBAL_GET("editor/export/convert_text_resources_to_binary");
  147. if (!convert) {
  148. return;
  149. }
  150. String tmp_path = EditorPaths::get_singleton()->get_cache_dir().path_join("tmpfile.res");
  151. Error err = ResourceFormatLoaderText::convert_file_to_binary(p_path, tmp_path);
  152. if (err != OK) {
  153. DirAccess::remove_file_or_error(tmp_path);
  154. ERR_FAIL();
  155. }
  156. Vector<uint8_t> data = FileAccess::get_file_as_array(tmp_path);
  157. if (data.size() == 0) {
  158. DirAccess::remove_file_or_error(tmp_path);
  159. ERR_FAIL();
  160. }
  161. DirAccess::remove_file_or_error(tmp_path);
  162. add_file(p_path + ".converted.res", data, true);
  163. }
  164. EditorExportTextSceneToBinaryPlugin::EditorExportTextSceneToBinaryPlugin() {
  165. GLOBAL_DEF("editor/export/convert_text_resources_to_binary", false);
  166. }