summaryrefslogtreecommitdiff
path: root/platform/javascript/engine/engine.js
diff options
context:
space:
mode:
Diffstat (limited to 'platform/javascript/engine/engine.js')
-rw-r--r--platform/javascript/engine/engine.js36
1 files changed, 26 insertions, 10 deletions
diff --git a/platform/javascript/engine/engine.js b/platform/javascript/engine/engine.js
index d709422abb..05a11701c0 100644
--- a/platform/javascript/engine/engine.js
+++ b/platform/javascript/engine/engine.js
@@ -33,6 +33,7 @@ Function('return this')()['Engine'] = (function() {
this.resizeCanvasOnStart = false;
this.onExecute = null;
this.onExit = null;
+ this.persistentPaths = [];
};
Engine.prototype.init = /** @param {string=} basePath */ function(basePath) {
@@ -56,12 +57,14 @@ Function('return this')()['Engine'] = (function() {
config['locateFile'] = Utils.createLocateRewrite(loadPath);
config['instantiateWasm'] = Utils.createInstantiatePromise(loadPromise);
Godot(config).then(function(module) {
- me.rtenv = module;
- if (unloadAfterInit) {
- unload();
- }
- resolve();
- config = null;
+ module['initFS'](me.persistentPaths).then(function(fs_err) {
+ me.rtenv = module;
+ if (unloadAfterInit) {
+ unload();
+ }
+ resolve();
+ config = null;
+ });
});
});
return initPromise;
@@ -118,10 +121,11 @@ Function('return this')()['Engine'] = (function() {
me.rtenv['noExitRuntime'] = true;
me.rtenv['onExecute'] = me.onExecute;
me.rtenv['onExit'] = function(code) {
+ me.rtenv['deinitFS']();
if (me.onExit)
me.onExit(code);
me.rtenv = null;
- }
+ };
return new Promise(function(resolve, reject) {
preloader.preloadedFiles.forEach(function(file) {
me.rtenv['copyToFS'](file.path, file.buffer);
@@ -207,18 +211,28 @@ Function('return this')()['Engine'] = (function() {
if (this.rtenv)
this.rtenv.onExecute = onExecute;
this.onExecute = onExecute;
- }
+ };
Engine.prototype.setOnExit = function(onExit) {
this.onExit = onExit;
- }
+ };
Engine.prototype.copyToFS = function(path, buffer) {
if (this.rtenv == null) {
throw new Error("Engine must be inited before copying files");
}
this.rtenv['copyToFS'](path, buffer);
- }
+ };
+
+ Engine.prototype.setPersistentPaths = function(persistentPaths) {
+ this.persistentPaths = persistentPaths;
+ };
+
+ Engine.prototype.requestQuit = function() {
+ if (this.rtenv) {
+ this.rtenv['request_quit']();
+ }
+ };
// Closure compiler exported engine methods.
/** @export */
@@ -241,5 +255,7 @@ Function('return this')()['Engine'] = (function() {
Engine.prototype['setOnExecute'] = Engine.prototype.setOnExecute;
Engine.prototype['setOnExit'] = Engine.prototype.setOnExit;
Engine.prototype['copyToFS'] = Engine.prototype.copyToFS;
+ Engine.prototype['setPersistentPaths'] = Engine.prototype.setPersistentPaths;
+ Engine.prototype['requestQuit'] = Engine.prototype.requestQuit;
return Engine;
})();