Path: blob/master/platform/web/export/export_plugin.h
21022 views
/**************************************************************************/1/* export_plugin.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "editor_http_server.h"3334#include "core/config/project_settings.h"35#include "core/io/image_loader.h"36#include "core/io/stream_peer_tls.h"37#include "core/io/tcp_server.h"38#include "core/io/zip_io.h"39#include "editor/editor_node.h"40#include "editor/editor_string_names.h"41#include "editor/export/editor_export_platform.h"42#include "main/splash.gen.h"4344class ImageTexture;4546class EditorExportPlatformWeb : public EditorExportPlatform {47GDCLASS(EditorExportPlatformWeb, EditorExportPlatform);4849enum RemoteDebugState {50REMOTE_DEBUG_STATE_UNAVAILABLE,51REMOTE_DEBUG_STATE_AVAILABLE,52REMOTE_DEBUG_STATE_SERVING,53};5455Ref<ImageTexture> logo;56Ref<ImageTexture> run_icon;57Ref<ImageTexture> stop_icon;58Ref<ImageTexture> restart_icon;59RemoteDebugState remote_debug_state = REMOTE_DEBUG_STATE_UNAVAILABLE;6061Ref<EditorHTTPServer> server;6263String _get_template_name(bool p_extension, bool p_thread_support, bool p_debug) const {64String name = "web";65if (p_extension) {66name += "_dlink";67}68if (!p_thread_support) {69name += "_nothreads";70}71if (p_debug) {72name += "_debug.zip";73} else {74name += "_release.zip";75}76return name;77}7879Ref<Image> _get_project_icon(const Ref<EditorExportPreset> &p_preset) const {80Error err = OK;81Ref<Image> icon;82icon.instantiate();83const String icon_path = String(get_project_setting(p_preset, "application/config/icon")).strip_edges();84if (!icon_path.is_empty()) {85icon = _load_icon_or_splash_image(icon_path, &err);86}87if (icon_path.is_empty() || err != OK || icon.is_null() || icon->is_empty()) {88return EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("DefaultProjectIcon"), EditorStringName(EditorIcons))->get_image();89}90return icon;91}9293Ref<Image> _get_project_splash(const Ref<EditorExportPreset> &p_preset) const {94Error err = OK;95Ref<Image> splash;96splash.instantiate();97const String splash_path = String(get_project_setting(p_preset, "application/boot_splash/image")).strip_edges();98if (!splash_path.is_empty()) {99splash = _load_icon_or_splash_image(splash_path, &err);100}101if (splash_path.is_empty() || err != OK || splash.is_null() || splash->is_empty()) {102return Ref<Image>(memnew(Image(boot_splash_png)));103}104return splash;105}106107Error _extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa);108void _replace_strings(const HashMap<String, String> &p_replaces, Vector<uint8_t> &r_template);109void _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);110Error _add_manifest_icon(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_icon, int p_size, Array &r_arr);111Error _build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects);112Error _write_or_error(const uint8_t *p_content, int p_len, String p_path);113114Error _export_project(const Ref<EditorExportPreset> &p_preset, int p_debug_flags);115Error _launch_browser(const String &p_bind_host, uint16_t p_bind_port, bool p_use_tls);116Error _start_server(const String &p_bind_host, uint16_t p_bind_port, bool p_use_tls);117Error _stop_server();118119public:120virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const override;121122virtual void get_export_options(List<ExportOption> *r_options) const override;123virtual bool get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const override;124125virtual String get_name() const override;126virtual String get_os_name() const override;127virtual Ref<Texture2D> get_logo() const override;128129virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug = false) const override;130virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;131virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;132virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags = 0) override;133134virtual bool poll_export() override;135virtual int get_options_count() const override;136virtual String get_option_label(int p_index) const override;137virtual String get_option_tooltip(int p_index) const override;138virtual Ref<Texture2D> get_option_icon(int p_index) const override;139virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_option, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) override;140virtual Ref<Texture2D> get_run_icon() const override;141142virtual void get_platform_features(List<String> *r_features) const override {143r_features->push_back("web");144r_features->push_back(get_os_name().to_lower());145}146147virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, HashSet<String> &p_features) override {148}149150String get_debug_protocol() const override { return "ws://"; }151152virtual void initialize() override;153~EditorExportPlatformWeb();154};155156157