pokerogue/test/setting-menu/helpers/menu-manip.ts
Bertie690 19730f9cf0
[Misc] Moved + cleaned up string manipulation functions (#6112)
* Added string utility package to replace util functions

* Changed string manipulation functions fully over to `change-case`

* Fixed missing comma in package.json

trailing commas when :(

* fixed lockfile

* Hopefully re-added all the string utils

* fixed package json

* Fixed remaining cases of regex + code dupliation

* Fixed more bugs and errors

* Moved around functions and hopefully fixed the regex issues

* Minor renaming

* Fixed incorrect casing on setting strings

pascal snake case 💀

* ran biome
2025-07-27 13:59:03 -07:00

138 lines
3.7 KiB
TypeScript

import {
assign,
canIAssignThisKey,
canIDeleteThisKey,
canIOverrideThisSetting,
deleteBind,
getIconWithKeycode,
getIconWithSettingName,
getKeyWithKeycode,
getKeyWithSettingName,
getSettingNameWithKeycode,
} from "#inputs/config-handler";
import { SettingKeyboard } from "#system/settings-keyboard";
import { expect } from "vitest";
export class MenuManip {
private config;
private settingName;
private keycode;
private icon;
private iconDisplayed;
private specialCaseIcon;
constructor(config) {
this.config = config;
this.settingName = null;
this.icon = null;
this.iconDisplayed = null;
this.specialCaseIcon = null;
}
// TODO: Review this
convertNameToButtonString(input) {
// Check if the input starts with "Alt_Button"
if (input.startsWith("Alt_Button")) {
// Return the last part in uppercase
return input.split("_").pop().toUpperCase();
}
// Split the input string by underscore
const parts = input.split("_");
// Skip the first part and join the rest with an underscore
const result = parts
.slice(1)
.map(part => part.toUpperCase())
.join("_");
return result;
}
whenCursorIsOnSetting(settingName) {
if (!settingName.includes("Button_")) {
settingName = "Button_" + settingName;
}
this.settingName = SettingKeyboard[settingName];
return this;
}
iconDisplayedIs(icon) {
if (!icon.toUpperCase().includes("KEY_")) {
icon = "KEY_" + icon.toUpperCase();
}
this.iconDisplayed = this.config.icons[icon];
expect(getIconWithSettingName(this.config, this.settingName)).toEqual(this.iconDisplayed);
return this;
}
thereShouldBeNoIconAnymore() {
const icon = getIconWithSettingName(this.config, this.settingName);
expect(icon === undefined).toEqual(true);
return this;
}
thereShouldBeNoIcon() {
return this.thereShouldBeNoIconAnymore();
}
nothingShouldHappen() {
const settingName = getSettingNameWithKeycode(this.config, this.keycode);
expect(settingName).toEqual(-1);
return this;
}
weWantThisBindInstead(keycode) {
this.keycode = Phaser.Input.Keyboard.KeyCodes[keycode];
const icon = getIconWithKeycode(this.config, this.keycode);
const key = getKeyWithKeycode(this.config, this.keycode)!; // TODO: is this bang correct?
const _keys = key.toLowerCase().split("_");
const iconIdentifier = _keys[_keys.length - 1];
expect(icon.toLowerCase().includes(iconIdentifier)).toEqual(true);
return this;
}
whenWeDelete(settingName?: string) {
this.settingName = settingName ? SettingKeyboard[settingName] : this.settingName;
// const key = getKeyWithSettingName(this.config, this.settingName);
deleteBind(this.config, this.settingName);
// expect(this.config.custom[key]).toEqual(-1);
return this;
}
whenWeTryToDelete(settingName?: string) {
this.settingName = settingName ? SettingKeyboard[settingName] : this.settingName;
deleteBind(this.config, this.settingName);
return this;
}
confirmAssignment() {
assign(this.config, this.settingName, this.keycode);
}
butLetsForceIt() {
this.confirm();
}
confirm() {
assign(this.config, this.settingName, this.keycode);
}
weCantAssignThisKey() {
const key = getKeyWithKeycode(this.config, this.keycode);
expect(canIAssignThisKey(this.config, key)).toEqual(false);
return this;
}
weCantOverrideThisBind() {
expect(canIOverrideThisSetting(this.config, this.settingName)).toEqual(false);
return this;
}
weCantDelete() {
const key = getKeyWithSettingName(this.config, this.settingName);
expect(canIDeleteThisKey(this.config, key)).toEqual(false);
return this;
}
}