diff --git a/data/GameManager.js b/data/GameManager.js index b05f407..095a92f 100644 --- a/data/GameManager.js +++ b/data/GameManager.js @@ -22,6 +22,7 @@ class EJS_GameManager { saveSaveFiles: this.Module.cwrap('cmd_savefiles', '', []), supportsStates: this.Module.cwrap('supports_states', 'number', []), loadSaveFiles: this.Module.cwrap('refresh_save_files', 'null', []), + togglePointerCapture: this.Module.cwrap('toggle_capturepointer', 'null', ['number']), toggleFastForward: this.Module.cwrap('toggle_fastforward', 'null', ['number']), setFastForwardRatio: this.Module.cwrap('set_ff_ratio', 'null', ['number']), toggleRewind: this.Module.cwrap('toggle_rewind', 'null', ['number']), @@ -351,6 +352,9 @@ class EJS_GameManager { this.clearEJSResetTimer(); this.functions.loadSaveFiles(); } + togglePointerCapture(active) { + this.functions.togglePointerCapture(active); + } setFastForwardRatio(ratio) { this.functions.setFastForwardRatio(ratio); } diff --git a/data/emulator.js b/data/emulator.js index 0b32164..cacb446 100644 --- a/data/emulator.js +++ b/data/emulator.js @@ -277,6 +277,11 @@ class EmulatorJS { this.settingsLanguage = window.EJS_settingsLanguage || false; this.config = config; this.currentPopup = null; + if (window.EJS_CapturePointer !== undefined) { + this.isPointerCapture = window.EJS_CapturePointer; + } else { + this.isPointerCapture = false; + } this.isFastForward = false; this.isSlowMotion = false; this.rewindEnabled = this.loadRewindEnabled(); @@ -1703,13 +1708,10 @@ class EmulatorJS { } 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(); - } + if (this.canvas.exitPointerLock) { + this.canvas.exitPointerLock(); + } else if (this.canvas.mozExitPointerLock) { + this.canvas.mozExitPointerLock(); } } this.play = (dontUpdate) => { @@ -1905,10 +1907,12 @@ class EmulatorJS { this.addEventListener(this.canvas, "click", (e) => { if (e.pointerType === "touch") return; if (!this.paused) { - if (this.canvas.requestPointerLock) { - this.canvas.requestPointerLock(); - } else if (this.canvas.mozRequestPointerLock) { - this.canvas.mozRequestPointerLock(); + if (this.isPointerCapture === true) { + if (this.canvas.requestPointerLock) { + this.canvas.requestPointerLock(); + } else if (this.canvas.mozRequestPointerLock) { + this.canvas.mozRequestPointerLock(); + } } this.menu.close(); } @@ -3902,6 +3906,12 @@ class EmulatorJS { if (this.rewindEnabled) { this.gameManager.setRewindGranularity(parseInt(value)); } + } else if (option === "capturepointer") { + if (value === "enabled") { + this.isPointerCapture = true; + } else { + this.isPointerCapture = false; + } } this.gameManager.setVariable(option, value); this.saveSettings(); @@ -4078,6 +4088,11 @@ class EmulatorJS { }, 'disabled'); } + addToMenu(this.localization('Capture Pointer'), 'capturepointer', { + 'enabled': this.localization("Enabled"), + 'disabled': this.localization("Disabled") + }, "disabled"); + addToMenu(this.localization('FPS'), 'fps', { 'show': this.localization("show"), 'hide': this.localization("hide")