2024-05-11 05:31:48 -07:00
|
|
|
import {GamepadConfig} from "../inputs-controller";
|
2024-05-11 05:51:01 -07:00
|
|
|
import {SettingGamepad} from "#app/system/settings-gamepad";
|
2024-05-11 08:54:34 -07:00
|
|
|
import {Button} from "#app/enums/buttons";
|
2024-05-11 05:31:48 -07:00
|
|
|
|
|
|
|
|
2024-05-11 06:43:38 -07:00
|
|
|
export function getKeyForButtonIndex(config: GamepadConfig, index: number): String {
|
2024-05-11 05:31:48 -07:00
|
|
|
for (const key of Object.keys(config.gamepadMapping)) {
|
|
|
|
const id = config.gamepadMapping[key];
|
|
|
|
if (id === index) return key;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2024-05-11 06:43:38 -07:00
|
|
|
export function getButtonIndexForKey(config: GamepadConfig, _key: string): number {
|
|
|
|
for (const key of Object.keys(config.gamepadMapping)) {
|
|
|
|
if (key === _key) return config.gamepadMapping[key];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2024-05-11 05:31:48 -07:00
|
|
|
|
2024-05-11 06:43:38 -07:00
|
|
|
export function getIconForCustomIndex(config: GamepadConfig, index: number): String {
|
2024-05-11 05:31:48 -07:00
|
|
|
const key = getKeyForButtonIndex(config, index);
|
|
|
|
return config.icons[key];
|
2024-05-11 05:51:01 -07:00
|
|
|
}
|
|
|
|
|
2024-05-11 08:54:34 -07:00
|
|
|
export function getKeyForRebindedAction(config: GamepadConfig, action: Button): String {
|
|
|
|
for (const key of Object.keys(config.default)) {
|
|
|
|
if (config.default[key] === action) return key;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-05-11 09:42:32 -07:00
|
|
|
export function getKeyForAction(config: GamepadConfig, action: Button): String {
|
|
|
|
for (const key of Object.keys(config.custom)) {
|
|
|
|
if (config.custom[key] === action) return key;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-05-11 08:54:34 -07:00
|
|
|
export function getKeyForRebindedSettingName(config: GamepadConfig, settingName: SettingGamepad): String {
|
|
|
|
const oldKey = getKeyForSettingName(config, settingName)
|
|
|
|
const action = config.custom[oldKey];
|
2024-05-11 09:42:32 -07:00
|
|
|
const key = getKeyForRebindedAction(config, action);
|
|
|
|
return key;
|
2024-05-11 08:54:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getIconForRebindedKey(config: GamepadConfig, _key): String {
|
|
|
|
const action = config.custom[_key];
|
|
|
|
const key = getKeyForRebindedAction(config, action);
|
|
|
|
return config.icons[key];
|
|
|
|
}
|
|
|
|
|
2024-05-11 05:51:01 -07:00
|
|
|
export function getKeyForSettingName(config: GamepadConfig, settingName: SettingGamepad) {
|
|
|
|
for (const key of Object.keys(config.setting)) {
|
|
|
|
const name = config.setting[key];
|
|
|
|
if (name === settingName) return key;
|
|
|
|
}
|
|
|
|
return null;
|
2024-05-11 06:43:38 -07:00
|
|
|
}
|
2024-05-11 09:42:32 -07:00
|
|
|
|
|
|
|
export function getIconForSettingName(config: GamepadConfig, settingName: SettingGamepad) {
|
|
|
|
const key = getKeyForSettingName(config, settingName);
|
|
|
|
const action = config.default[key];
|
|
|
|
const rebindedKey = getKeyForAction(config, action);
|
|
|
|
return config.icons[rebindedKey];
|
|
|
|
}
|