Skip to content

Commit

Permalink
include amulet.wasm in web editor exports
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmaclarty committed Jul 16, 2018
1 parent 96f5402 commit 82b28d1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions html/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,21 @@ function load_text(url, cb) {
};
}

function load_arraybuffer(url, cb) {
var oReq = new XMLHttpRequest();
oReq.open("GET", url, true);
oReq.responseType = "arraybuffer";
oReq.send();

oReq.onload = function(oEvent) {
var arrayBuffer = oReq.response;
cb(arrayBuffer);
};
}

function all_loaded(files) {
return files["amulet.js"] &&
files["amulet.wasm"] &&
files["amulet_license.txt"] &&
files["player.html"];
}
Expand All @@ -28,6 +41,16 @@ function load_text_file(file, files, on_all_loaded) {
});
}

function load_bin_file(file, files, on_all_loaded) {
load_arraybuffer(file, function(ab) {
console.log("loaded " + file);
files[file] = ab;
if (all_loaded(files)) {
on_all_loaded(files);
}
});
}

function export_game(name, code) {
log_output("Generating export...", "info");
var files = {};
Expand All @@ -39,6 +62,7 @@ function export_game(name, code) {
var download_zip = new JSZip();
download_zip.file("data.pak", data_base64, {base64: true});
download_zip.file("amulet.js", files["amulet.js"]);
download_zip.file("amulet.wasm", files["amulet.wasm"]);
download_zip.file("amulet_license.txt", files["amulet_license.txt"]);
download_zip.file("index.html", files["player.html"]);
var content = download_zip.generate({type:"blob"});
Expand All @@ -51,6 +75,7 @@ function export_game(name, code) {
log_output("For a native standalone build, see the documentation at <http://www.amulet.xyz>.");
}
load_text_file("amulet.js", files, create_export);
load_bin_file("amulet.wasm", files, create_export);
load_text_file("amulet_license.txt", files, create_export);
load_text_file("player.html", files, create_export);
}

0 comments on commit 82b28d1

Please sign in to comment.