Comparing version 0.1.6 to 0.1.7
@@ -40,3 +40,3 @@ import { mapValues } from 'lodash-es'; | ||
keys: [], | ||
gamepadButtons: [], | ||
gamepad: [], | ||
}; | ||
@@ -53,3 +53,3 @@ if (inputCommand === null) | ||
if (typeof args[1] === 'string') | ||
resolvedCommand.gamepadButtons = [args[1]]; | ||
resolvedCommand.gamepad = [args[1]]; | ||
return resolvedCommand; | ||
@@ -119,3 +119,3 @@ })), | ||
for (const [name, command] of Object.entries(section)) { | ||
let { keys, disabled, gamepadButtons, preventDefault } = command; | ||
let { keys, disabled, gamepad, preventDefault } = command; | ||
const userOverride = resolvedSchema?.[sectionName]?.[name]; | ||
@@ -125,3 +125,3 @@ if (userOverride?.keys) | ||
if (userOverride?.gamepad) | ||
gamepadButtons = userOverride.gamepad; | ||
gamepad = userOverride.gamepad; | ||
if ('code' in codeOrButton) { | ||
@@ -131,3 +131,3 @@ if (!keys.includes(codeOrButton.code)) | ||
} | ||
else if (!gamepadButtons.includes(codeOrButton.button)) { | ||
else if (!gamepad.includes(codeOrButton.button)) { | ||
continue; | ||
@@ -144,3 +144,3 @@ } | ||
for (const [name, groupedCommand] of Object.entries(section)) { | ||
const [keyboard, gamepadButtons, options = {}] = groupedCommand; | ||
const [keyboard, gamepad, options = {}] = groupedCommand; | ||
const emitData = { | ||
@@ -162,3 +162,3 @@ command: `${sectionName}.${name}`, | ||
else { | ||
const buttonIndex = gamepadButtons.indexOf(codeOrButton.button); | ||
const buttonIndex = gamepad.indexOf(codeOrButton.button); | ||
if (buttonIndex === -1) | ||
@@ -170,3 +170,3 @@ continue; | ||
gamepadIndex: codeOrButton.gamepadIndex, | ||
key: gamepadButtons[buttonIndex], | ||
key: gamepad[buttonIndex], | ||
}); | ||
@@ -212,2 +212,7 @@ } | ||
}; | ||
const mouseEvent = (e) => { | ||
const { button } = e; | ||
const mousedownEvent = e.type === 'mousedown'; | ||
this.pressedKeyOrButtonChanged({ code: 'Mouse' + button }, mousedownEvent, { preventDefault: () => e.preventDefault() }); | ||
}; | ||
// BIND EVENTS | ||
@@ -217,2 +222,4 @@ bindEventListeners(target, { | ||
keyup: keyboardEvent, | ||
mousedown: mouseEvent, | ||
mouseup: mouseEvent, | ||
}); | ||
@@ -219,0 +226,0 @@ const visibilitychangeListener = () => { |
@@ -18,3 +18,3 @@ import { LiteralUnion } from 'type-fest'; | ||
keys: AllKeyCodes[]; | ||
gamepadButtons: GamepadButtonName[]; | ||
gamepad: GamepadButtonName[]; | ||
}; | ||
@@ -21,0 +21,0 @@ export type KeysGroup = 'WASD' | 'Arrows' | 'Digits' | 'NumpadDigits' | 'AnyDigits' | 'Modifiers' | 'FKeys' | 'PageMoveKeys'; |
@@ -9,5 +9,6 @@ type SingleNumber = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; | ||
type LetterKey = `Key${Capitalize<'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z'>}`; | ||
type AllKeyCodesWithoutModifiers = `${DigitKeys}` | LetterKey | `F${Fnumbers}` | NumpadKeys | OtherKeys; | ||
type MouseSideKeys = `Mouse${0 | 1 | 2 | 3 | 4}`; | ||
type AllKeyCodesWithoutModifiers = `${DigitKeys}` | LetterKey | `F${Fnumbers}` | NumpadKeys | OtherKeys | MouseSideKeys; | ||
export type AllKeyCodes = `${ModifierOnlyKeys}` | AllKeyCodesWithoutModifiers; | ||
export type AllKeyCodesWithModifiers = `${AllKeyCodes}` | `${ModifierOnlyKeys}+${AllKeyCodesWithoutModifiers}`; | ||
export {}; |
{ | ||
"name": "contro-max", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Game controls done in the best possible way!", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
49051
952