From de1bf3d855e4d35b64bcdea7c01654f439776b65 Mon Sep 17 00:00:00 2001 From: Greenlamp Date: Thu, 16 May 2024 02:09:42 +0200 Subject: [PATCH] comment TSDOC settings --- .../settings/settings-gamepad-ui-handler.ts | 50 ++++++++++++++++ .../settings/settings-keyboard-ui-handler.ts | 58 ++++++++++++++++++- 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/src/ui/settings/settings-gamepad-ui-handler.ts b/src/ui/settings/settings-gamepad-ui-handler.ts index 936180c98ed..674cdda1cfe 100644 --- a/src/ui/settings/settings-gamepad-ui-handler.ts +++ b/src/ui/settings/settings-gamepad-ui-handler.ts @@ -9,8 +9,20 @@ import {InterfaceConfig} from "#app/inputs-controller"; import AbstractSettingsUiUiHandler from "#app/ui/settings/abstract-settings-ui-handler"; import {Device} from "#app/enums/devices"; +/** + * Class representing the settings UI handler for gamepads. + * + * @extends AbstractSettingsUiUiHandler + */ + export default class SettingsGamepadUiHandler extends AbstractSettingsUiUiHandler { + /** + * Creates an instance of SettingsGamepadUiHandler. + * + * @param scene - The BattleScene instance. + * @param mode - The UI mode, optional. + */ constructor(scene: BattleScene, mode?: Mode) { super(scene, mode); this.titleSelected = 'Gamepad'; @@ -22,6 +34,9 @@ export default class SettingsGamepadUiHandler extends AbstractSettingsUiUiHandle this.localStoragePropertyName = 'settingsGamepad'; } + /** + * Setup UI elements. + */ setup() { super.setup(); // If no gamepads are detected, set up a default UI prompt in the settings container. @@ -38,16 +53,32 @@ export default class SettingsGamepadUiHandler extends AbstractSettingsUiUiHandle this.layout['noGamepads'].label = label; } + /** + * Get the active configuration. + * + * @returns The active gamepad configuration. + */ getActiveConfig(): InterfaceConfig { return this.scene.inputController.getActiveConfig(Device.GAMEPAD); } + /** + * Get the gamepad settings from local storage. + * + * @returns The gamepad settings from local storage. + */ getLocalStorageSetting(): object { // Retrieve the gamepad settings from local storage or use an empty object if none exist. const settings: object = localStorage.hasOwnProperty('settingsGamepad') ? JSON.parse(localStorage.getItem('settingsGamepad')) : {}; return settings; } + /** + * Set the layout for the active configuration. + * + * @param activeConfig - The active gamepad configuration. + * @returns `true` if the layout was successfully applied, otherwise `false`. + */ setLayout(activeConfig: InterfaceConfig): boolean { // Check if there is no active configuration (e.g., no gamepad connected). if (!activeConfig) { @@ -63,16 +94,29 @@ export default class SettingsGamepadUiHandler extends AbstractSettingsUiUiHandle } + /** + * Navigate to the left menu tab. + * + * @returns `true` indicating the navigation was successful. + */ navigateMenuLeft(): boolean { this.scene.ui.setMode(Mode.SETTINGS) return true; } + /** + * Navigate to the right menu tab. + * + * @returns `true` indicating the navigation was successful. + */ navigateMenuRight(): boolean { this.scene.ui.setMode(Mode.SETTINGS_KEYBOARD) return true; } + /** + * Update the display of the chosen gamepad. + */ updateChosenGamepadDisplay(): void { // Update any bindings that might have changed since the last update. this.updateBindings(); @@ -95,6 +139,12 @@ export default class SettingsGamepadUiHandler extends AbstractSettingsUiUiHandle } } + /** + * Save the setting to local storage. + * + * @param setting - The setting to save. + * @param cursor - The cursor position to save. + */ saveSettingToLocalStorage(setting, cursor): void { if (this.settingDevice[setting] !== this.settingDevice.Default_Controller) this.scene.gameData.saveGamepadSetting(setting, cursor) diff --git a/src/ui/settings/settings-keyboard-ui-handler.ts b/src/ui/settings/settings-keyboard-ui-handler.ts index 38b5b63fec6..8e34abaae5e 100644 --- a/src/ui/settings/settings-keyboard-ui-handler.ts +++ b/src/ui/settings/settings-keyboard-ui-handler.ts @@ -9,8 +9,18 @@ import {addTextObject, TextStyle} from "#app/ui/text"; import {deleteBind} from "#app/configs/configHandler"; import {Device} from "#app/enums/devices"; - +/** + * Class representing the settings UI handler for keyboards. + * + * @extends AbstractSettingsUiUiHandler + */ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandler { + /** + * Creates an instance of SettingsKeyboardUiHandler. + * + * @param scene - The BattleScene instance. + * @param mode - The UI mode, optional. + */ constructor(scene: BattleScene, mode?: Mode) { super(scene, mode); this.titleSelected = 'Keyboard'; @@ -26,6 +36,9 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl deleteEvent.on('up', this.onDeleteDown, this); } + /** + * Setup UI elements. + */ setup() { super.setup(); // If no gamepads are detected, set up a default UI prompt in the settings container. @@ -42,6 +55,9 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl this.layout['noKeyboard'].label = label; } + /** + * Handle the delete key press event. + */ onDeleteDown(): void { const cursor = this.cursor + this.scrollCursor; // Calculate the absolute cursor position. const selection = this.settingLabels[cursor].text; @@ -53,16 +69,32 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl this.updateBindings(); } + /** + * Get the active configuration. + * + * @returns The active keyboard configuration. + */ getActiveConfig(): InterfaceConfig { return this.scene.inputController.getActiveConfig(Device.KEYBOARD); } + /** + * Get the keyboard settings from local storage. + * + * @returns The keyboard settings from local storage. + */ getLocalStorageSetting(): object { // Retrieve the gamepad settings from local storage or use an empty object if none exist. const settings: object = localStorage.hasOwnProperty('settingsKeyboard') ? JSON.parse(localStorage.getItem('settingsKeyboard')) : {}; return settings; } + /** + * Set the layout for the active configuration. + * + * @param activeConfig - The active keyboard configuration. + * @returns `true` if the layout was successfully applied, otherwise `false`. + */ setLayout(activeConfig: InterfaceConfig): boolean { // Check if there is no active configuration (e.g., no gamepad connected). if (!activeConfig) { @@ -77,16 +109,29 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl return super.setLayout(activeConfig); } + /** + * Navigate to the left menu tab. + * + * @returns `true` indicating the navigation was successful. + */ navigateMenuLeft(): boolean { this.scene.ui.setMode(Mode.SETTINGS_GAMEPAD) return true; } + /** + * Navigate to the right menu tab. + * + * @returns `true` indicating the navigation was successful. + */ navigateMenuRight(): boolean { this.scene.ui.setMode(Mode.SETTINGS) return true; } + /** + * Update the display of the chosen keyboard layout. + */ updateChosenKeyboardDisplay(): void { // Update any bindings that might have changed since the last update. this.updateBindings(); @@ -109,10 +154,21 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl } + /** + * Save the custom keyboard mapping to local storage. + * + * @param config - The configuration to save. + */ saveCustomKeyboardMappingToLocalStorage(config): void { this.scene.gameData.saveMappingConfigs(this.scene.inputController?.selectedDevice[Device.KEYBOARD], config); } + /** + * Save the setting to local storage. + * + * @param settingName - The name of the setting to save. + * @param cursor - The cursor position to save. + */ saveSettingToLocalStorage(settingName, cursor): void { if (this.settingDevice[settingName] !== this.settingDevice.Default_Layout) this.scene.gameData.saveKeyboardSetting(settingName, cursor)