diff --git a/src/emulator.js b/src/emulator.js index 0303761..6859508 100644 --- a/src/emulator.js +++ b/src/emulator.js @@ -94,6 +94,11 @@ class EmulatorJS { downloadFile(path, cb, progressCB, notWithPath, opts) { const basePath = notWithPath ? '' : this.config.dataPath; path = basePath + path; + if (!notWithPath && this.config.filePaths) { + if (typeof this.config.filePaths[path.split('/').pop()] === "string") { + path = this.config.filePaths[path.split('/').pop()]; + } + } let url; try {url=new URL(path)}catch(e){}; if ((url && ['http:', 'https:'].includes(url.protocol)) || !url) { @@ -271,10 +276,17 @@ class EmulatorJS { this.touch = true; }) this.addEventListener(button, "click", this.startButtonClicked.bind(this)); + if (this.config.startOnLoad === true) { + this.startButtonClicked(button); + } } startButtonClicked(e) { - e.preventDefault(); - e.target.remove(); + if (e.preventDefault) { + e.preventDefault(); + e.target.remove(); + } else { + e.remove(); + } this.createText(); this.downloadGameCore(); } @@ -941,6 +953,8 @@ class EmulatorJS { a.click(); }); const loadState = addButton("Load State", '', async () => { + const called = this.callEvent("load"); + if (called > 0) return; const file = await this.selectFile(); const state = new Uint8Array(await file.arrayBuffer()); this.gameManager.loadState(state); diff --git a/src/loader.js b/src/loader.js index 9342d7f..d3c2b68 100644 --- a/src/loader.js +++ b/src/loader.js @@ -1,13 +1,13 @@ (async function() { const folderPath = (path) => path.substring(0, path.length - path.split('/').pop().length); - const scriptPath = folderPath((new URL(document.currentScript.src)).pathname); + const scriptPath = (typeof window.EJS_pathtodata === "string") ? window.EJS_pathtodata : folderPath((new URL(document.currentScript.src)).pathname); if (!scriptPath.endsWith('/')) scriptPath+='/'; //console.log(scriptPath); function loadScript(file) { return new Promise(function (resolve, reject) { let script = document.createElement('script'); script.src = function() { - if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] == 'string') { + if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] === 'string') { return EJS_paths[file]; } else { return scriptPath+file; @@ -22,7 +22,7 @@ let css = document.createElement('link'); css.rel = 'stylesheet'; css.href = function() { - if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] == 'string') { + if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] === 'string') { return EJS_paths[file]; } else { return scriptPath+file; @@ -54,7 +54,9 @@ config.VirtualGamepadSettings = window.EJS_VirtualGamepadSettings; config.buttonOpts = window.EJS_Buttons; config.volume = window.EJS_volume; - config.defaultControllers = window.EJS_defaultControls + config.defaultControllers = window.EJS_defaultControls; + config.startOnLoad = window.EJS_startOnLoaded; + config.filePaths = window.EJS_paths; new EmulatorJS(EJS_player, config);