Merge pull request #18765 from eska014/enginejs-extalt
Facilitate using non-default filename extensions in HTML5 platform
This commit is contained in:
commit
a415efa4b7
2 changed files with 17 additions and 4 deletions
4
misc/dist/html/default.html
vendored
4
misc/dist/html/default.html
vendored
|
@ -229,7 +229,7 @@ $GODOT_HEAD_INCLUDE
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
const BASENAME = '$GODOT_BASENAME';
|
const MAIN_PACK = '$GODOT_BASENAME.pck';
|
||||||
const DEBUG_ENABLED = $GODOT_DEBUG_ENABLED;
|
const DEBUG_ENABLED = $GODOT_DEBUG_ENABLED;
|
||||||
const INDETERMINATE_STATUS_STEP_MS = 100;
|
const INDETERMINATE_STATUS_STEP_MS = 100;
|
||||||
|
|
||||||
|
@ -380,7 +380,7 @@ $GODOT_HEAD_INCLUDE
|
||||||
} else {
|
} else {
|
||||||
setStatusMode('indeterminate');
|
setStatusMode('indeterminate');
|
||||||
engine.setCanvas(canvas);
|
engine.setCanvas(canvas);
|
||||||
engine.startGame(BASENAME + '.pck').then(() => {
|
engine.startGame(MAIN_PACK).then(() => {
|
||||||
setStatusMode('hidden');
|
setStatusMode('hidden');
|
||||||
initializing = false;
|
initializing = false;
|
||||||
}, displayFailureNotice);
|
}, displayFailureNotice);
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
var DOWNLOAD_ATTEMPTS_MAX = 4;
|
var DOWNLOAD_ATTEMPTS_MAX = 4;
|
||||||
|
|
||||||
var basePath = null;
|
var basePath = null;
|
||||||
|
var wasmFilenameExtensionOverride = null;
|
||||||
var engineLoadPromise = null;
|
var engineLoadPromise = null;
|
||||||
|
|
||||||
var loadingFiles = {};
|
var loadingFiles = {};
|
||||||
|
@ -129,13 +130,17 @@
|
||||||
this.startGame = function(mainPack) {
|
this.startGame = function(mainPack) {
|
||||||
|
|
||||||
executableName = getBaseName(mainPack);
|
executableName = getBaseName(mainPack);
|
||||||
|
var mainArgs = [];
|
||||||
|
if (!getPathLeaf(mainPack).endsWith('.pck')) {
|
||||||
|
mainArgs = ['--main-pack', getPathLeaf(mainPack)];
|
||||||
|
}
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
// Load from directory,
|
// Load from directory,
|
||||||
this.init(getBasePath(mainPack)),
|
this.init(getBasePath(mainPack)),
|
||||||
// ...but write to root where the engine expects it.
|
// ...but write to root where the engine expects it.
|
||||||
this.preloadFile(mainPack, getPathLeaf(mainPack))
|
this.preloadFile(mainPack, getPathLeaf(mainPack))
|
||||||
]).then(
|
]).then(
|
||||||
Function.prototype.apply.bind(synchronousStart, this, [])
|
Function.prototype.apply.bind(synchronousStart, this, mainArgs)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -303,6 +308,14 @@
|
||||||
return !!testContext;
|
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) {
|
Engine.load = function(newBasePath) {
|
||||||
|
|
||||||
if (newBasePath !== undefined) basePath = getBasePath(newBasePath);
|
if (newBasePath !== undefined) basePath = getBasePath(newBasePath);
|
||||||
|
@ -310,7 +323,7 @@
|
||||||
if (typeof WebAssembly !== 'object')
|
if (typeof WebAssembly !== 'object')
|
||||||
return Promise.reject(new Error("Browser doesn't support WebAssembly"));
|
return Promise.reject(new Error("Browser doesn't support WebAssembly"));
|
||||||
// TODO cache/retrieve module to/from idb
|
// 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;
|
return xhr.response;
|
||||||
});
|
});
|
||||||
engineLoadPromise = engineLoadPromise.catch(function(err) {
|
engineLoadPromise = engineLoadPromise.catch(function(err) {
|
||||||
|
|
Loading…
Reference in a new issue