commented gamepad fallback on disconnect

pull/685/head
Greenlamp 2024-05-11 12:45:45 +02:00
parent 635a2ea959
commit 931ec61f87
1 changed files with 12 additions and 8 deletions

View File

@ -257,18 +257,22 @@ export class InputsController {
// If we don't do that, we have no way to determine if the gamepad is connected or not. // If we don't do that, we have no way to determine if the gamepad is connected or not.
// We want to know that because we want to hide it in the selection menu of gamepad to use // We want to know that because we want to hide it in the selection menu of gamepad to use
this.disconnectedGamepads.push(thisGamepad.id); this.disconnectedGamepads.push(thisGamepad.id);
// we look for gamepads still connected by substracting the 2 arrays /** commented for now this code because i don't know anymore if it's good to do that
const gamepadsLeft = this.gamepads.filter(g => !this.disconnectedGamepads.includes(g.id)).map(g => g); * for example i'm playing with a wireless gamepad that shutdown after 5 min
* i don't want my game to use my second controller when i turn back on my main gamepad
* we look for gamepads still connected by substracting the 2 arrays
*/
// const gamepadsLeft = this.gamepads.filter(g => !this.disconnectedGamepads.includes(g.id)).map(g => g);
// we check if the chosen gamepad is still connected // we check if the chosen gamepad is still connected
const chosenIsConnected = gamepadsLeft.some(g => g.id === this.chosenGamepad); // const chosenIsConnected = gamepadsLeft.some(g => g.id === this.chosenGamepad);
// if the chosen gamepad is disconnected, and we got others gamepad connected // if the chosen gamepad is disconnected, and we got others gamepad connected
if (!chosenIsConnected && gamepadsLeft?.length) { // if (!chosenIsConnected && gamepadsLeft?.length) {
// We remove the previously chosen gamepad // We remove the previously chosen gamepad
this.clearChosenGamepad(); // this.clearChosenGamepad();
// and we set the first of the gamepad still connected as the chosen one. // and we set the first of the gamepad still connected as the chosen one.
this.setChosenGamepad(gamepadsLeft[0].id); // this.setChosenGamepad(gamepadsLeft[0].id);
return; // return;
} // }
} }
onReconnect(thisGamepad: Phaser.Input.Gamepad.Gamepad): void { onReconnect(thisGamepad: Phaser.Input.Gamepad.Gamepad): void {