2021-07-14 20:16:48 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* export_plugin.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2022-08-28 18:27:45 +00:00
|
|
|
#ifndef WEB_EXPORT_PLUGIN_H
|
|
|
|
#define WEB_EXPORT_PLUGIN_H
|
2021-07-14 20:16:48 +00:00
|
|
|
|
2023-06-08 12:51:32 +00:00
|
|
|
#include "editor_http_server.h"
|
|
|
|
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "core/config/project_settings.h"
|
2021-07-14 20:16:48 +00:00
|
|
|
#include "core/io/image_loader.h"
|
2022-09-06 22:46:12 +00:00
|
|
|
#include "core/io/stream_peer_tls.h"
|
2021-07-14 20:16:48 +00:00
|
|
|
#include "core/io/tcp_server.h"
|
|
|
|
#include "core/io/zip_io.h"
|
2022-02-14 13:00:03 +00:00
|
|
|
#include "editor/editor_node.h"
|
2023-08-13 00:33:39 +00:00
|
|
|
#include "editor/editor_string_names.h"
|
2022-07-17 17:24:37 +00:00
|
|
|
#include "editor/export/editor_export_platform.h"
|
2022-05-08 07:46:53 +00:00
|
|
|
#include "main/splash.gen.h"
|
2021-07-14 20:16:48 +00:00
|
|
|
|
2022-08-28 18:27:45 +00:00
|
|
|
class EditorExportPlatformWeb : public EditorExportPlatform {
|
|
|
|
GDCLASS(EditorExportPlatformWeb, EditorExportPlatform);
|
2021-07-14 20:16:48 +00:00
|
|
|
|
2024-04-30 17:37:41 +00:00
|
|
|
enum HTTPServerState {
|
|
|
|
HTTP_SERVER_STATE_OFF,
|
|
|
|
HTTP_SERVER_STATE_ON,
|
|
|
|
};
|
|
|
|
|
2021-07-14 20:16:48 +00:00
|
|
|
Ref<ImageTexture> logo;
|
|
|
|
Ref<ImageTexture> run_icon;
|
|
|
|
Ref<ImageTexture> stop_icon;
|
2024-04-30 17:37:41 +00:00
|
|
|
Ref<ImageTexture> restart_icon;
|
|
|
|
HTTPServerState server_state = HTTP_SERVER_STATE_OFF;
|
2021-07-14 20:16:48 +00:00
|
|
|
|
|
|
|
Ref<EditorHTTPServer> server;
|
|
|
|
|
2023-12-01 18:39:09 +00:00
|
|
|
String _get_template_name(bool p_extension, bool p_thread_support, bool p_debug) const {
|
2022-08-29 13:56:28 +00:00
|
|
|
String name = "web";
|
|
|
|
if (p_extension) {
|
|
|
|
name += "_dlink";
|
2021-07-14 20:16:48 +00:00
|
|
|
}
|
2023-12-01 18:39:09 +00:00
|
|
|
if (!p_thread_support) {
|
|
|
|
name += "_nothreads";
|
|
|
|
}
|
2021-07-14 20:16:48 +00:00
|
|
|
if (p_debug) {
|
|
|
|
name += "_debug.zip";
|
|
|
|
} else {
|
|
|
|
name += "_release.zip";
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Image> _get_project_icon() const {
|
|
|
|
Ref<Image> icon;
|
|
|
|
icon.instantiate();
|
|
|
|
const String icon_path = String(GLOBAL_GET("application/config/icon")).strip_edges();
|
|
|
|
if (icon_path.is_empty() || ImageLoader::load_image(icon_path, icon) != OK) {
|
2023-08-13 00:33:39 +00:00
|
|
|
return EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("DefaultProjectIcon"), EditorStringName(EditorIcons))->get_image();
|
2021-07-14 20:16:48 +00:00
|
|
|
}
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Image> _get_project_splash() const {
|
|
|
|
Ref<Image> splash;
|
|
|
|
splash.instantiate();
|
|
|
|
const String splash_path = String(GLOBAL_GET("application/boot_splash/image")).strip_edges();
|
|
|
|
if (splash_path.is_empty() || ImageLoader::load_image(splash_path, splash) != OK) {
|
|
|
|
return Ref<Image>(memnew(Image(boot_splash_png)));
|
|
|
|
}
|
|
|
|
return splash;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error _extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa);
|
2021-08-01 19:47:20 +00:00
|
|
|
void _replace_strings(const HashMap<String, String> &p_replaces, Vector<uint8_t> &r_template);
|
2021-07-14 20:16:48 +00:00
|
|
|
void _fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug, int p_flags, const Vector<SharedObject> p_shared_objects, const Dictionary &p_file_sizes);
|
|
|
|
Error _add_manifest_icon(const String &p_path, const String &p_icon, int p_size, Array &r_arr);
|
|
|
|
Error _build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects);
|
|
|
|
Error _write_or_error(const uint8_t *p_content, int p_len, String p_path);
|
|
|
|
|
2024-04-30 17:37:41 +00:00
|
|
|
Error _export_project(const Ref<EditorExportPreset> &p_preset, int p_debug_flags);
|
|
|
|
Error _launch_browser(const String &p_bind_host, uint16_t p_bind_port, bool p_use_tls);
|
|
|
|
Error _start_server(const String &p_bind_host, uint16_t p_bind_port, bool p_use_tls);
|
|
|
|
Error _stop_server();
|
|
|
|
|
2021-07-14 20:16:48 +00:00
|
|
|
public:
|
2022-07-27 22:34:12 +00:00
|
|
|
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const override;
|
2021-07-14 20:16:48 +00:00
|
|
|
|
2023-03-09 08:41:52 +00:00
|
|
|
virtual void get_export_options(List<ExportOption> *r_options) const override;
|
2021-07-14 20:16:48 +00:00
|
|
|
|
|
|
|
virtual String get_name() const override;
|
|
|
|
virtual String get_os_name() const override;
|
|
|
|
virtual Ref<Texture2D> get_logo() const override;
|
|
|
|
|
2023-06-11 17:01:39 +00:00
|
|
|
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug = false) const override;
|
2022-07-17 19:26:03 +00:00
|
|
|
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;
|
2021-07-14 20:16:48 +00:00
|
|
|
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;
|
|
|
|
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;
|
|
|
|
|
|
|
|
virtual bool poll_export() override;
|
|
|
|
virtual int get_options_count() const override;
|
2024-04-30 17:37:41 +00:00
|
|
|
virtual String get_option_label(int p_index) const override;
|
|
|
|
virtual String get_option_tooltip(int p_index) const override;
|
2021-07-14 20:16:48 +00:00
|
|
|
virtual Ref<ImageTexture> get_option_icon(int p_index) const override;
|
|
|
|
virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags) override;
|
|
|
|
virtual Ref<Texture2D> get_run_icon() const override;
|
|
|
|
|
2022-07-27 22:34:12 +00:00
|
|
|
virtual void get_platform_features(List<String> *r_features) const override {
|
2021-07-14 20:16:48 +00:00
|
|
|
r_features->push_back("web");
|
2021-03-26 14:33:36 +00:00
|
|
|
r_features->push_back(get_os_name().to_lower());
|
2021-07-14 20:16:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 15:00:06 +00:00
|
|
|
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, HashSet<String> &p_features) override {
|
2021-07-14 20:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String get_debug_protocol() const override { return "ws://"; }
|
|
|
|
|
2022-08-28 18:27:45 +00:00
|
|
|
EditorExportPlatformWeb();
|
|
|
|
~EditorExportPlatformWeb();
|
2021-07-14 20:16:48 +00:00
|
|
|
};
|
|
|
|
|
2022-08-28 18:27:45 +00:00
|
|
|
#endif // WEB_EXPORT_PLUGIN_H
|