From d3ffc8ad0c12e5c31d9443f566ec185d95773dd9 Mon Sep 17 00:00:00 2001 From: Leon Krause Date: Tue, 27 Mar 2018 11:25:03 +0200 Subject: [PATCH] Fix engine.js startGame() when loading from directory (cherry picked from commit 3014e48ec5a985b9d143ba27b91e32b933dcfdad) --- platform/javascript/engine.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/platform/javascript/engine.js b/platform/javascript/engine.js index dab7104af81..06ff96bc307 100644 --- a/platform/javascript/engine.js +++ b/platform/javascript/engine.js @@ -14,6 +14,13 @@ var loadingFiles = {}; + function getPathLeaf(path) { + + while (path.endsWith('/')) + path = path.slice(0, -1); + return path.slice(path.lastIndexOf('/') + 1); + } + function getBasePath(path) { if (path.endsWith('/')) @@ -25,8 +32,7 @@ function getBaseName(path) { - path = getBasePath(path); - return path.slice(path.lastIndexOf('/') + 1); + return getPathLeaf(getBasePath(path)); } Engine = function Engine() { @@ -123,7 +129,12 @@ this.startGame = function(mainPack) { executableName = getBaseName(mainPack); - return Promise.all([this.init(getBasePath(mainPack)), this.preloadFile(mainPack)]).then( + 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, []) ); };