1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

handle gamepad disconnected event

This commit is contained in:
Lukas Dolezal 2020-12-27 20:19:35 +01:00
parent 8c01af3b6a
commit 08ee615c6c

View File

@ -28,6 +28,7 @@ export class InputDistributor {
*/
this.keysDown = new Set();
/** @type number */
this.connectedGamepadIndex = null;
this.bindToEvents();
@ -153,6 +154,7 @@ export class InputDistributor {
window.addEventListener("blur", this.handleBlur.bind(this));
window.addEventListener("gamepadconnected", this.handleGamepadConnected.bind(this));
window.addEventListener("gamepaddisconnected", this.handleGamepadDisconnected.bind(this));
}
forwardToReceiver(eventId, payload = null) {
@ -177,6 +179,12 @@ export class InputDistributor {
this.connectedGamepadIndex = event.gamepad.index;
}
handleGamepadDisconnected(event) {
if (event.gamepad.index === this.connectedGamepadIndex) {
this.connectedGamepadIndex = null;
}
}
processGamepadInputs() {
if (this.connectedGamepadIndex === null) {
return;