UNPKG

contro-max

Version:

Game controls done in the best possible way!

42 lines (41 loc) 1.58 kB
export const getMovementKeysGroup = (group) => { const wasdKeys = [...'WASD'].map(key => letterKeyToKeyCode(key)); const arrowKeys = ['ArrowUp', 'ArrowLeft', 'ArrowDown', 'ArrowRight']; switch (group) { case 'WASD': return wasdKeys; case 'Arrows': return arrowKeys; case 'WASDArrows': return [...wasdKeys, ...arrowKeys]; default: throw new Error('Unreachable'); } }; // TODO find alternative export const letterKeyToKeyCode = (letter) => `Key${letter}`; /** @index */ export const keysGroup = (group) => { switch (group) { case 'Arrows': // the same order as for WASD return ['ArrowUp', 'ArrowLeft', 'ArrowDown', 'ArrowRight']; case 'PageMoveKeys': return ['PageDown', 'PageUp']; case 'WASD': return ['KeyW', 'KeyA', 'KeyS', 'KeyD']; case 'Digits': return Array.from({ length: 10 }, (_, i) => `Digit${i}`); case 'NumpadDigits': return Array.from({ length: 10 }, (_, i) => `Numpad${i}`); case 'AnyDigits': return Array.from({ length: 10 }, (_, i) => [`Digit${i}`, `Numpad${i}`]).flat(1); case 'FKeys': return Array.from({ length: 24 }, (_, i) => `F${i + 1}`); case 'Modifiers': return ['Shift', 'Control', 'Alt', 'Meta'].flatMap(key => ['Left', 'Right'].map(side => `${key}${side}`)); default: throw new Error('Unreachable'); } }; export const createCombinedGroup = (groups) => { };