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ChB,cAAc,GACd,mBAAmB,GACnB,gBAAgB,GAChB,KAAK,GACL,SAAS,GACT,iBAAiB,CAAC;AAEpB,+BAAgC,SAAQ,YAAY;IAClD,eAAe,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7D,mBAAmB,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACjE,OAAO,EAAE,CACP,GAAG,CAAC,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,MAAM,KACZ,IAAI,CAAC;IACV,MAAM,EAAE,CACN,oBAAoB,CAAC,EAAE,MAAM,EAC7B,qBAAqB,CAAC,EAAE,MAAM,EAC9B,WAAW,CAAC,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,MAAM,KACZ,IAAI,CAAC;IACV,cAAc,EAAE,CACd,WAAW,CAAC,EAAE,MAAM,EACpB,YAAY,CAAC,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,MAAM,KACZ,IAAI,CAAC;IACV,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,EAAE,EAAE,YAAY,CAAC;CAClB;AAGD;IACE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAMD,QAAA,MAAM,iBAAiB,EAAE,cAA0D,CAAC;AAMpF,iCAAiC,OAAO,GAAE,qBAA0B,GAAG,cAAc,CAepF;AAED,eAAe,iBAAiB,CAAC","sources":["index.ts"],"sourcesContent":["// @ts-ignore\nimport { EventEmitter } from 'events';\n// @ts-ignore\nimport { SdlGameController as NativeSdlGameController } from './build/Release/sdl_gamecontroller.node';\n// @ts-ignore\nimport bindings from 'bindings';\n\n// Get the native binding\nconst SdlGameController: typeof NativeSdlGameController = bindings('sdl_gamecontroller').SdlGameController;\n\nexport type Message = { message: string };\nexport type Player = { player?: number };\nexport type Error = Message & Player & { operation: string };\nexport type Warning = Message & {\n operation: string;\n elapsed_ms?: number;\n poll_number?: number;\n};\nexport type SdlInit = {\n compiled_against_SDL_version: string;\n linked_against_SDL_version: string;\n};\nexport type DeviceAdded = Message &\n Player & {\n which: number;\n name: string;\n vendor_id: number;\n product_id: number;\n serial_number?: string;\n effects_supported: boolean;\n haptic: boolean;\n has_leds?: boolean;\n num_touchpads?: number;\n has_accelerometer?: boolean;\n has_gyroscope?: boolean;\n has_rumble?: boolean;\n has_rumble_trigger?: boolean;\n };\nexport type SensorUpdate = Message & {\n sensor: 'gyroscope' | 'accelerometer';\n x: number;\n y: number;\n z: number;\n};\nexport type SensorUpdateEvents =\n | 'controller-sensor-update'\n | 'gyroscope'\n | 'accelerometer';\nexport type SensorStateEvents =\n | 'accelerometer:enabled'\n | 'accelerometer:disabled'\n | 'gyroscope:enabled'\n | 'gyroscope:disabled';\n\nexport type TouchpadUpdate = Message & {\n touchpad: number;\n finger: number;\n x: number;\n y: number;\n pressure: number;\n};\nexport type TouchpadEvents =\n | 'controller-touchpad-down'\n | 'controller-touchpad-up'\n | 'controller-touchpad-motion';\n\nexport type DeviceUpdated = Message & {\n which: number;\n};\nexport type DeviceUpdateEvents =\n | 'controller-device-removed'\n | 'controller-device-remapped';\nexport type BatteryUpdateEvents = 'controller-battery-update';\n\nexport type AxisType =\n | 'leftx'\n | 'lefty'\n | 'rightx'\n | 'righty'\n | 'lefttrigger'\n | 'righttrigger';\n\nexport type ButtonType =\n | 'a'\n | 'b'\n | 'x'\n | 'y'\n | 'back'\n | 'guide'\n | 'start'\n | 'leftstick'\n | 'misc1'\n | 'rightstick'\n | 'leftshoulder'\n | 'rightshoulder'\n | 'dpup'\n | 'dpdown'\n | 'dpright'\n | 'dpleft';\n\nexport type AxisMotionData = Message &\n Player & { button: AxisType; value: number; timestamp: number };\n\nexport type ButtonPress = Message &\n Player & { button: ButtonType; pressed: boolean };\n\nexport type ButtonTypeWithUpsAndDowns =\n | `${ButtonType}:up`\n | `${ButtonType}:down`\n | ButtonType\n | 'controller-button-up'\n | 'controller-button-down';\n\nexport type ControllerButtonDown = Message &\n Player & { button: ButtonType; pressed: boolean };\n\nexport type BatteryLevelType =\n | 'empty'\n | 'low'\n | 'medium'\n | 'full'\n | 'wired'\n | 'max'\n | 'unknown';\nexport type BatteryUpdate = Message &\n DeviceUpdated & {\n timestamp: number;\n level: BatteryLevelType;\n };\n\nexport type CallBack<T = Record<string, unknown>> = (data: T) => void;\n\ntype ON<TEventName, TCallBack> = (\n eventName: TEventName,\n callBack: CallBack<TCallBack>,\n) => never;\n\ntype OnErrorCall = ON<'error', Error>;\ntype OnWarningCall = ON<'warning', Warning>;\ntype OnSdlInitCall = ON<'sdl-init', SdlInit>;\ntype OnDeviceAddedCall = ON<'controller-device-added', DeviceAdded>;\ntype OnDeviceUpdated = ON<DeviceUpdateEvents, DeviceUpdated>;\ntype OnBatteryUpdated = ON<BatteryUpdateEvents, BatteryUpdate>;\ntype OnAxisUpdate = ON<AxisType, AxisMotionData>;\ntype OnButtonPressCall = ON<ButtonTypeWithUpsAndDowns, ButtonPress>;\ntype OnSensorUpdate = ON<SensorUpdateEvents, SensorUpdate>;\ntype OnSensorStateChange = ON<SensorStateEvents, Player>;\ntype OnTouchpadUpdate = ON<TouchpadEvents, TouchpadUpdate>;\ntype OnLed = ON<'led', Player>;\ntype OnRumbled = ON<'rumbled', Player>;\ntype OnRumbledTriggers = ON<'rumbled-triggers', Player>;\n\ntype AllOnOptions = OnButtonPressCall &\n OnAxisUpdate &\n OnErrorCall &\n OnWarningCall &\n OnSdlInitCall &\n OnDeviceAddedCall &\n OnDeviceUpdated &\n OnBatteryUpdated &\n OnSensorUpdate &\n OnSensorStateChange &\n OnTouchpadUpdate &\n OnLed &\n OnRumbled &\n OnRumbledTriggers;\n\nexport interface Gamecontroller extends EventEmitter {\n enableGyroscope: (enable?: boolean, player?: number) => void;\n enableAccelerometer: (enable?: boolean, player?: number) => void;\n setLeds: (\n red?: number,\n green?: number,\n blue?: number,\n player?: number,\n ) => void;\n rumble: (\n low_frequency_rumble?: number,\n high_frequency_rumble?: number,\n duration_ms?: number,\n player?: number,\n ) => void;\n rumbleTriggers: (\n left_rumble?: number,\n right_rumble?: number,\n duration_ms?: number,\n player?: number,\n ) => void;\n pollEvents: () => void; // internal\n on: AllOnOptions;\n}\n\n// Options interface\nexport interface GameControllerOptions {\n interval?: number;\n fps?: number;\n sdl_joystick_rog_chakram?: boolean; // additional SDL options\n}\n\n// Apply EventEmitter methods to SdlGameController\nObject.setPrototypeOf(SdlGameController.prototype, EventEmitter.prototype);\n\n// Default export (former index.js)\nconst defaultController: Gamecontroller = new SdlGameController() as Gamecontroller;\n\nsetInterval(() => {\n defaultController.pollEvents();\n}, 33);\n\nexport function createController(options: GameControllerOptions = {}): Gamecontroller {\n console.log('createController options:', options);\n const inst = new SdlGameController(options) as Gamecontroller;\n let interval = options.interval || 33;\n\n if (options.fps) {\n interval = 1000 / options.fps;\n }\n\n console.log('poll interval: ', interval, 'ms');\n setInterval(() => {\n inst.pollEvents();\n }, interval);\n\n return inst;\n}\n\nexport default defaultController;\n"],"names":[],"version":3,"file":"types.d.ts.map","sourceRoot":"../"}