1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

Fix Closure compiler build, python style.

Move copyToFS into utils.js library included with '--pre-js'.
This commit is contained in:
Fabio Alessandrelli
2020-05-08 16:55:01 +02:00
parent 7411e7fd37
commit d2eef39731
11 changed files with 79 additions and 50 deletions

View File

@@ -82,7 +82,7 @@ Function('return this')()['Engine'] = (function() {
var me = this;
return me.init().then(function() {
if (!me.rtenv) {
reject(new Error('The engine must be initialized before it can be started'));
return Promise.reject(new Error('The engine must be initialized before it can be started'));
}
if (!(me.canvas instanceof HTMLCanvasElement)) {
@@ -124,7 +124,7 @@ Function('return this')()['Engine'] = (function() {
}
return new Promise(function(resolve, reject) {
preloader.preloadedFiles.forEach(function(file) {
Utils.copyToFS(me.rtenv['FS'], file.path, file.buffer);
me.rtenv['copyToFS'](file.path, file.buffer);
});
preloader.preloadedFiles.length = 0; // Clear memory
me.rtenv['callMain'](args);
@@ -217,7 +217,7 @@ Function('return this')()['Engine'] = (function() {
if (this.rtenv == null) {
throw new Error("Engine must be inited before copying files");
}
Utils.copyToFS(this.rtenv['FS'], path, buffer);
this.rtenv['copyToFS'](path, buffer);
}
// Closure compiler exported engine methods.

View File

@@ -27,24 +27,6 @@ var Utils = {
return instantiateWasm;
},
copyToFS: function(fs, path, buffer) {
var p = path.lastIndexOf("/");
var dir = "/";
if (p > 0) {
dir = path.slice(0, path.lastIndexOf("/"));
}
try {
fs.stat(dir);
} catch (e) {
if (e.errno !== 44) { // 'ENOENT', see https://github.com/emscripten-core/emscripten/blob/master/system/lib/libc/musl/arch/emscripten/bits/errno.h
throw e;
}
fs['mkdirTree'](dir);
}
// With memory growth, canOwn should be false.
fs['writeFile'](path, new Uint8Array(buffer), {'flags': 'wx+'});
},
findCanvas: function() {
var nodes = document.getElementsByTagName('canvas');
if (nodes.length && nodes[0] instanceof HTMLCanvasElement) {