From 74624c4e9ac22f5054e48aff153b74849badf258 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien <77750390+ethanaobrien@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:51:58 -0500 Subject: [PATCH] Fix cheats menu. Resolves #621 --- data/emulator.js | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/data/emulator.js b/data/emulator.js index 16f3c05..408b5ef 100644 --- a/data/emulator.js +++ b/data/emulator.js @@ -299,7 +299,7 @@ class EmulatorJS { this.game.classList.remove("ejs_game_background"); if (this.config.backgroundBlur) this.game.classList.remove("ejs_game_background_blur"); }) - }else{ + } else { this.game.setAttribute("style", "--ejs-background-color: "+this.config.backgroundColor+";"); } @@ -310,7 +310,8 @@ class EmulatorJS { this.cheats.push({ desc: cheat[0], checked: false, - code: cheat[1] + code: cheat[1], + is_permanent: true }) } } @@ -4686,6 +4687,12 @@ class EmulatorJS { } }, true); this.cheatMenu = body.parentElement; + this.cheatMenu.getElementsByTagName("h4")[0].style["padding-bottom"] = "0px"; + const msg = this.createElement("div"); + msg.style["padding-top"] = "0px"; + msg.style["padding-bottom"] = "15px"; + msg.innerText = "Note that some cheats require a restart to disable."; + body.appendChild(msg); const rows = this.createElement("div"); body.appendChild(rows); rows.classList.add("ejs_cheat_rows"); @@ -4693,13 +4700,8 @@ class EmulatorJS { } updateCheatUI() { this.elements.cheatRows.innerHTML = ""; - const getIndex = (desc, code) => { - for (let i=0; i { + const addToMenu = (desc, checked, code, is_permanent, i) => { const row = this.createElement("div"); row.classList.add("ejs_cheat_row"); const input = this.createElement("input"); @@ -4714,28 +4716,28 @@ class EmulatorJS { row.appendChild(label); label.addEventListener("click", (e) => { input.checked = !input.checked; - this.cheats[getIndex(desc, code)].checked = input.checked; - this.cheatChanged(input.checked, code, getIndex(desc, code)); + this.cheats[i].checked = input.checked; + this.cheatChanged(input.checked, code, i); this.saveSettings(); }) - const close = this.createElement("a"); - close.classList.add("ejs_cheat_row_button"); - close.innerText = "×"; - row.appendChild(close); - close.addEventListener("click", (e) => { - this.cheatChanged(false, code, getIndex(desc, code)); - this.cheats.splice(getIndex(desc, code), 1); - row.remove(); - this.saveSettings(); - }) - + if (!is_permanent) { + const close = this.createElement("a"); + close.classList.add("ejs_cheat_row_button"); + close.innerText = "×"; + row.appendChild(close); + close.addEventListener("click", (e) => { + this.cheatChanged(false, code, i); + this.cheats.splice(i, 1); + this.updateCheatUI(); + this.saveSettings(); + }) + } this.elements.cheatRows.appendChild(row); this.cheatChanged(checked, code, i); - } this.gameManager.resetCheat(); for (let i=0; i