export_plugin.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**************************************************************************/
  2. /* export_plugin.h */
  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. #ifndef WEB_EXPORT_PLUGIN_H
  31. #define WEB_EXPORT_PLUGIN_H
  32. #include "editor_http_server.h"
  33. #include "core/config/project_settings.h"
  34. #include "core/io/image_loader.h"
  35. #include "core/io/stream_peer_tls.h"
  36. #include "core/io/tcp_server.h"
  37. #include "core/io/zip_io.h"
  38. #include "editor/editor_node.h"
  39. #include "editor/editor_string_names.h"
  40. #include "editor/export/editor_export_platform.h"
  41. #include "main/splash.gen.h"
  42. class EditorExportPlatformWeb : public EditorExportPlatform {
  43. GDCLASS(EditorExportPlatformWeb, EditorExportPlatform);
  44. enum RemoteDebugState {
  45. REMOTE_DEBUG_STATE_UNAVAILABLE,
  46. REMOTE_DEBUG_STATE_AVAILABLE,
  47. REMOTE_DEBUG_STATE_SERVING,
  48. };
  49. Ref<ImageTexture> logo;
  50. Ref<ImageTexture> run_icon;
  51. Ref<ImageTexture> stop_icon;
  52. Ref<ImageTexture> restart_icon;
  53. RemoteDebugState remote_debug_state = REMOTE_DEBUG_STATE_UNAVAILABLE;
  54. Ref<EditorHTTPServer> server;
  55. String _get_template_name(bool p_extension, bool p_thread_support, bool p_debug) const {
  56. String name = "web";
  57. if (p_extension) {
  58. name += "_dlink";
  59. }
  60. if (!p_thread_support) {
  61. name += "_nothreads";
  62. }
  63. if (p_debug) {
  64. name += "_debug.zip";
  65. } else {
  66. name += "_release.zip";
  67. }
  68. return name;
  69. }
  70. Ref<Image> _get_project_icon() const {
  71. Error err = OK;
  72. Ref<Image> icon;
  73. icon.instantiate();
  74. const String icon_path = String(GLOBAL_GET("application/config/icon")).strip_edges();
  75. if (!icon_path.is_empty()) {
  76. icon = _load_icon_or_splash_image(icon_path, &err);
  77. }
  78. if (icon_path.is_empty() || err != OK || icon.is_null() || icon->is_empty()) {
  79. return EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("DefaultProjectIcon"), EditorStringName(EditorIcons))->get_image();
  80. }
  81. return icon;
  82. }
  83. Ref<Image> _get_project_splash() const {
  84. Error err = OK;
  85. Ref<Image> splash;
  86. splash.instantiate();
  87. const String splash_path = String(GLOBAL_GET("application/boot_splash/image")).strip_edges();
  88. if (!splash_path.is_empty()) {
  89. splash = _load_icon_or_splash_image(splash_path, &err);
  90. }
  91. if (splash_path.is_empty() || err != OK || splash.is_null() || splash->is_empty()) {
  92. return Ref<Image>(memnew(Image(boot_splash_png)));
  93. }
  94. return splash;
  95. }
  96. Error _extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa);
  97. void _replace_strings(const HashMap<String, String> &p_replaces, Vector<uint8_t> &r_template);
  98. void _fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug, BitField<EditorExportPlatform::DebugFlags> p_flags, const Vector<SharedObject> p_shared_objects, const Dictionary &p_file_sizes);
  99. Error _add_manifest_icon(const String &p_path, const String &p_icon, int p_size, Array &r_arr);
  100. Error _build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects);
  101. Error _write_or_error(const uint8_t *p_content, int p_len, String p_path);
  102. Error _export_project(const Ref<EditorExportPreset> &p_preset, int p_debug_flags);
  103. Error _launch_browser(const String &p_bind_host, uint16_t p_bind_port, bool p_use_tls);
  104. Error _start_server(const String &p_bind_host, uint16_t p_bind_port, bool p_use_tls);
  105. Error _stop_server();
  106. public:
  107. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const override;
  108. virtual void get_export_options(List<ExportOption> *r_options) const override;
  109. virtual bool get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const override;
  110. virtual String get_name() const override;
  111. virtual String get_os_name() const override;
  112. virtual Ref<Texture2D> get_logo() const override;
  113. virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug = false) const override;
  114. virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;
  115. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;
  116. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags = 0) override;
  117. virtual bool poll_export() override;
  118. virtual int get_options_count() const override;
  119. virtual String get_option_label(int p_index) const override;
  120. virtual String get_option_tooltip(int p_index) const override;
  121. virtual Ref<ImageTexture> get_option_icon(int p_index) const override;
  122. virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_option, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) override;
  123. virtual Ref<Texture2D> get_run_icon() const override;
  124. virtual void get_platform_features(List<String> *r_features) const override {
  125. r_features->push_back("web");
  126. r_features->push_back(get_os_name().to_lower());
  127. }
  128. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, HashSet<String> &p_features) override {
  129. }
  130. String get_debug_protocol() const override { return "ws://"; }
  131. EditorExportPlatformWeb();
  132. ~EditorExportPlatformWeb();
  133. };
  134. #endif // WEB_EXPORT_PLUGIN_H