From 32eb3e1b7d2aa6010f154d8b4850357f5a11662a Mon Sep 17 00:00:00 2001 From: Leon Krause Date: Thu, 10 May 2018 13:30:29 +0200 Subject: [PATCH 1/2] Add Engine.setWebAssemblyFilenameExtension() Some web game hosts only allow certain filename extensions. If .wasm is not allowed, this function allows overriding the WebAssembly filename extension to work around that restriction. --- platform/javascript/engine.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/platform/javascript/engine.js b/platform/javascript/engine.js index e4839af4335..0c1337cc3ba 100644 --- a/platform/javascript/engine.js +++ b/platform/javascript/engine.js @@ -10,6 +10,7 @@ var DOWNLOAD_ATTEMPTS_MAX = 4; var basePath = null; + var wasmFilenameExtensionOverride = null; var engineLoadPromise = null; var loadingFiles = {}; @@ -299,6 +300,14 @@ return !!testContext; }; + Engine.setWebAssemblyFilenameExtension = function(override) { + + if (String(override).length === 0) { + throw new Error('Invalid WebAssembly filename extension override'); + } + wasmFilenameExtensionOverride = String(override); + } + Engine.load = function(newBasePath) { if (newBasePath !== undefined) basePath = getBasePath(newBasePath); @@ -306,7 +315,7 @@ if (typeof WebAssembly !== 'object') return Promise.reject(new Error("Browser doesn't support WebAssembly")); // TODO cache/retrieve module to/from idb - engineLoadPromise = loadPromise(basePath + '.wasm').then(function(xhr) { + engineLoadPromise = loadPromise(basePath + '.' + (wasmFilenameExtensionOverride || 'wasm')).then(function(xhr) { return xhr.response; }); engineLoadPromise = engineLoadPromise.catch(function(err) { From 96f907c023b687206df6233be383d724e2810088 Mon Sep 17 00:00:00 2001 From: Leon Krause Date: Thu, 10 May 2018 13:43:58 +0200 Subject: [PATCH 2/2] Accept non-default main packs in engine.js startGame() Allows using startGame() with main packs exported as .zip, but also any other custom extension, for example if a web game host does not allow the .pck filename extension. --- misc/dist/html/default.html | 4 ++-- platform/javascript/engine.js | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/misc/dist/html/default.html b/misc/dist/html/default.html index 4e3515a7b65..9aef77b1d20 100644 --- a/misc/dist/html/default.html +++ b/misc/dist/html/default.html @@ -229,7 +229,7 @@ $GODOT_HEAD_INCLUDE (function() { - const BASENAME = '$GODOT_BASENAME'; + const MAIN_PACK = '$GODOT_BASENAME.pck'; const DEBUG_ENABLED = $GODOT_DEBUG_ENABLED; const INDETERMINATE_STATUS_STEP_MS = 100; @@ -380,7 +380,7 @@ $GODOT_HEAD_INCLUDE } else { setStatusMode('indeterminate'); engine.setCanvas(canvas); - engine.startGame(BASENAME + '.pck').then(() => { + engine.startGame(MAIN_PACK).then(() => { setStatusMode('hidden'); initializing = false; }, displayFailureNotice); diff --git a/platform/javascript/engine.js b/platform/javascript/engine.js index 0c1337cc3ba..1d78f28bb68 100644 --- a/platform/javascript/engine.js +++ b/platform/javascript/engine.js @@ -130,13 +130,17 @@ this.startGame = function(mainPack) { executableName = getBaseName(mainPack); + var mainArgs = []; + if (!getPathLeaf(mainPack).endsWith('.pck')) { + mainArgs = ['--main-pack', getPathLeaf(mainPack)]; + } return Promise.all([ // Load from directory, this.init(getBasePath(mainPack)), // ...but write to root where the engine expects it. this.preloadFile(mainPack, getPathLeaf(mainPack)) ]).then( - Function.prototype.apply.bind(synchronousStart, this, []) + Function.prototype.apply.bind(synchronousStart, this, mainArgs) ); };