2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* export.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2018-01-01 14:40:08 +01:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2017-03-05 14:21:25 +01:00
|
|
|
#include "editor/editor_node.h"
|
2017-03-28 03:21:21 +02:00
|
|
|
#include "editor_export.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "io/zip_io.h"
|
2017-11-20 00:06:11 +01:00
|
|
|
#include "main/splash.gen.h"
|
2017-06-23 17:03:41 +02:00
|
|
|
#include "platform/javascript/logo.gen.h"
|
2017-05-25 20:57:13 +02:00
|
|
|
#include "platform/javascript/run_icon.gen.h"
|
2017-01-26 01:55:59 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
#define EXPORT_TEMPLATE_WEBASSEMBLY_RELEASE "webassembly_release.zip"
|
|
|
|
#define EXPORT_TEMPLATE_WEBASSEMBLY_DEBUG "webassembly_debug.zip"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
class EditorExportPlatformJavaScript : public EditorExportPlatform {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
GDCLASS(EditorExportPlatformJavaScript, EditorExportPlatform)
|
2016-01-20 03:21:29 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Ref<ImageTexture> logo;
|
2017-05-25 20:57:13 +02:00
|
|
|
Ref<ImageTexture> run_icon;
|
2017-06-27 03:13:36 +02:00
|
|
|
bool runnable_when_last_polled;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
void _fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
public:
|
2017-03-28 03:21:21 +02:00
|
|
|
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
virtual void get_export_options(List<ExportOption> *r_options);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
virtual String get_name() const;
|
2017-07-19 22:00:46 +02:00
|
|
|
virtual String get_os_name() const;
|
2017-03-28 03:21:21 +02:00
|
|
|
virtual Ref<Texture> get_logo() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
|
2017-12-12 22:09:48 +01:00
|
|
|
virtual String get_binary_extension(const Ref<EditorExportPreset> &p_preset) const;
|
2017-03-28 03:21:21 +02:00
|
|
|
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-27 03:13:36 +02:00
|
|
|
virtual bool poll_devices();
|
|
|
|
virtual int get_device_count() const;
|
2017-03-28 03:21:21 +02:00
|
|
|
virtual String get_device_name(int p_device) const { return TTR("Run in Browser"); }
|
|
|
|
virtual String get_device_info(int p_device) const { return TTR("Run exported HTML in the system's default browser."); }
|
|
|
|
virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags);
|
2017-05-25 20:57:13 +02:00
|
|
|
virtual Ref<Texture> get_run_icon() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
virtual void get_platform_features(List<String> *r_features) {
|
|
|
|
|
|
|
|
r_features->push_back("web");
|
2018-01-12 00:15:21 +01:00
|
|
|
r_features->push_back(get_os_name());
|
2017-07-19 22:00:46 +02:00
|
|
|
}
|
|
|
|
|
2018-08-22 04:56:04 +02:00
|
|
|
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) {
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
EditorExportPlatformJavaScript();
|
|
|
|
};
|
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
String str_template = String::utf8(reinterpret_cast<const char *>(p_html.ptr()), p_html.size());
|
|
|
|
String str_export;
|
|
|
|
Vector<String> lines = str_template.split("\n");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
for (int i = 0; i < lines.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
String current_line = lines[i];
|
2017-08-13 13:10:04 +02:00
|
|
|
current_line = current_line.replace("$GODOT_BASENAME", p_name);
|
2017-03-28 03:21:21 +02:00
|
|
|
current_line = current_line.replace("$GODOT_HEAD_INCLUDE", p_preset->get("html/head_include"));
|
|
|
|
current_line = current_line.replace("$GODOT_DEBUG_ENABLED", p_debug ? "true" : "false");
|
|
|
|
str_export += current_line + "\n";
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
CharString cs = str_export.utf8();
|
|
|
|
p_html.resize(cs.length());
|
|
|
|
for (int i = 0; i < cs.length(); i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
p_html.write[i] = cs[i];
|
2017-03-28 03:21:21 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
void EditorExportPlatformJavaScript::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
|
2015-09-10 05:10:54 +02:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
if (p_preset->get("texture_format/s3tc")) {
|
|
|
|
r_features->push_back("s3tc");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-28 03:21:21 +02:00
|
|
|
if (p_preset->get("texture_format/etc")) {
|
|
|
|
r_features->push_back("etc");
|
|
|
|
}
|
|
|
|
if (p_preset->get("texture_format/etc2")) {
|
|
|
|
r_features->push_back("etc2");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
void EditorExportPlatformJavaScript::get_export_options(List<ExportOption> *r_options) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-01-20 13:41:19 +01:00
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true));
|
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
|
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), true));
|
2018-08-23 21:45:48 +02:00
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/custom_html_shell", PROPERTY_HINT_FILE, "*.html"), ""));
|
2017-03-28 03:21:21 +02:00
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/head_include", PROPERTY_HINT_MULTILINE_TEXT), ""));
|
2018-08-23 21:45:48 +02:00
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
|
|
|
|
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
|
2017-03-28 03:21:21 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
String EditorExportPlatformJavaScript::get_name() const {
|
|
|
|
|
|
|
|
return "HTML5";
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
String EditorExportPlatformJavaScript::get_os_name() const {
|
|
|
|
|
2018-01-12 00:15:21 +01:00
|
|
|
return "HTML5";
|
2017-07-19 22:00:46 +02:00
|
|
|
}
|
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
Ref<Texture> EditorExportPlatformJavaScript::get_logo() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
return logo;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
bool EditorExportPlatformJavaScript::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-08-20 17:35:33 +02:00
|
|
|
bool valid = false;
|
|
|
|
String err;
|
|
|
|
|
|
|
|
if (find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_RELEASE) != "")
|
|
|
|
valid = true;
|
|
|
|
else if (find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_DEBUG) != "")
|
|
|
|
valid = true;
|
|
|
|
|
|
|
|
if (p_preset->get("custom_template/debug") != "") {
|
|
|
|
if (FileAccess::exists(p_preset->get("custom_template/debug"))) {
|
|
|
|
valid = true;
|
|
|
|
} else {
|
|
|
|
err += "Custom debug template not found.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_preset->get("custom_template/release") != "") {
|
|
|
|
if (FileAccess::exists(p_preset->get("custom_template/release"))) {
|
|
|
|
valid = true;
|
|
|
|
} else {
|
|
|
|
err += "Custom release template not found.\n";
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-08-20 17:35:33 +02:00
|
|
|
if (!err.empty())
|
|
|
|
r_error = err;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-08-20 17:35:33 +02:00
|
|
|
r_missing_templates = !valid;
|
|
|
|
return valid;
|
2017-03-28 03:21:21 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-12 22:09:48 +01:00
|
|
|
String EditorExportPlatformJavaScript::get_binary_extension(const Ref<EditorExportPreset> &p_preset) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
return "html";
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
2017-10-02 17:01:43 +02:00
|
|
|
ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
String custom_debug = p_preset->get("custom_template/debug");
|
|
|
|
String custom_release = p_preset->get("custom_template/release");
|
2017-11-20 00:06:11 +01:00
|
|
|
String custom_html = p_preset->get("html/custom_html_shell");
|
2017-03-28 03:21:21 +02:00
|
|
|
|
|
|
|
String template_path = p_debug ? custom_debug : custom_release;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
template_path = template_path.strip_edges();
|
|
|
|
|
|
|
|
if (template_path == String()) {
|
|
|
|
|
2017-11-18 05:50:26 +01:00
|
|
|
if (p_debug)
|
|
|
|
template_path = find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_DEBUG);
|
|
|
|
else
|
|
|
|
template_path = find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_RELEASE);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
if (template_path != String() && !FileAccess::exists(template_path)) {
|
2018-01-04 16:08:24 +01:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Template file not found:") + "\n" + template_path);
|
2017-03-28 03:21:21 +02:00
|
|
|
return ERR_FILE_NOT_FOUND;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
String pck_path = p_path.get_basename() + ".pck";
|
|
|
|
Error error = save_pack(p_preset, pck_path);
|
|
|
|
if (error != OK) {
|
2018-01-04 16:08:24 +01:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + pck_path);
|
2017-03-28 03:21:21 +02:00
|
|
|
return error;
|
|
|
|
}
|
2014-02-13 22:03:28 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
FileAccess *src_f = NULL;
|
|
|
|
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
|
|
|
|
unzFile pkg = unzOpen2(template_path.utf8().get_data(), &io);
|
2014-02-13 22:03:28 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!pkg) {
|
|
|
|
|
2018-01-04 16:08:24 +01:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Could not open template for export:") + "\n" + template_path);
|
2014-02-10 02:10:30 +01:00
|
|
|
return ERR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2017-11-20 00:06:11 +01:00
|
|
|
if (unzGoToFirstFile(pkg) != UNZ_OK) {
|
2018-01-04 16:08:24 +01:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Invalid export template:") + "\n" + template_path);
|
2017-11-20 00:06:11 +01:00
|
|
|
unzClose(pkg);
|
|
|
|
return ERR_FILE_CORRUPT;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-11-20 00:06:11 +01:00
|
|
|
do {
|
2014-02-10 02:10:30 +01:00
|
|
|
//get filename
|
|
|
|
unz_file_info info;
|
|
|
|
char fname[16384];
|
2017-11-20 00:06:11 +01:00
|
|
|
unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
String file = fname;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Vector<uint8_t> data;
|
|
|
|
data.resize(info.uncompressed_size);
|
|
|
|
|
|
|
|
//read
|
|
|
|
unzOpenCurrentFile(pkg);
|
2017-11-25 04:07:54 +01:00
|
|
|
unzReadCurrentFile(pkg, data.ptrw(), data.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
unzCloseCurrentFile(pkg);
|
|
|
|
|
|
|
|
//write
|
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
if (file == "godot.html") {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-11-20 00:06:11 +01:00
|
|
|
if (!custom_html.empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-03-28 03:21:21 +02:00
|
|
|
_fix_html(data, p_preset, p_path.get_file().get_basename(), p_debug);
|
|
|
|
file = p_path.get_file();
|
2017-11-20 00:06:11 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
} else if (file == "godot.js") {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
file = p_path.get_file().get_basename() + ".js";
|
|
|
|
} else if (file == "godot.wasm") {
|
2016-11-30 22:47:19 +01:00
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
file = p_path.get_file().get_basename() + ".wasm";
|
2016-10-30 23:10:17 +01:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String dst = p_path.get_base_dir().plus_file(file);
|
2017-03-28 03:21:21 +02:00
|
|
|
FileAccess *f = FileAccess::open(dst, FileAccess::WRITE);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!f) {
|
2018-01-04 16:08:24 +01:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + dst);
|
2014-02-10 02:10:30 +01:00
|
|
|
unzClose(pkg);
|
|
|
|
return ERR_FILE_CANT_WRITE;
|
|
|
|
}
|
2017-03-28 03:21:21 +02:00
|
|
|
f->store_buffer(data.ptr(), data.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
memdelete(f);
|
|
|
|
|
2017-11-20 00:06:11 +01:00
|
|
|
} while (unzGoToNextFile(pkg) == UNZ_OK);
|
|
|
|
unzClose(pkg);
|
|
|
|
|
|
|
|
if (!custom_html.empty()) {
|
|
|
|
|
|
|
|
FileAccess *f = FileAccess::open(custom_html, FileAccess::READ);
|
|
|
|
if (!f) {
|
2018-01-04 16:08:24 +01:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Could not read custom HTML shell:") + "\n" + custom_html);
|
2017-11-20 00:06:11 +01:00
|
|
|
return ERR_FILE_CANT_READ;
|
|
|
|
}
|
|
|
|
Vector<uint8_t> buf;
|
|
|
|
buf.resize(f->get_len());
|
2017-11-25 04:07:54 +01:00
|
|
|
f->get_buffer(buf.ptrw(), buf.size());
|
2017-11-20 00:06:11 +01:00
|
|
|
memdelete(f);
|
|
|
|
_fix_html(buf, p_preset, p_path.get_file().get_basename(), p_debug);
|
|
|
|
|
|
|
|
f = FileAccess::open(p_path, FileAccess::WRITE);
|
|
|
|
if (!f) {
|
2018-01-04 16:08:24 +01:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + p_path);
|
2017-11-20 00:06:11 +01:00
|
|
|
return ERR_FILE_CANT_WRITE;
|
|
|
|
}
|
|
|
|
f->store_buffer(buf.ptr(), buf.size());
|
|
|
|
memdelete(f);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-11-20 00:06:11 +01:00
|
|
|
Ref<Image> splash;
|
|
|
|
String splash_path = GLOBAL_GET("application/boot_splash/image");
|
|
|
|
splash_path = splash_path.strip_edges();
|
|
|
|
if (!splash_path.empty()) {
|
|
|
|
splash.instance();
|
|
|
|
Error err = splash->load(splash_path);
|
|
|
|
if (err) {
|
2018-01-04 17:31:35 +01:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Could not read boot splash image file:") + "\n" + splash_path + "\n" + TTR("Using default boot splash image."));
|
2017-11-20 00:06:11 +01:00
|
|
|
splash.unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (splash.is_null()) {
|
|
|
|
splash = Ref<Image>(memnew(Image(boot_splash_png)));
|
|
|
|
}
|
|
|
|
String png_path = p_path.get_base_dir().plus_file(p_path.get_file().get_basename() + ".png");
|
|
|
|
if (splash->save_png(png_path) != OK) {
|
2018-01-04 16:08:24 +01:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + png_path);
|
2017-11-20 00:06:11 +01:00
|
|
|
return ERR_FILE_CANT_WRITE;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-06-27 03:13:36 +02:00
|
|
|
bool EditorExportPlatformJavaScript::poll_devices() {
|
|
|
|
|
|
|
|
Ref<EditorExportPreset> preset;
|
|
|
|
|
|
|
|
for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
|
|
|
|
|
|
|
|
Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
|
|
|
|
if (ep->is_runnable() && ep->get_platform() == this) {
|
|
|
|
preset = ep;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool prev = runnable_when_last_polled;
|
|
|
|
runnable_when_last_polled = preset.is_valid();
|
|
|
|
return runnable_when_last_polled != prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
int EditorExportPlatformJavaScript::get_device_count() const {
|
|
|
|
|
|
|
|
return runnable_when_last_polled;
|
|
|
|
}
|
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-11-17 21:48:24 +01:00
|
|
|
String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_export.html");
|
2017-03-28 03:21:21 +02:00
|
|
|
Error err = export_project(p_preset, true, path, p_debug_flags);
|
|
|
|
if (err) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return err;
|
2017-03-28 03:21:21 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
OS::get_singleton()->shell_open(path);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-05-25 20:57:13 +02:00
|
|
|
Ref<Texture> EditorExportPlatformJavaScript::get_run_icon() const {
|
|
|
|
|
|
|
|
return run_icon;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() {
|
|
|
|
|
2017-05-17 12:36:47 +02:00
|
|
|
Ref<Image> img = memnew(Image(_javascript_logo));
|
2017-03-28 03:21:21 +02:00
|
|
|
logo.instance();
|
2014-02-10 02:10:30 +01:00
|
|
|
logo->create_from_image(img);
|
2017-05-25 20:57:13 +02:00
|
|
|
|
|
|
|
img = Ref<Image>(memnew(Image(_javascript_run_icon)));
|
|
|
|
run_icon.instance();
|
|
|
|
run_icon->create_from_image(img);
|
2017-06-27 03:13:36 +02:00
|
|
|
|
|
|
|
runnable_when_last_polled = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void register_javascript_exporter() {
|
|
|
|
|
2017-03-28 03:21:21 +02:00
|
|
|
Ref<EditorExportPlatformJavaScript> platform;
|
|
|
|
platform.instance();
|
|
|
|
EditorExport::get_singleton()->add_export_platform(platform);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|