mirror of
https://github.com/EmulatorJS/EmulatorJS.git
synced 2024-09-20 02:46:23 +00:00
Ability to change settings if game crashes
This commit is contained in:
parent
900eb3b5a9
commit
5abea1917c
1 changed files with 72 additions and 40 deletions
|
@ -494,8 +494,7 @@ class EmulatorJS {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.downloadFile(path, (res) => {
|
this.downloadFile(path, (res) => {
|
||||||
if (res === -1) {
|
if (res === -1) {
|
||||||
this.textElem.innerText = this.localization('Network Error');
|
this.startGameError(this.localization('Network Error'));
|
||||||
this.textElem.style.color = "red";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const blob = new Blob([res.data], {
|
const blob = new Blob([res.data], {
|
||||||
|
@ -548,8 +547,7 @@ class EmulatorJS {
|
||||||
this.downloadFile("compression/libunrar.js", (res) => {
|
this.downloadFile("compression/libunrar.js", (res) => {
|
||||||
this.downloadFile("compression/libunrar.wasm", (res2) => {
|
this.downloadFile("compression/libunrar.wasm", (res2) => {
|
||||||
if (res === -1 || res2 === -1) {
|
if (res === -1 || res2 === -1) {
|
||||||
this.textElem.innerText = this.localization('Network Error');
|
this.startGameError(this.localization('Network Error'));
|
||||||
this.textElem.style.color = "red";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const path = URL.createObjectURL(new Blob([res2.data], {type: "application/wasm"}));
|
const path = URL.createObjectURL(new Blob([res2.data], {type: "application/wasm"}));
|
||||||
|
@ -601,16 +599,24 @@ class EmulatorJS {
|
||||||
checkCoreCompatibility(version) {
|
checkCoreCompatibility(version) {
|
||||||
// Leave commented until next release - this is ready to go.
|
// Leave commented until next release - this is ready to go.
|
||||||
if (this.versionAsInt(version.minimumEJSVersion) > this.versionAsInt(this.ejs_version)) {
|
if (this.versionAsInt(version.minimumEJSVersion) > this.versionAsInt(this.ejs_version)) {
|
||||||
//this.textElem.innerText = this.localization("Outdated EmulatorJS version");
|
//this.startGameError(this.localization("Outdated EmulatorJS version"));
|
||||||
//this.textElem.style.color = "red";
|
|
||||||
//throw new Error("Core requires minimum EmulatorJS version of " + version.minimumEJSVersion);
|
//throw new Error("Core requires minimum EmulatorJS version of " + version.minimumEJSVersion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
startGameError(message) {
|
||||||
|
console.log(message);
|
||||||
|
this.textElem.innerText = message;
|
||||||
|
this.textElem.style.color = "red";
|
||||||
|
|
||||||
|
this.setupSettingsMenu();
|
||||||
|
this.loadSettings();
|
||||||
|
|
||||||
|
this.menu.failedToStart();
|
||||||
|
}
|
||||||
downloadGameCore() {
|
downloadGameCore() {
|
||||||
this.textElem.innerText = this.localization("Download Game Core");
|
this.textElem.innerText = this.localization("Download Game Core");
|
||||||
if (this.config.threads && ((typeof window.SharedArrayBuffer) !== "function")) {
|
if (this.config.threads && ((typeof window.SharedArrayBuffer) !== "function")) {
|
||||||
this.textElem.innerText = this.localization('Error for site owner')+"\n"+this.localization("Check console");
|
this.startGameError(this.localization('Error for site owner')+"\n"+this.localization("Check console"));
|
||||||
this.textElem.style.color = "red";
|
|
||||||
console.warn("Threads is set to true, but the SharedArrayBuffer function is not exposed. Threads requires 2 headers to be set when sending you html page. See https://stackoverflow.com/a/68630724");
|
console.warn("Threads is set to true, but the SharedArrayBuffer function is not exposed. Threads requires 2 headers to be set when sending you html page. See https://stackoverflow.com/a/68630724");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -661,11 +667,10 @@ class EmulatorJS {
|
||||||
this.downloadFile("https://cdn.emulatorjs.org/stable/data/"+corePath, (res) => {
|
this.downloadFile("https://cdn.emulatorjs.org/stable/data/"+corePath, (res) => {
|
||||||
if (res === -1) {
|
if (res === -1) {
|
||||||
if (!this.supportsWebgl2) {
|
if (!this.supportsWebgl2) {
|
||||||
this.textElem.innerText = this.localization('Outdated graphics driver');
|
this.startGameError(this.localization('Outdated graphics driver'));
|
||||||
} else {
|
} else {
|
||||||
this.textElem.innerText = this.localization('Network Error');
|
this.startGameError(this.localization('Network Error'));
|
||||||
}
|
}
|
||||||
this.textElem.style.color = "red";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.warn("File was not found locally, but was found on the emulatorjs cdn.\nIt is recommended to download the latest release from here: https://cdn.emulatorjs.org/releases/");
|
console.warn("File was not found locally, but was found on the emulatorjs cdn.\nIt is recommended to download the latest release from here: https://cdn.emulatorjs.org/releases/");
|
||||||
|
@ -737,8 +742,7 @@ class EmulatorJS {
|
||||||
|
|
||||||
this.downloadFile(this.config.loadState, (res) => {
|
this.downloadFile(this.config.loadState, (res) => {
|
||||||
if (res === -1) {
|
if (res === -1) {
|
||||||
this.textElem.innerText = this.localization('Network Error');
|
this.startGameError(this.localization('Network Error'));
|
||||||
this.textElem.style.color = "red";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.on("start", () => {
|
this.on("start", () => {
|
||||||
|
@ -781,8 +785,7 @@ class EmulatorJS {
|
||||||
}
|
}
|
||||||
this.downloadFile(this.config.gamePatchUrl, (res) => {
|
this.downloadFile(this.config.gamePatchUrl, (res) => {
|
||||||
if (res === -1) {
|
if (res === -1) {
|
||||||
this.textElem.innerText = this.localization('Network Error');
|
this.startGameError(this.localization('Network Error'));
|
||||||
this.textElem.style.color = "red";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.toData(this.config.gamePatchUrl, true)) {
|
if (this.toData(this.config.gamePatchUrl, true)) {
|
||||||
|
@ -832,8 +835,7 @@ class EmulatorJS {
|
||||||
}
|
}
|
||||||
this.downloadFile(this.config.gameParentUrl, (res) => {
|
this.downloadFile(this.config.gameParentUrl, (res) => {
|
||||||
if (res === -1) {
|
if (res === -1) {
|
||||||
this.textElem.innerText = this.localization('Network Error');
|
this.startGameError(this.localization('Network Error'));
|
||||||
this.textElem.style.color = "red";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.toData(this.config.gameParentUrl, true)) {
|
if (this.toData(this.config.gameParentUrl, true)) {
|
||||||
|
@ -877,8 +879,7 @@ class EmulatorJS {
|
||||||
|
|
||||||
this.downloadFile(this.config.biosUrl, (res) => {
|
this.downloadFile(this.config.biosUrl, (res) => {
|
||||||
if (res === -1) {
|
if (res === -1) {
|
||||||
this.textElem.innerText = this.localization('Network Error');
|
this.startGameError(this.localization('Network Error'));
|
||||||
this.textElem.style.color = "red";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.storage.bios.get(this.config.biosUrl.split("/").pop()).then((result) => {
|
this.storage.bios.get(this.config.biosUrl.split("/").pop()).then((result) => {
|
||||||
|
@ -888,8 +889,7 @@ class EmulatorJS {
|
||||||
}
|
}
|
||||||
this.downloadFile(this.config.biosUrl, (res) => {
|
this.downloadFile(this.config.biosUrl, (res) => {
|
||||||
if (res === -1) {
|
if (res === -1) {
|
||||||
this.textElem.innerText = this.localization('Network Error');
|
this.startGameError(this.localization('Network Error'));
|
||||||
this.textElem.style.color = "red";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.toData(this.config.biosUrl, true)) {
|
if (this.toData(this.config.biosUrl, true)) {
|
||||||
|
@ -1013,8 +1013,7 @@ class EmulatorJS {
|
||||||
|
|
||||||
this.downloadFile(this.config.gameUrl, (res) => {
|
this.downloadFile(this.config.gameUrl, (res) => {
|
||||||
if (res === -1) {
|
if (res === -1) {
|
||||||
this.textElem.innerText = this.localization('Network Error');
|
this.startGameError(this.localization('Network Error'));
|
||||||
this.textElem.style.color = "red";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const name = (typeof this.config.gameUrl === "string") ? this.config.gameUrl.split('/').pop() : "game";
|
const name = (typeof this.config.gameUrl === "string") ? this.config.gameUrl.split('/').pop() : "game";
|
||||||
|
@ -1025,8 +1024,7 @@ class EmulatorJS {
|
||||||
}
|
}
|
||||||
this.downloadFile(this.config.gameUrl, (res) => {
|
this.downloadFile(this.config.gameUrl, (res) => {
|
||||||
if (res === -1) {
|
if (res === -1) {
|
||||||
this.textElem.innerText = this.localization('Network Error');
|
this.startGameError(this.localization('Network Error'));
|
||||||
this.textElem.style.color = "red";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.toData(this.config.gameUrl, true)) {
|
if (this.toData(this.config.gameUrl, true)) {
|
||||||
|
@ -1143,8 +1141,7 @@ class EmulatorJS {
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.warn("failed to start game", e);
|
console.warn("failed to start game", e);
|
||||||
this.textElem.innerText = this.localization("Failed to start game");
|
this.startGameError(this.localization("Failed to start game"));
|
||||||
this.textElem.style.color = "red";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.callEvent("start");
|
this.callEvent("start");
|
||||||
|
@ -1618,12 +1615,11 @@ class EmulatorJS {
|
||||||
})
|
})
|
||||||
this.menu = {
|
this.menu = {
|
||||||
close: () => {
|
close: () => {
|
||||||
if (!this.started) return;
|
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
this.elements.menu.classList.add("ejs_menu_bar_hidden");
|
this.elements.menu.classList.add("ejs_menu_bar_hidden");
|
||||||
},
|
},
|
||||||
open: () => {
|
open: (force) => {
|
||||||
if (!this.started) return;
|
if (!this.started && force !== true) return;
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
timeout = setTimeout(hide, 3000);
|
timeout = setTimeout(hide, 3000);
|
||||||
this.elements.menu.classList.remove("ejs_menu_bar_hidden");
|
this.elements.menu.classList.remove("ejs_menu_bar_hidden");
|
||||||
|
@ -1635,7 +1631,6 @@ class EmulatorJS {
|
||||||
timeout = setTimeout(hide, 3000);
|
timeout = setTimeout(hide, 3000);
|
||||||
}
|
}
|
||||||
this.elements.menu.classList.toggle("ejs_menu_bar_hidden");
|
this.elements.menu.classList.toggle("ejs_menu_bar_hidden");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.elements.parent.appendChild(this.elements.menu);
|
this.elements.parent.appendChild(this.elements.menu);
|
||||||
|
@ -2061,14 +2056,47 @@ class EmulatorJS {
|
||||||
muteButton.style.display = "none";
|
muteButton.style.display = "none";
|
||||||
unmuteButton.style.display = "none";
|
unmuteButton.style.display = "none";
|
||||||
}
|
}
|
||||||
if (this.config.buttonOpts.saveState === false) saveState.style.display = "none"
|
if (this.config.buttonOpts.saveState === false) saveState.style.display = "none";
|
||||||
if (this.config.buttonOpts.loadState === false) loadState.style.display = "none"
|
if (this.config.buttonOpts.loadState === false) loadState.style.display = "none";
|
||||||
if (this.config.buttonOpts.saveSavFiles === false) saveSavFiles.style.display = "none"
|
if (this.config.buttonOpts.saveSavFiles === false) saveSavFiles.style.display = "none";
|
||||||
if (this.config.buttonOpts.loadSavFiles === false) loadSavFiles.style.display = "none"
|
if (this.config.buttonOpts.loadSavFiles === false) loadSavFiles.style.display = "none";
|
||||||
if (this.config.buttonOpts.gamepad === false) controlMenu.style.display = "none"
|
if (this.config.buttonOpts.gamepad === false) controlMenu.style.display = "none";
|
||||||
if (this.config.buttonOpts.cheat === false) cheatMenu.style.display = "none"
|
if (this.config.buttonOpts.cheat === false) cheatMenu.style.display = "none";
|
||||||
if (this.config.buttonOpts.cacheManager === false) cache.style.display = "none"
|
if (this.config.buttonOpts.cacheManager === false) cache.style.display = "none";
|
||||||
if (this.config.buttonOpts.netplay === false) netplay.style.display = "none"
|
if (this.config.buttonOpts.netplay === false) netplay.style.display = "none";
|
||||||
|
if (this.config.buttonOpts.diskButton === false) diskButton[0].style.display = "none";
|
||||||
|
if (this.config.buttonOpts.volumeSlider === false) volumeSlider.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.menu.failedToStart = () => {
|
||||||
|
if (!this.config.buttonOpts) this.config.buttonOpts = {};
|
||||||
|
this.config.buttonOpts.mute = false;
|
||||||
|
|
||||||
|
settingButton[0].style.display = "";
|
||||||
|
|
||||||
|
// Hide all except settings button.
|
||||||
|
pauseButton.style.display = "none";
|
||||||
|
playButton.style.display = "none";
|
||||||
|
contextMenuButton.style.display = "none";
|
||||||
|
restartButton.style.display = "none";
|
||||||
|
enter.style.display = "none";
|
||||||
|
exit.style.display = "none";
|
||||||
|
muteButton.style.display = "none";
|
||||||
|
unmuteButton.style.display = "none";
|
||||||
|
saveState.style.display = "none";
|
||||||
|
loadState.style.display = "none";
|
||||||
|
saveSavFiles.style.display = "none";
|
||||||
|
loadSavFiles.style.display = "none";
|
||||||
|
controlMenu.style.display = "none";
|
||||||
|
cheatMenu.style.display = "none";
|
||||||
|
cache.style.display = "none";
|
||||||
|
netplay.style.display = "none";
|
||||||
|
diskButton[0].style.display = "none";
|
||||||
|
volumeSlider.style.display = "none";
|
||||||
|
|
||||||
|
this.elements.menu.style.opacity = "";
|
||||||
|
this.elements.menu.style.background = "none";
|
||||||
|
this.menu.open(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
openCacheMenu() {
|
openCacheMenu() {
|
||||||
|
@ -3895,6 +3923,7 @@ class EmulatorJS {
|
||||||
menuOptionChanged(option, value) {
|
menuOptionChanged(option, value) {
|
||||||
this.saveSettings();
|
this.saveSettings();
|
||||||
if (this.debug) console.log(option, value);
|
if (this.debug) console.log(option, value);
|
||||||
|
if (!this.gameManager) return;
|
||||||
if (option === "shader") {
|
if (option === "shader") {
|
||||||
this.enableShader(value);
|
this.enableShader(value);
|
||||||
return;
|
return;
|
||||||
|
@ -4309,7 +4338,7 @@ class EmulatorJS {
|
||||||
addToMenu(this.localization('Shaders'), 'shader', shaderMenu, 'disabled');
|
addToMenu(this.localization('Shaders'), 'shader', shaderMenu, 'disabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
addToMenu(this.localization('WebGL2') + "(" + this.localization('Requires page reload') + ")", 'webgl2Enabled', {
|
addToMenu(this.localization('WebGL2') + " (" + this.localization('Requires page reload') + ")", 'webgl2Enabled', {
|
||||||
'enabled': this.localization("Enabled"),
|
'enabled': this.localization("Enabled"),
|
||||||
'disabed': this.localization("Disabled")
|
'disabed': this.localization("Disabled")
|
||||||
}, this.defaultWebgl2 ? "enabled" : "disabed");
|
}, this.defaultWebgl2 ? "enabled" : "disabed");
|
||||||
|
@ -5155,6 +5184,7 @@ class EmulatorJS {
|
||||||
this.elements.cheatRows = rows;
|
this.elements.cheatRows = rows;
|
||||||
}
|
}
|
||||||
updateCheatUI() {
|
updateCheatUI() {
|
||||||
|
if (!this.gameManager) return;
|
||||||
this.elements.cheatRows.innerHTML = "";
|
this.elements.cheatRows.innerHTML = "";
|
||||||
|
|
||||||
const addToMenu = (desc, checked, code, is_permanent, i) => {
|
const addToMenu = (desc, checked, code, is_permanent, i) => {
|
||||||
|
@ -5197,10 +5227,12 @@ class EmulatorJS {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cheatChanged(checked, code, index) {
|
cheatChanged(checked, code, index) {
|
||||||
|
if (!this.gameManager) return;
|
||||||
this.gameManager.setCheat(index, checked, code);
|
this.gameManager.setCheat(index, checked, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
enableShader(name) {
|
enableShader(name) {
|
||||||
|
if (!this.gameManager) return;
|
||||||
try {
|
try {
|
||||||
this.Module.FS.unlink("/shader/shader.glslp");
|
this.Module.FS.unlink("/shader/shader.glslp");
|
||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
|
|
Loading…
Reference in a new issue