From c7d62abf3bb25bec5d1ec4aea541bdcc778bcee8 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien <77750390+ethanaobrien@users.noreply.github.com> Date: Sat, 1 Jul 2023 14:15:00 -0500 Subject: [PATCH] Add button toggle --- index.html | 7 ++++--- src/emulator.js | 41 ++++++++++++++++++++++++++++++++--------- src/loader.js | 1 + 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index 3ffe2a4..a1a853e 100644 --- a/index.html +++ b/index.html @@ -8,12 +8,13 @@ EJS_gameUrl = 'mega_mountain.nes'; EJS_DEBUG_XX = true; EJS_AdUrl = "https://www.google.com/search?igu=1"; + /* EJS_Buttons = { playPause: false, restart: false, mute: false, - settings: false, - fullscreen: true, + settings: true, + fullscreen: false, saveState: false, loadState: false, screenRecord: false, @@ -24,6 +25,6 @@ quickLoad: false, screenshot: false, cacheManager: false - } + }*/ diff --git a/src/emulator.js b/src/emulator.js index a67e2a0..a1de511 100644 --- a/src/emulator.js +++ b/src/emulator.js @@ -706,9 +706,10 @@ class EmulatorJS { li.appendChild(a); parent.appendChild(li); hideMenu(); + return li; } let screenshotUrl; - addButton("Take Screenshot", false, () => { + const screenshot = addButton("Take Screenshot", false, () => { if (screenshotUrl) URL.revokeObjectURL(screenshotUrl); const screenshot = this.gameManager.screenshot(); const blob = new Blob([screenshot]); @@ -720,11 +721,11 @@ class EmulatorJS { a.click(); hideMenu(); }); - addButton("Quick Save", false, () => { + const qSave = addButton("Quick Save", false, () => { this.gameManager.quickSave(); hideMenu(); }); - addButton("Quick Load", false, () => { + const qLoad = addButton("Quick Load", false, () => { this.gameManager.quickLoad(); hideMenu(); }); @@ -736,9 +737,14 @@ class EmulatorJS { } }); body.innerText = "Todo. Write about, include tabs on side with licenses, links to docs/repo/discord?"; - }); + if (this.config.buttonOpts) { + if (!this.config.buttonOpts.screenshot) screenshot.setAttribute("hidden", ""); + if (!this.config.buttonOpts.quickSave) qSave.setAttribute("hidden", ""); + if (!this.config.buttonOpts.quickLoad) qLoad.setAttribute("hidden", ""); + } + this.elements.contextmenu.appendChild(parent); this.elements.parent.appendChild(this.elements.contextmenu); @@ -859,7 +865,7 @@ class EmulatorJS { //todo. Center text on not restart button - addButton("Restart", '', () => { + const restartButton = addButton("Restart", '', () => { this.gameManager.restart(); }); const pauseButton = addButton("Pause", '', () => { @@ -883,7 +889,7 @@ class EmulatorJS { let stateUrl; - addButton("Save State", '', async () => { + const saveState = addButton("Save State", '', async () => { const state = await this.gameManager.getState(); const called = this.callEvent("save", { screenshot: this.gameManager.screenshot(), @@ -898,15 +904,15 @@ class EmulatorJS { a.download = this.getBaseFileName()+".state"; a.click(); }); - addButton("Load State", '', async () => { + const loadState = addButton("Load State", '', async () => { const file = await this.selectFile(); const state = new Uint8Array(await file.arrayBuffer()); this.gameManager.loadState(state); }); - addButton("Control Settings", '', () => { + const controlMenu = addButton("Control Settings", '', () => { this.controlMenu.style.display = ""; }); - addButton("Cheats", '', () => { + const cheatMenu = addButton("Cheats", '', () => { this.cheatMenu.style.display = ""; }); @@ -982,6 +988,23 @@ class EmulatorJS { } }) + if (this.config.buttonOpts) { + if (!this.config.buttonOpts.playPause) { + pauseButton.style.display = "none"; + playButton.style.display = "none"; + } + if (!this.config.buttonOpts.restart) restartButton.setAttribute("hidden", ""); + if (!this.config.buttonOpts.settings) settingButton[0].setAttribute("hidden", ""); + if (!this.config.buttonOpts.fullscreen) { + enter.style.display = "none"; + exit.style.display = "none"; + } + if (!this.config.buttonOpts.saveState) saveState.setAttribute("hidden", ""); + if (!this.config.buttonOpts.loadState) loadState.setAttribute("hidden", ""); + if (!this.config.buttonOpts.gamepad) controlMenu.setAttribute("hidden", ""); + if (!this.config.buttonOpts.cheat) cheatMenu.setAttribute("hidden", ""); + } + } createControlSettingMenu() { let buttonListeners = []; diff --git a/src/loader.js b/src/loader.js index 9036163..aa6ce3b 100644 --- a/src/loader.js +++ b/src/loader.js @@ -52,6 +52,7 @@ config.adUrl = window.EJS_AdUrl; config.adTimer = window.EJS_AdTimer config.VirtualGamepadSettings = window.EJS_VirtualGamepadSettings; + config.buttonOpts = window.EJS_Buttons; new EmulatorJS(EJS_player, config);