summaryrefslogtreecommitdiff
path: root/platform/javascript/engine/loader.js
diff options
context:
space:
mode:
Diffstat (limited to 'platform/javascript/engine/loader.js')
-rw-r--r--platform/javascript/engine/loader.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/platform/javascript/engine/loader.js b/platform/javascript/engine/loader.js
new file mode 100644
index 0000000000..d27fbf612e
--- /dev/null
+++ b/platform/javascript/engine/loader.js
@@ -0,0 +1,33 @@
+var Loader = /** @constructor */ function() {
+
+ this.env = null;
+
+ this.init = function(loadPromise, basePath, config) {
+ var me = this;
+ return new Promise(function(resolve, reject) {
+ var cfg = config || {};
+ cfg['locateFile'] = Utils.createLocateRewrite(basePath);
+ cfg['instantiateWasm'] = Utils.createInstantiatePromise(loadPromise);
+ loadPromise = null;
+ Godot(cfg).then(function(module) {
+ me.env = module;
+ resolve();
+ });
+ });
+ }
+
+ this.start = function(preloadedFiles, args) {
+ var me = this;
+ return new Promise(function(resolve, reject) {
+ if (!me.env) {
+ reject(new Error('The engine must be initialized before it can be started'));
+ }
+ preloadedFiles.forEach(function(file) {
+ Utils.copyToFS(me.env['FS'], file.path, file.buffer);
+ });
+ preloadedFiles.length = 0; // Clear memory
+ me.env['callMain'](args);
+ resolve();
+ });
+ }
+};