diff --git a/src/inputs-controller.ts b/src/inputs-controller.ts index 6b3e6182a..552ebf222 100644 --- a/src/inputs-controller.ts +++ b/src/inputs-controller.ts @@ -91,10 +91,13 @@ export class InputsController { } setGamepadSupport(value: boolean): void { + // value is true if we activate gamepad + // value is false if we deactivate gamepad if (value) { this.gamepadSupport = true; } else { this.gamepadSupport = false; + // if we disable the gamepad, we want to release every key pressed this.deactivatePressedKey(); } } @@ -103,11 +106,17 @@ export class InputsController { // reversed to let the cancel button have a kinda priority on the action button for (const b of Utils.getEnumValues(Button).reverse()) { if ( - this.interactions.hasOwnProperty(b) && - this.repeatInputDurationJustPassed(b) && - this.interactions[b].isPressed + this.interactions.hasOwnProperty(b) && // if the button is in the interactions dict + this.repeatInputDurationJustPassed(b) && // if we hold enough the button + this.interactions[b].isPressed // if the button is pressed ) { + // if the gamepad support is disable and the source is a gamepad + // we don't want to repeat the button + // even if we have disabled the gamepad, at the exact moment of the change in the menu + // we can be here and have an infinite loop since the code can't know we + // have released the key since the gamepad is not there anymore if (!this.gamepadSupport && this.interactions[b].source === 'gamepad') { + // if we are here and the gamepad is disabled, we delete the latest interracted button this.delLastProcessedMovementTime(b); return; } @@ -270,6 +279,7 @@ export class InputsController { } } + // added source so when we repeat the key, we can also tell from which source the key is from setLastProcessedMovementTime(button: Button, source: String = 'keyboard'): void { if (!this.interactions.hasOwnProperty(button)) return; this.setButtonLock(button); diff --git a/src/system/settings.ts b/src/system/settings.ts index b0c61fabf..f25356dc7 100644 --- a/src/system/settings.ts +++ b/src/system/settings.ts @@ -149,6 +149,8 @@ export function setSetting(scene: BattleScene, setting: Setting, value: integer) return false; break; case Setting.Gamepad_Support: + // if we change the value of the gamepad support, we call a method in the inputController to + // activate or deactivate the controller listener scene.inputController.setGamepadSupport(settingOptions[setting][value] !== 'Disabled'); break; case Setting.Swap_A_and_B: