Path: blob/master/platform/web/export/export_plugin.h
10278 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 EditorExportPlatformWeb : public EditorExportPlatform {45GDCLASS(EditorExportPlatformWeb, EditorExportPlatform);4647enum RemoteDebugState {48REMOTE_DEBUG_STATE_UNAVAILABLE,49REMOTE_DEBUG_STATE_AVAILABLE,50REMOTE_DEBUG_STATE_SERVING,51};5253Ref<ImageTexture> logo;54Ref<ImageTexture> run_icon;55Ref<ImageTexture> stop_icon;56Ref<ImageTexture> restart_icon;57RemoteDebugState remote_debug_state = REMOTE_DEBUG_STATE_UNAVAILABLE;5859Ref<EditorHTTPServer> server;6061String _get_template_name(bool p_extension, bool p_thread_support, bool p_debug) const {62String name = "web";63if (p_extension) {64name += "_dlink";65}66if (!p_thread_support) {67name += "_nothreads";68}69if (p_debug) {70name += "_debug.zip";71} else {72name += "_release.zip";73}74return name;75}7677Ref<Image> _get_project_icon(const Ref<EditorExportPreset> &p_preset) const {78Error err = OK;79Ref<Image> icon;80icon.instantiate();81const String icon_path = String(get_project_setting(p_preset, "application/config/icon")).strip_edges();82if (!icon_path.is_empty()) {83icon = _load_icon_or_splash_image(icon_path, &err);84}85if (icon_path.is_empty() || err != OK || icon.is_null() || icon->is_empty()) {86return EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("DefaultProjectIcon"), EditorStringName(EditorIcons))->get_image();87}88return icon;89}9091Ref<Image> _get_project_splash(const Ref<EditorExportPreset> &p_preset) const {92Error err = OK;93Ref<Image> splash;94splash.instantiate();95const String splash_path = String(get_project_setting(p_preset, "application/boot_splash/image")).strip_edges();96if (!splash_path.is_empty()) {97splash = _load_icon_or_splash_image(splash_path, &err);98}99if (splash_path.is_empty() || err != OK || splash.is_null() || splash->is_empty()) {100return Ref<Image>(memnew(Image(boot_splash_png)));101}102return splash;103}104105Error _extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa);106void _replace_strings(const HashMap<String, String> &p_replaces, Vector<uint8_t> &r_template);107void _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);108Error _add_manifest_icon(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_icon, int p_size, Array &r_arr);109Error _build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects);110Error _write_or_error(const uint8_t *p_content, int p_len, String p_path);111112Error _export_project(const Ref<EditorExportPreset> &p_preset, int p_debug_flags);113Error _launch_browser(const String &p_bind_host, uint16_t p_bind_port, bool p_use_tls);114Error _start_server(const String &p_bind_host, uint16_t p_bind_port, bool p_use_tls);115Error _stop_server();116117public:118virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const override;119120virtual void get_export_options(List<ExportOption> *r_options) const override;121virtual bool get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const override;122123virtual String get_name() const override;124virtual String get_os_name() const override;125virtual Ref<Texture2D> get_logo() const override;126127virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug = false) const override;128virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;129virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;130virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags = 0) override;131132virtual bool poll_export() override;133virtual int get_options_count() const override;134virtual String get_option_label(int p_index) const override;135virtual String get_option_tooltip(int p_index) const override;136virtual Ref<Texture2D> get_option_icon(int p_index) const override;137virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_option, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) override;138virtual Ref<Texture2D> get_run_icon() const override;139140virtual void get_platform_features(List<String> *r_features) const override {141r_features->push_back("web");142r_features->push_back(get_os_name().to_lower());143}144145virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, HashSet<String> &p_features) override {146}147148String get_debug_protocol() const override { return "ws://"; }149150EditorExportPlatformWeb();151~EditorExportPlatformWeb();152};153154155