Debian Codegraph @

platform/web/export/export_plugin.h

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