reset mapping to default on press the Home button

This commit is contained in:
Greenlamp 2024-05-17 15:43:03 +02:00
parent a2e0c1c5f1
commit a6b150a48c
3 changed files with 24 additions and 0 deletions

View File

@ -691,6 +691,13 @@ export class InputsController {
this.configs[selectedDevice].custom = mappingConfigs.custom;
}
resetConfigs(): void {
this.configs = new Map();
if (this.getGamepadsName()?.length)
this.setupGamepad(this.selectedDevice[Device.GAMEPAD]);
this.setupKeyboard();
}
/**
* Swaps a binding in the configuration.
*

View File

@ -589,6 +589,13 @@ export class GameData {
return true; // Return true to indicate the operation was successful
}
public resetMappingToFactory(): boolean {
if (!localStorage.hasOwnProperty('mappingConfigs')) // Check if 'mappingConfigs' exists in localStorage
return false; // If 'mappingConfigs' does not exist, return false
localStorage.removeItem('mappingConfigs');
this.scene.inputController.resetConfigs();
}
/**
* Saves a gamepad setting to localStorage.
*

View File

@ -40,7 +40,9 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl
this.settingBlacklisted = settingKeyboardBlackList;
const deleteEvent = scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.DELETE);
const restoreDefaultEvent = scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.HOME);
deleteEvent.on('up', this.onDeleteDown, this);
restoreDefaultEvent.on('up', this.onHomeDown, this);
}
setSetting(scene: BattleScene, setting, value: integer): boolean {
@ -66,6 +68,14 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl
this.layout['noKeyboard'].label = label;
}
/**
* Handle the home key press event.
*/
onHomeDown(): void {
if (![Mode.SETTINGS_KEYBOARD, Mode.SETTINGS, Mode.SETTINGS_GAMEPAD].includes(this.scene.ui.getMode())) return;
this.scene.gameData.resetMappingToFactory();
}
/**
* Handle the delete key press event.
*/