import { buttonIndexes } from './gamepad/controlMap'; import ButtonInputControl, { ButtonInputControlOptions } from '../controls/ButtonInputControl'; import StickInputControl, { StickInputControlOptions } from '../controls/StickInputControl'; import AxisInputControl from '../controls/AxisInputControl'; import { InputControlOptions } from '../controls/InputControl'; import { DeviceEvents, PollingDevice, ThrottledDeviceOptions } from '../Device'; import { WildcardHandler } from 'mitt'; type GamepadEvents = DeviceEvents & { connected: undefined; disconnected: undefined; }; export interface GamepadOptions extends ThrottledDeviceOptions { index?: number; } /** * Emitted when a Gamepad device is connected. * @event */ export type OnConnected = () => void; /** * Available options depend on which control is requested. */ export type GamepadGetControlOptions = Omit, 'device' | 'children'>; /** * A Device driven by the [Web Gamepad API](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API). * * Currently a [Standard Gamepad mapping](https://w3c.github.io/gamepad/#dfn-standard-gamepad) is assumed. * * Note that since the Gamepad API does not currently support change events, * this is a polling device and therefore requires calling `.update()` repeatedly * to update values and emit change events. */ export default class Gamepad extends PollingDevice { getControl: { /** Two-dimensional stick inputs */ (name: 'leftStick' | 'rightStick', options?: GamepadGetControlOptions): StickInputControl; /** One-dimensional, single axis of each stick */ (name: 'leftStickX' | 'leftStickY' | 'rightStickX' | 'rightStickY', options?: GamepadGetControlOptions): AxisInputControl; /** Buttons. Some provide partial, "analog" values while others are either pressed or not. */ (name: keyof typeof buttonIndexes, options?: GamepadGetControlOptions): ButtonInputControl; }; /** [Gamepad API](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad) object */ readonly device: globalThis.Gamepad; /** * A string containing some information about the controller, provided * by the browser. Empty if no Gamepad device has been connected. */ readonly id: string; /** * returns an Iterable of available control names. */ controls: () => IterableIterator; on: { /** * Emitted when the Gamepad device is connected. * @event */ (type: 'connected', handler: OnConnected): void; /** * Emitted when the Gamepad device is disconnected. * @event */ (type: 'disconnected', handler: () => void): void; /** * Emitted when any value changes. * @event */ (type: 'change', handler: () => void): void; (type: '*', handler: WildcardHandler): void; }; constructor(options?: GamepadOptions); } export {};