mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-12-14 05:45:20 +01:00
* Added more biome rules * Fixes * Added a few more rules * Added global phaser to biome * Fix tpyo * Updated biome to 2.1.4; improved docs on linting/localization; added vcs support Also added `.build` to gitignore cuz reasons * Fixed tpyo * dd * Applied linter fixes * Partially fixed some private property issues * Upgraded to Biome 2.2.0; added `operatorLinebreak` and a few new rules * Moved operator linebreaks before lines * Applied kev's suggestions * Update biome.jsonc Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * added like all the rules and then some * modify biome.jsonc * apply biome formatting * Reverted changes to balance folder * fixed stuff * Fixed biome stripping trailing globstars from everything * made `noInvertedElse` an error rule * Add & apply fixes for `useExplicitLengthCheck`, `useAtIndex` and `noNonNullAssertedOptionalChain` * Bumped biome to 2.2.3 * Fixed a few syntax errors * Removed trailing globstars since biome actually fixed their shit * Final clean up * foobarbaz * Fixed remaining issues * Fixed a few errors in SSUI * fixed rounding issue * Fixed test to not round funky * Fixed biome false positive for vitest hooks * Apply biome:all --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com>
221 lines
6.8 KiB
TypeScript
221 lines
6.8 KiB
TypeScript
import { Device } from "#enums/devices";
|
|
|
|
/**
|
|
* Retrieves the key associated with the specified keycode from the mapping.
|
|
*
|
|
* @param config - The configuration object containing the mapping.
|
|
* @param keycode - The keycode to search for.
|
|
* @returns The key associated with the specified keycode.
|
|
*/
|
|
export function getKeyWithKeycode(config, keycode) {
|
|
return Object.keys(config.deviceMapping).find(key => config.deviceMapping[key] === keycode);
|
|
}
|
|
|
|
/**
|
|
* Retrieves the setting name associated with the specified keycode.
|
|
*
|
|
* @param config - The configuration object containing custom settings.
|
|
* @param keycode - The keycode to search for.
|
|
* @returns The setting name associated with the specified keycode.
|
|
*/
|
|
export function getSettingNameWithKeycode(config, keycode) {
|
|
const key = getKeyWithKeycode(config, keycode);
|
|
return key ? config.custom[key] : null;
|
|
}
|
|
|
|
/**
|
|
* Retrieves the icon associated with the specified keycode.
|
|
*
|
|
* @param config - The configuration object containing icons.
|
|
* @param keycode - The keycode to search for.
|
|
* @returns The icon associated with the specified keycode.
|
|
*/
|
|
export function getIconWithKeycode(config, keycode) {
|
|
const key = getKeyWithKeycode(config, keycode);
|
|
return key ? config.icons[key] : null;
|
|
}
|
|
|
|
/**
|
|
* Retrieves the button associated with the specified keycode.
|
|
*
|
|
* @param config - The configuration object containing settings.
|
|
* @param keycode - The keycode to search for.
|
|
* @returns The button associated with the specified keycode.
|
|
*/
|
|
export function getButtonWithKeycode(config, keycode) {
|
|
const settingName = getSettingNameWithKeycode(config, keycode);
|
|
return config.settings[settingName];
|
|
}
|
|
|
|
/**
|
|
* Retrieves the key associated with the specified setting name.
|
|
*
|
|
* @param config - The configuration object containing custom settings.
|
|
* @param settingName - The setting name to search for.
|
|
* @returns The key associated with the specified setting name.
|
|
*/
|
|
export function getKeyWithSettingName(config, settingName) {
|
|
return Object.keys(config.custom).find(key => config.custom[key] === settingName);
|
|
}
|
|
|
|
/**
|
|
* Retrieves the setting name associated with the specified key.
|
|
*
|
|
* @param config - The configuration object containing custom settings.
|
|
* @param key - The key to search for.
|
|
* @returns The setting name associated with the specified key.
|
|
*/
|
|
export function getSettingNameWithKey(config, key) {
|
|
return config.custom[key];
|
|
}
|
|
|
|
/**
|
|
* Retrieves the icon associated with the specified key.
|
|
*
|
|
* @param config - The configuration object containing icons.
|
|
* @param key - The key to search for.
|
|
* @returns The icon associated with the specified key.
|
|
*/
|
|
export function getIconWithKey(config, key) {
|
|
return config.icons[key];
|
|
}
|
|
|
|
/**
|
|
* Retrieves the icon associated with the specified setting name.
|
|
*
|
|
* @param config - The configuration object containing icons.
|
|
* @param settingName - The setting name to search for.
|
|
* @returns The icon associated with the specified setting name.
|
|
*/
|
|
export function getIconWithSettingName(config, settingName) {
|
|
const key = getKeyWithSettingName(config, settingName);
|
|
return getIconWithKey(config, key);
|
|
}
|
|
|
|
export function getIconForLatestInput(configs, source, devices, settingName) {
|
|
let config: any; // TODO: refine type
|
|
if (source === "gamepad") {
|
|
config = configs[devices[Device.GAMEPAD]];
|
|
} else {
|
|
config = configs[devices[Device.KEYBOARD]];
|
|
}
|
|
const icon = getIconWithSettingName(config, settingName);
|
|
if (!icon) {
|
|
const isAlt = settingName.includes("ALT_");
|
|
let altSettingName: string;
|
|
if (isAlt) {
|
|
altSettingName = settingName.split("ALT_").splice(1)[0];
|
|
} else {
|
|
altSettingName = `ALT_${settingName}`;
|
|
}
|
|
return getIconWithSettingName(config, altSettingName);
|
|
}
|
|
return icon;
|
|
}
|
|
|
|
export function assign(config, settingNameTarget, keycode): boolean {
|
|
// first, we need to check if this keycode is already used on another settingName
|
|
if (
|
|
!canIAssignThisKey(config, getKeyWithKeycode(config, keycode))
|
|
|| !canIOverrideThisSetting(config, settingNameTarget)
|
|
) {
|
|
return false;
|
|
}
|
|
const previousSettingName = getSettingNameWithKeycode(config, keycode);
|
|
// if it was already bound, we delete the bind
|
|
if (previousSettingName) {
|
|
const previousKey = getKeyWithSettingName(config, previousSettingName);
|
|
if (previousKey) {
|
|
config.custom[previousKey] = -1;
|
|
}
|
|
}
|
|
// then, we need to delete the current key for this settingName
|
|
const currentKey = getKeyWithSettingName(config, settingNameTarget);
|
|
if (currentKey) {
|
|
config.custom[currentKey] = -1;
|
|
}
|
|
|
|
// then, the new key is assigned to the new settingName
|
|
const newKey = getKeyWithKeycode(config, keycode);
|
|
if (newKey) {
|
|
config.custom[newKey] = settingNameTarget;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
export function swap(config, settingNameTarget, keycode) {
|
|
// only for gamepad
|
|
if (config.padType === "keyboard") {
|
|
return false;
|
|
}
|
|
const prev_key = getKeyWithSettingName(config, settingNameTarget);
|
|
const prev_settingName = getSettingNameWithKey(config, prev_key);
|
|
|
|
const new_key = getKeyWithKeycode(config, keycode);
|
|
const new_settingName = getSettingNameWithKey(config, new_key);
|
|
|
|
if (prev_key) {
|
|
config.custom[prev_key] = new_settingName;
|
|
}
|
|
if (new_key) {
|
|
config.custom[new_key] = prev_settingName;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Deletes the binding of the specified setting name.
|
|
*
|
|
* @param config - The configuration object containing custom settings.
|
|
* @param settingName - The setting name to delete.
|
|
*/
|
|
export function deleteBind(config, settingName) {
|
|
const key = getKeyWithSettingName(config, settingName);
|
|
if (config.blacklist.includes(key)) {
|
|
return false;
|
|
}
|
|
if (key) {
|
|
config.custom[key] = -1;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
export function canIAssignThisKey(config, key) {
|
|
const settingName = getSettingNameWithKey(config, key);
|
|
if (config.blacklist?.includes(key)) {
|
|
return false;
|
|
}
|
|
if (settingName === -1) {
|
|
return true;
|
|
}
|
|
// if (isTheLatestBind(config, settingName)) {
|
|
// return false;
|
|
// }
|
|
return true;
|
|
}
|
|
|
|
export function canIOverrideThisSetting(config, settingName) {
|
|
const key = getKeyWithSettingName(config, settingName);
|
|
// || isTheLatestBind(config, settingName) no longer needed since action and cancel are protected
|
|
return !config.blacklist?.includes(key);
|
|
}
|
|
|
|
export function canIDeleteThisKey(config, key) {
|
|
return canIAssignThisKey(config, key);
|
|
}
|
|
|
|
// export function isTheLatestBind(config, settingName) {
|
|
// if (config.padType !== "keyboard") {
|
|
// return false;
|
|
// }
|
|
// const isAlt = settingName.includes("ALT_");
|
|
// let altSettingName;
|
|
// if (isAlt) {
|
|
// altSettingName = settingName.split("ALT_").splice(1)[0];
|
|
// } else {
|
|
// altSettingName = `ALT_${settingName}`;
|
|
// }
|
|
// const secondButton = getKeyWithSettingName(config, altSettingName);
|
|
// return secondButton === undefined;
|
|
// }
|