--- a/data/src/emulator.js +++ b/data/src/emulator.js @@ -204,7 +204,6 @@ this.extensions = []; this.initControlVars(); this.debug = (window.EJS_DEBUG_XX === true); - if (this.debug || (window.location && ["localhost", "127.0.0.1"].includes(location.hostname))) this.checkForUpdates(); this.netplayEnabled = (window.EJS_DEBUG_XX === true) && (window.EJS_EXPERIMENTAL_NETPLAY === true); this.config = config; this.config.buttonOpts = this.buildButtonOptions(this.config.buttonOpts); @@ -601,39 +600,11 @@ let legacy = (this.supportsWebgl2 && this.webgl2Enabled ? "" : "-legacy"); let filename = this.getCore() + (threads ? "-thread" : "") + legacy + "-wasm.data"; - if (!this.debug) { - const result = await this.storage.core.get(filename); - if (result && result.version === rep.buildStart) { - gotCore(result.data); - return; - } - } - const corePath = "cores/" + filename; - let res = await this.downloadFile(corePath, (progress) => { - this.textElem.innerText = this.localization("Download Game Core") + progress; - }, false, { responseType: "arraybuffer", method: "GET" }); - if (res === -1) { - console.log("File not found, attemping to fetch from emulatorjs cdn."); - console.error("**THIS METHOD IS A FAILSAFE, AND NOT OFFICIALLY SUPPORTED. USE AT YOUR OWN RISK**"); - let version = this.ejs_version.endsWith("-beta") ? "nightly" : this.ejs_version; - res = await this.downloadFile(`https://cdn.emulatorjs.org/${version}/data/${corePath}`, (progress) => { - this.textElem.innerText = this.localization("Download Game Core") + progress; - }, true, { responseType: "arraybuffer", method: "GET" }); - if (res === -1) { - if (!this.supportsWebgl2) { - this.startGameError(this.localization("Outdated graphics driver")); - } else { - this.startGameError(this.localization("Error downloading core") + " (" + filename + ")"); - } - return; - } - console.warn("File was not found locally, but was found on the emulatorjs cdn.\nIt is recommended to download the stable release from here: https://cdn.emulatorjs.org/releases/"); - } - gotCore(res.data); - this.storage.core.put(filename, { - version: rep.buildStart, - data: res.data - }); + try { + gotCore(await window.arcadeReadCore(filename)); + } catch (error) { + this.startGameError(error.message); + } }); } initGameCore(js, wasm, thread) { @@ -1137,26 +1108,33 @@ }); this.gamepad = new GamepadHandler(); //https://github.com/ethanaobrien/Gamepad + // Gamepad events carry the browser's Gamepad.index, which is not a position in this.gamepad.gamepads. this.gamepad.on("connected", (e) => { if (!this.gamepadLabels) return; + const gamepad = this.gamepad.gamepads.find(f => f && f.index === e.gamepadIndex); + if (!gamepad) return; for (let i = 0; i < this.gamepadSelection.length; i++) { if (this.gamepadSelection[i] === "") { - this.gamepadSelection[i] = this.gamepad.gamepads[e.gamepadIndex].id + "_" + this.gamepad.gamepads[e.gamepadIndex].index; + this.gamepadSelection[i] = gamepad.id + "_" + gamepad.index; break; } } this.updateGamepadLabels(); }) this.gamepad.on("disconnected", (e) => { - const gamepadIndex = this.gamepad.gamepads.indexOf(this.gamepad.gamepads.find(f => f.index == e.gamepadIndex)); - const gamepadSelection = this.gamepad.gamepads[gamepadIndex].id + "_" + this.gamepad.gamepads[gamepadIndex].index; - for (let i = 0; i < this.gamepadSelection.length; i++) { - if (this.gamepadSelection[i] === gamepadSelection) { - this.gamepadSelection[i] = ""; + const gamepad = this.gamepad.gamepads.find(f => f && f.index === e.gamepadIndex); + if (gamepad) { + const gamepadSelection = gamepad.id + "_" + gamepad.index; + for (let i = 0; i < this.gamepadSelection.length; i++) { + if (this.gamepadSelection[i] === gamepadSelection) { + this.gamepadSelection[i] = ""; + } } } setTimeout(this.updateGamepadLabels.bind(this), 10); }) + // Controllers already in use when the handler started connected before these listeners existed. + this.gamepad.gamepads.forEach(gamepad => this.gamepad.dispatchEvent("connected", { gamepadIndex: gamepad.index })); this.gamepad.on("axischanged", this.gamepadEvent.bind(this)); this.gamepad.on("buttondown", this.gamepadEvent.bind(this)); this.gamepad.on("buttonup", this.gamepadEvent.bind(this)); @@ -3349,7 +3327,9 @@ } gamepadEvent(e) { if (!this.started) return; - const gamepadIndex = this.gamepadSelection.indexOf(this.gamepad.gamepads[e.gamepadIndex].id + "_" + this.gamepad.gamepads[e.gamepadIndex].index); + const gamepad = this.gamepad.gamepads.find(f => f && f.index === e.gamepadIndex); + if (!gamepad) return; + const gamepadIndex = this.gamepadSelection.indexOf(gamepad.id + "_" + gamepad.index); if (gamepadIndex < 0) { return; // Gamepad not set anywhere }