mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-15 21:02:18 +02:00
comment TSDOC utils.ts
This commit is contained in:
parent
de1bf3d855
commit
1d3418a4f8
@ -121,7 +121,7 @@ export function setSettingGamepad(scene: BattleScene, setting: SettingGamepad, v
|
||||
};
|
||||
scene.ui.setOverlayMode(Mode.OPTION_SELECT, {
|
||||
options: [...gp.map((g) => ({
|
||||
label: truncateString(g, 30), // Truncate the gamepad name for display
|
||||
label: truncateString(g, 22), // Truncate the gamepad name for display
|
||||
handler: () => changeGamepadHandler(g)
|
||||
})), {
|
||||
label: 'Cancel',
|
||||
|
@ -147,7 +147,7 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl
|
||||
if (_key === 'noKeyboard') continue; // Skip updating the no gamepad layout.
|
||||
// Update the text of the first option label under the current setting to the name of the chosen gamepad,
|
||||
// truncating the name to 30 characters if necessary.
|
||||
this.layout[_key].optionValueLabels[index][0].setText(truncateString(this.scene.inputController.selectedDevice[Device.KEYBOARD], 30));
|
||||
this.layout[_key].optionValueLabels[index][0].setText(truncateString(this.scene.inputController.selectedDevice[Device.KEYBOARD], 22));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
26
src/utils.ts
26
src/utils.ts
@ -336,19 +336,45 @@ export function rgbaToInt(rgba: integer[]): integer {
|
||||
return (rgba[0] << 24) + (rgba[1] << 16) + (rgba[2] << 8) + rgba[3];
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate a string to a specified maximum length and add an ellipsis if it exceeds that length.
|
||||
*
|
||||
* @param str - The string to be truncated.
|
||||
* @param maxLength - The maximum length of the truncated string, defaults to 10.
|
||||
* @returns The truncated string with an ellipsis if it was longer than maxLength.
|
||||
*/
|
||||
export function truncateString(str: String, maxLength: number = 10) {
|
||||
// Check if the string length exceeds the maximum length
|
||||
if (str.length > maxLength) {
|
||||
// Truncate the string and add an ellipsis
|
||||
return str.slice(0, maxLength - 3) + "..."; // Subtract 3 to accommodate the ellipsis
|
||||
}
|
||||
// Return the original string if it does not exceed the maximum length
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a deep copy of an object.
|
||||
*
|
||||
* @param values - The object to be deep copied.
|
||||
* @returns A new object that is a deep copy of the input.
|
||||
*/
|
||||
export function deepCopy(values: object): object {
|
||||
// Convert the object to a JSON string and parse it back to an object to perform a deep copy
|
||||
return JSON.parse(JSON.stringify(values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a space-separated string into a capitalized and underscored string.
|
||||
*
|
||||
* @param input - The string to be converted.
|
||||
* @returns The converted string with words capitalized and separated by underscores.
|
||||
*/
|
||||
export function reverseValueToKeySetting(input) {
|
||||
// Split the input string into an array of words
|
||||
const words = input.split(' ');
|
||||
// Capitalize the first letter of each word and convert the rest to lowercase
|
||||
const capitalizedWords = words.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase());
|
||||
// Join the capitalized words with underscores and return the result
|
||||
return capitalizedWords.join('_');
|
||||
}
|
Loading…
Reference in New Issue
Block a user