UNPKG

contro-max

Version:

Game controls done in the best possible way!

33 lines (32 loc) 922 B
export const buttonMap = [ ['A'], ['B'], ['X'], ['Y'], ['Left Bumper', 'LB'], ['Right Bumper', 'RB'], ['Left Trigger', 'LT'], ['Right Trigger', 'RT'], ['Back', 'View'], ['Start'], ['Left Stick'], ['Right Stick'], ['Up', 'DpadUp'], ['Down', 'DpadDown'], ['Left', 'DpadLeft'], ['Right', 'DpadRight'], ['Home', 'Guide', 'Xbox'], ]; /** Find button number by button name (or number itself) */ export const findButtonNumber = (button) => { if (typeof button === 'number') return button; button = button.toLowerCase(); const buttonNumber = buttonMap.findIndex((aliases) => aliases.find(alias => button === alias.toLowerCase())); if (buttonNumber) return buttonNumber; throw new Error(`There is no gamepad button called "${button}"!`); }; export function getButtonLabel(buttonIndex) { return buttonMap[buttonIndex][0]; }