From dd76cbc7a247137dc215e9388f7a319b0b62cfd1 Mon Sep 17 00:00:00 2001 From: Benjamin Odom Date: Sun, 5 May 2024 00:25:57 -0500 Subject: [PATCH] Add Setting to Swap A and B on Gamepad (#474) * Add Setting to Swap A and B on Gamepad Added a new setting to swap the A and B button on controller. Defaults to off which retains the current behavior on live. * Add comments --- src/battle-scene.ts | 9 +++++++++ src/system/settings.ts | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 0a5c4bbf488..46f7b4ae0a2 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -235,6 +235,15 @@ export default class BattleScene extends SceneBase { this.nextCommandPhaseQueue = []; } + /** + * Conditionally swaps the ACTION and CANCEL button + * @param standard When true, uses the default values + */ + setGamepadConfirm(standard: boolean) { + this.gamepadKeyConfig[Button.ACTION] = standard ? 0 : 1; + this.gamepadKeyConfig[Button.CANCEL] = standard ? 1 : 0; + } + loadPokemonAtlas(key: string, atlasPath: string, experimental?: boolean) { if (experimental === undefined) experimental = this.experimentalSprites; diff --git a/src/system/settings.ts b/src/system/settings.ts index 8f0b169efc1..62b97e27a58 100644 --- a/src/system/settings.ts +++ b/src/system/settings.ts @@ -25,6 +25,7 @@ export enum Setting { Fusion_Palette_Swaps = "FUSION_PALETTE_SWAPS", Player_Gender = "PLAYER_GENDER", Gamepad_Support = "GAMEPAD_SUPPORT", + Swap_A_and_B = "SWAP_A_B", // Swaps which gamepad button handles ACTION and CANCEL Touch_Controls = "TOUCH_CONTROLS", Vibration = "VIBRATION" } @@ -56,6 +57,7 @@ export const settingOptions: SettingOptions = { [Setting.Fusion_Palette_Swaps]: [ 'Off', 'On' ], [Setting.Player_Gender]: [ 'Boy', 'Girl' ], [Setting.Gamepad_Support]: [ 'Auto', 'Disabled' ], + [Setting.Swap_A_and_B]: [ 'Enabled', 'Disabled' ], [Setting.Touch_Controls]: [ 'Auto', 'Disabled' ], [Setting.Vibration]: [ 'Auto', 'Disabled' ] }; @@ -79,6 +81,7 @@ export const settingDefaults: SettingDefaults = { [Setting.Fusion_Palette_Swaps]: 1, [Setting.Player_Gender]: 0, [Setting.Gamepad_Support]: 0, + [Setting.Swap_A_and_B]: 1, // Set to 'Disabled' by default [Setting.Touch_Controls]: 0, [Setting.Vibration]: 0 }; @@ -148,6 +151,9 @@ export function setSetting(scene: BattleScene, setting: Setting, value: integer) case Setting.Gamepad_Support: scene.gamepadSupport = settingOptions[setting][value] !== 'Disabled'; break; + case Setting.Swap_A_and_B:debugger; + scene.setGamepadConfirm(settingOptions[setting][value] !== 'Enabled'); + break; case Setting.Touch_Controls: scene.enableTouchControls = settingOptions[setting][value] !== 'Disabled' && hasTouchscreen(); const touchControls = document.getElementById('touchControls');