[HTML5] Port JavaScript inline code to libraries.

The API is implemented in javascript, and generates C functions that can
be called from godot.
This allows much cleaner code replacing all `EM_ASM` calls in our C++
code with plain C function calls.
This also gets rid of few hacks and comes with few optimizations (e.g.
custom cursor shapes should be much faster now).
This commit is contained in:
Fabio Alessandrelli 2020-10-23 18:33:20 +02:00
parent 54cda5c3b8
commit e2083871eb
33 changed files with 1995 additions and 1461 deletions

View file

@ -39,6 +39,11 @@
#include <emscripten/emscripten.h>
// JavaScript functions defined in library_godot_editor_tools.js
extern "C" {
extern void godot_js_editor_download_file(const char *p_path, const char *p_name, const char *p_mime);
}
static void _javascript_editor_init_callback() {
EditorNode::get_singleton()->add_editor_plugin(memnew(JavaScriptToolsEditorPlugin(EditorNode::get_singleton())));
}
@ -65,25 +70,7 @@ void JavaScriptToolsEditorPlugin::_download_zip(Variant p_v) {
String base_path = resource_path.substr(0, resource_path.rfind("/")) + "/";
_zip_recursive(resource_path, base_path, zip);
zipClose(zip, NULL);
EM_ASM({
const path = "/tmp/project.zip";
const size = FS.stat(path)["size"];
const buf = new Uint8Array(size);
const fd = FS.open(path, "r");
FS.read(fd, buf, 0, size);
FS.close(fd);
FS.unlink(path);
const blob = new Blob([buf], { type: "application/zip" });
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "project.zip";
a.style.display = "none";
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
});
godot_js_editor_download_file("/tmp/project.zip", "project.zip", "application/zip");
}
void JavaScriptToolsEditorPlugin::_bind_methods() {