mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 16:33:30 +00:00
[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:
parent
a7ecb3c048
commit
e52ed6d89e
31 changed files with 2016 additions and 1502 deletions
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue