From 0afa3dcdccb8c62835c11839bba719ef957a53f3 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien <77750390+ethanaobrien@users.noreply.github.com> Date: Thu, 29 Jun 2023 16:26:30 -0500 Subject: [PATCH] start gamepad --- src/GameManager.js | 3 ++- src/emulator.js | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/GameManager.js b/src/GameManager.js index f2a1fa3..a96bfb2 100644 --- a/src/GameManager.js +++ b/src/GameManager.js @@ -21,9 +21,10 @@ class EJS_GameManager { this.mkdir("/home/web_user/retroarch"); this.mkdir("/home/web_user/retroarch/userdata"); - this.FS.writeFile("/home/web_user/retroarch/userdata/retroarch.cfg", this.getRetroArchCfg()); + //this.FS.writeFile("/home/web_user/retroarch/userdata/retroarch.cfg", this.getRetroArchCfg()); this.initShaders(); + window.RA.nonblock = true; //lets see if this works } mkdir(path) { try { diff --git a/src/emulator.js b/src/emulator.js index 0a3864d..4993fca 100644 --- a/src/emulator.js +++ b/src/emulator.js @@ -468,6 +468,7 @@ class EmulatorJS { this.setupSettingsMenu(); this.handleResize(); this.updateCheatUI(); + this.updateGamepadLabels(); this.elements.parent.focus(); } bindListeners() { @@ -482,8 +483,33 @@ class EmulatorJS { }) this.addEventListener(window, "resize", this.handleResize.bind(this)); //this.addEventListener(window, "blur", e => console.log(e), true); //TODO - add "click to make keyboard keys work" message - //this.gamepad = new GamepadHandler(); //https://github.com/ethanaobrien/Gamepad - //keyboard, etc... + this.gamepad = new GamepadHandler(); //https://github.com/ethanaobrien/Gamepad + this.gamepad.on('connected', (e) => { + if (!this.gamepadLabels) return; + this.updateGamepadLabels(); + }) + this.gamepad.on('disconnected', (e) => { + setTimeout(this.updateGamepadLabels.bind(this), 10); + }) + this.gamepad.on('axischanged', function(e) { + console.log('axischanged', e); + }) + this.gamepad.on('buttondown', function(e) { + console.log('buttondown', e); + }) + this.gamepad.on('buttonup', function(e) { + console.log('buttonup', e); + }) + } + updateGamepadLabels() { + for (let i=0; i { @@ -880,6 +907,7 @@ class EmulatorJS { gamepadTitle.innerText = "Connected Gamepad: "; const gamepadName = this.createElement("span"); + this.gamepadLabels.push(gamepadName); gamepadName.innerText = "n/a"; gamepadTitle.appendChild(gamepadName);