mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-16 21:32:18 +02:00
comment TSDOC settings
This commit is contained in:
parent
ed860167d0
commit
de1bf3d855
@ -9,8 +9,20 @@ import {InterfaceConfig} from "#app/inputs-controller";
|
|||||||
import AbstractSettingsUiUiHandler from "#app/ui/settings/abstract-settings-ui-handler";
|
import AbstractSettingsUiUiHandler from "#app/ui/settings/abstract-settings-ui-handler";
|
||||||
import {Device} from "#app/enums/devices";
|
import {Device} from "#app/enums/devices";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class representing the settings UI handler for gamepads.
|
||||||
|
*
|
||||||
|
* @extends AbstractSettingsUiUiHandler
|
||||||
|
*/
|
||||||
|
|
||||||
export default class SettingsGamepadUiHandler 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) {
|
constructor(scene: BattleScene, mode?: Mode) {
|
||||||
super(scene, mode);
|
super(scene, mode);
|
||||||
this.titleSelected = 'Gamepad';
|
this.titleSelected = 'Gamepad';
|
||||||
@ -22,6 +34,9 @@ export default class SettingsGamepadUiHandler extends AbstractSettingsUiUiHandle
|
|||||||
this.localStoragePropertyName = 'settingsGamepad';
|
this.localStoragePropertyName = 'settingsGamepad';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup UI elements.
|
||||||
|
*/
|
||||||
setup() {
|
setup() {
|
||||||
super.setup();
|
super.setup();
|
||||||
// If no gamepads are detected, set up a default UI prompt in the settings container.
|
// 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;
|
this.layout['noGamepads'].label = label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the active configuration.
|
||||||
|
*
|
||||||
|
* @returns The active gamepad configuration.
|
||||||
|
*/
|
||||||
getActiveConfig(): InterfaceConfig {
|
getActiveConfig(): InterfaceConfig {
|
||||||
return this.scene.inputController.getActiveConfig(Device.GAMEPAD);
|
return this.scene.inputController.getActiveConfig(Device.GAMEPAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the gamepad settings from local storage.
|
||||||
|
*
|
||||||
|
* @returns The gamepad settings from local storage.
|
||||||
|
*/
|
||||||
getLocalStorageSetting(): object {
|
getLocalStorageSetting(): object {
|
||||||
// Retrieve the gamepad settings from local storage or use an empty object if none exist.
|
// 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')) : {};
|
const settings: object = localStorage.hasOwnProperty('settingsGamepad') ? JSON.parse(localStorage.getItem('settingsGamepad')) : {};
|
||||||
return settings;
|
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 {
|
setLayout(activeConfig: InterfaceConfig): boolean {
|
||||||
// Check if there is no active configuration (e.g., no gamepad connected).
|
// Check if there is no active configuration (e.g., no gamepad connected).
|
||||||
if (!activeConfig) {
|
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 {
|
navigateMenuLeft(): boolean {
|
||||||
this.scene.ui.setMode(Mode.SETTINGS)
|
this.scene.ui.setMode(Mode.SETTINGS)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Navigate to the right menu tab.
|
||||||
|
*
|
||||||
|
* @returns `true` indicating the navigation was successful.
|
||||||
|
*/
|
||||||
navigateMenuRight(): boolean {
|
navigateMenuRight(): boolean {
|
||||||
this.scene.ui.setMode(Mode.SETTINGS_KEYBOARD)
|
this.scene.ui.setMode(Mode.SETTINGS_KEYBOARD)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the display of the chosen gamepad.
|
||||||
|
*/
|
||||||
updateChosenGamepadDisplay(): void {
|
updateChosenGamepadDisplay(): void {
|
||||||
// Update any bindings that might have changed since the last update.
|
// Update any bindings that might have changed since the last update.
|
||||||
this.updateBindings();
|
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 {
|
saveSettingToLocalStorage(setting, cursor): void {
|
||||||
if (this.settingDevice[setting] !== this.settingDevice.Default_Controller)
|
if (this.settingDevice[setting] !== this.settingDevice.Default_Controller)
|
||||||
this.scene.gameData.saveGamepadSetting(setting, cursor)
|
this.scene.gameData.saveGamepadSetting(setting, cursor)
|
||||||
|
@ -9,8 +9,18 @@ import {addTextObject, TextStyle} from "#app/ui/text";
|
|||||||
import {deleteBind} from "#app/configs/configHandler";
|
import {deleteBind} from "#app/configs/configHandler";
|
||||||
import {Device} from "#app/enums/devices";
|
import {Device} from "#app/enums/devices";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class representing the settings UI handler for keyboards.
|
||||||
|
*
|
||||||
|
* @extends AbstractSettingsUiUiHandler
|
||||||
|
*/
|
||||||
export default class SettingsKeyboardUiHandler 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) {
|
constructor(scene: BattleScene, mode?: Mode) {
|
||||||
super(scene, mode);
|
super(scene, mode);
|
||||||
this.titleSelected = 'Keyboard';
|
this.titleSelected = 'Keyboard';
|
||||||
@ -26,6 +36,9 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl
|
|||||||
deleteEvent.on('up', this.onDeleteDown, this);
|
deleteEvent.on('up', this.onDeleteDown, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup UI elements.
|
||||||
|
*/
|
||||||
setup() {
|
setup() {
|
||||||
super.setup();
|
super.setup();
|
||||||
// If no gamepads are detected, set up a default UI prompt in the settings container.
|
// 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;
|
this.layout['noKeyboard'].label = label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the delete key press event.
|
||||||
|
*/
|
||||||
onDeleteDown(): void {
|
onDeleteDown(): void {
|
||||||
const cursor = this.cursor + this.scrollCursor; // Calculate the absolute cursor position.
|
const cursor = this.cursor + this.scrollCursor; // Calculate the absolute cursor position.
|
||||||
const selection = this.settingLabels[cursor].text;
|
const selection = this.settingLabels[cursor].text;
|
||||||
@ -53,16 +69,32 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl
|
|||||||
this.updateBindings();
|
this.updateBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the active configuration.
|
||||||
|
*
|
||||||
|
* @returns The active keyboard configuration.
|
||||||
|
*/
|
||||||
getActiveConfig(): InterfaceConfig {
|
getActiveConfig(): InterfaceConfig {
|
||||||
return this.scene.inputController.getActiveConfig(Device.KEYBOARD);
|
return this.scene.inputController.getActiveConfig(Device.KEYBOARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the keyboard settings from local storage.
|
||||||
|
*
|
||||||
|
* @returns The keyboard settings from local storage.
|
||||||
|
*/
|
||||||
getLocalStorageSetting(): object {
|
getLocalStorageSetting(): object {
|
||||||
// Retrieve the gamepad settings from local storage or use an empty object if none exist.
|
// 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')) : {};
|
const settings: object = localStorage.hasOwnProperty('settingsKeyboard') ? JSON.parse(localStorage.getItem('settingsKeyboard')) : {};
|
||||||
return settings;
|
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 {
|
setLayout(activeConfig: InterfaceConfig): boolean {
|
||||||
// Check if there is no active configuration (e.g., no gamepad connected).
|
// Check if there is no active configuration (e.g., no gamepad connected).
|
||||||
if (!activeConfig) {
|
if (!activeConfig) {
|
||||||
@ -77,16 +109,29 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl
|
|||||||
return super.setLayout(activeConfig);
|
return super.setLayout(activeConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Navigate to the left menu tab.
|
||||||
|
*
|
||||||
|
* @returns `true` indicating the navigation was successful.
|
||||||
|
*/
|
||||||
navigateMenuLeft(): boolean {
|
navigateMenuLeft(): boolean {
|
||||||
this.scene.ui.setMode(Mode.SETTINGS_GAMEPAD)
|
this.scene.ui.setMode(Mode.SETTINGS_GAMEPAD)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Navigate to the right menu tab.
|
||||||
|
*
|
||||||
|
* @returns `true` indicating the navigation was successful.
|
||||||
|
*/
|
||||||
navigateMenuRight(): boolean {
|
navigateMenuRight(): boolean {
|
||||||
this.scene.ui.setMode(Mode.SETTINGS)
|
this.scene.ui.setMode(Mode.SETTINGS)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the display of the chosen keyboard layout.
|
||||||
|
*/
|
||||||
updateChosenKeyboardDisplay(): void {
|
updateChosenKeyboardDisplay(): void {
|
||||||
// Update any bindings that might have changed since the last update.
|
// Update any bindings that might have changed since the last update.
|
||||||
this.updateBindings();
|
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 {
|
saveCustomKeyboardMappingToLocalStorage(config): void {
|
||||||
this.scene.gameData.saveMappingConfigs(this.scene.inputController?.selectedDevice[Device.KEYBOARD], config);
|
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 {
|
saveSettingToLocalStorage(settingName, cursor): void {
|
||||||
if (this.settingDevice[settingName] !== this.settingDevice.Default_Layout)
|
if (this.settingDevice[settingName] !== this.settingDevice.Default_Layout)
|
||||||
this.scene.gameData.saveKeyboardSetting(settingName, cursor)
|
this.scene.gameData.saveKeyboardSetting(settingName, cursor)
|
||||||
|
Loading…
Reference in New Issue
Block a user