From 57bf7bbd8c3b50fe58f92706cf0acf4074d9652f Mon Sep 17 00:00:00 2001 From: LoveEevee Date: Sat, 15 Dec 2018 22:13:16 +0300 Subject: [PATCH] Gamepad: Disable with keyboard input --- public/src/js/gamepad.js | 3 +++ public/src/js/pageevents.js | 2 ++ public/src/js/scoresheet.js | 3 +++ public/src/js/session.js | 1 + 4 files changed, 9 insertions(+) diff --git a/public/src/js/gamepad.js b/public/src/js/gamepad.js index b5be89e..0487c92 100644 --- a/public/src/js/gamepad.js +++ b/public/src/js/gamepad.js @@ -32,6 +32,9 @@ class Gamepad{ } } play(callback){ + if(pageEvents.lastKeyEvent + 5000 > Date.now()){ + return + } if("getGamepads" in navigator){ var gamepads = navigator.getGamepads() }else{ diff --git a/public/src/js/pageevents.js b/public/src/js/pageevents.js index 4577851..741804e 100644 --- a/public/src/js/pageevents.js +++ b/public/src/js/pageevents.js @@ -3,6 +3,7 @@ class PageEvents{ this.allEvents = new Map() this.keyListeners = new Map() this.mouseListeners = new Map() + this.lastKeyEvent = -Infinity this.add(window, "keydown", this.keyEvent.bind(this)) this.add(window, "keyup", this.keyEvent.bind(this)) this.add(window, "mousemove", this.mouseEvent.bind(this)) @@ -80,6 +81,7 @@ class PageEvents{ }) } keyEvent(event){ + this.lastKeyEvent = Date.now() this.keyListeners.forEach(addedKeyCode => { this.checkListener(addedKeyCode.get("all"), event) this.checkListener(addedKeyCode.get(event.keyCode), event) diff --git a/public/src/js/scoresheet.js b/public/src/js/scoresheet.js index b171741..77c638a 100644 --- a/public/src/js/scoresheet.js +++ b/public/src/js/scoresheet.js @@ -714,6 +714,9 @@ class Scoresheet{ this.redrawRunning = false pageEvents.keyRemove(this, "all") pageEvents.remove(this.canvas, ["mousedown", "touchstart"]) + if(p2.session){ + pageEvents.remove(p2, "message") + } delete this.ctx delete this.canvas } diff --git a/public/src/js/session.js b/public/src/js/session.js index baf2010..526b934 100644 --- a/public/src/js/session.js +++ b/public/src/js/session.js @@ -59,6 +59,7 @@ class Session{ this.gamepad.clean() pageEvents.remove(window, ["mousedown", "touchstart"]) pageEvents.keyRemove(this, 27) + pageEvents.remove(p2, "message") delete this.endButton delete this.sessionInvite }