From acf668a2f3f93b08e89ce8ce129c84ae6523637f Mon Sep 17 00:00:00 2001 From: Ethan O'Brien <77750390+ethanaobrien@users.noreply.github.com> Date: Sun, 2 Jul 2023 18:03:29 -0500 Subject: [PATCH] Mouselock --- src/css/main.css | 4 ++-- src/emulator.js | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/css/main.css b/src/css/main.css index 1e5d620..68b085b 100644 --- a/src/css/main.css +++ b/src/css/main.css @@ -583,11 +583,11 @@ } .ejs_settings_transition { overflow: hidden; - max-height: 385px; + max-height: 300px; transition: height .35s cubic-bezier(0.4,0,0.2,1),width .35s cubic-bezier(0.4,0,0.2,1); } .ejs_setting_home { - max-height: 385px; + max-height: 300px; overflow: scroll; } .ejs_settings_main_bar { diff --git a/src/emulator.js b/src/emulator.js index 0531400..b6c6962 100644 --- a/src/emulator.js +++ b/src/emulator.js @@ -827,6 +827,13 @@ class EmulatorJS { timeout = setTimeout(hide, 3000); this.elements.menu.classList.remove("ejs_menu_bar_hidden"); }) + this.addEventListener(this.elements.menu, 'touchstart touchend touchmove', (e) => { + if (!this.started) return; + if (this.isPopupOpen()) return; + if (timeout !== null) clearTimeout(timeout); + timeout = setTimeout(hide, 3000); + this.elements.menu.classList.remove("ejs_menu_bar_hidden"); + }) this.menu = { close: () => { if (!this.started) return; @@ -890,6 +897,15 @@ class EmulatorJS { playButton.style.display = "none"; } this.gameManager.toggleMainLoop(this.paused ? 0 : 1); + + //I now realize its not easy to pause it while the cursor is locked, just in case I guess + if (this.getCore(true) === "nds") { + if (this.canvas.exitPointerLock) { + this.canvas.exitPointerLock(); + } else if (this.canvas.mozExitPointerLock) { + this.canvas.mozExitPointerLock(); + } + } } @@ -958,7 +974,8 @@ class EmulatorJS { volumeSlider.setAttribute("aria-valuemax", 100); this.setVolume = (volume) => { - volumeSlider.setAttribute("value", volume); + this.muted = (volume === 0); + volumeSlider.value = volume; volumeSlider.setAttribute("aria-valuenow", volume*100); volumeSlider.setAttribute("aria-valuetext", (volume*100).toFixed(1) + "%"); volumeSlider.setAttribute("style", "--value: "+volume*100+"%;margin-left: 5px;position: relative;z-index: 2;"); @@ -969,6 +986,7 @@ class EmulatorJS { this.initAudio = () => { RA.queueAudio = () => { var index = RA.bufIndex; + let volume = this.volume; var startTime; if (RA.bufIndex) startTime = RA.buffers[RA.bufIndex - 1].endTime; @@ -977,13 +995,14 @@ class EmulatorJS { const bufferSource = RA.context.createBufferSource(); bufferSource.buffer = RA.buffers[index]; - if (this.volume === 1) { + if (this.muted) volume = 0; + if (volume === 1) { bufferSource.connect(RA.context.destination); } else { var gain = RA.context.createGain(); bufferSource.connect(gain); gain.connect(RA.context.destination); - gain.gain.setValueAtTime(this.volume, RA.context.currentTime, 0); + gain.gain.setValueAtTime(volume, RA.context.currentTime, 0); } bufferSource.start(startTime); @@ -1037,6 +1056,15 @@ class EmulatorJS { this.closeSettingsMenu(); }, 10) }) + this.addEventListener(this.canvas, "click", (e) => { + if (this.getCore(true) === "nds" && !this.paused) { + if (this.canvas.requestPointerLock) { + this.canvas.requestPointerLock(); + } else if (this.canvas.mozRequestPointerLock) { + this.canvas.mozRequestPointerLock(); + } + } + }) const enter = addButton("Enter Fullscreen", '', () => { if (this.elements.parent.requestFullscreen) { @@ -1996,7 +2024,7 @@ class EmulatorJS { home.appendChild(menuOption); const menu = this.createElement("div"); - menu.style["max-height"] = "385px"; + menu.style["max-height"] = "300px"; menu.style.overflow = "auto"; menu.setAttribute("hidden", ""); const button = this.createElement("button");