forked from IBM/sdl2-gamecontroller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
79 lines (67 loc) · 2.01 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
declare const gamecontroller: Gamecontroller;
export default gamecontroller;
export type Message = { message: string };
export type Player = { player: number };
export type Error = Message & Player & { operation: string };
export type Value = { value: number };
export type TimeStamp = { timestamp: number };
export type OnButtonPress = Message &
Player & { button: ButtonType; pressed: boolean };
export type OnTriggerPress = Omit<OnButtonPress, 'pressed'> & {
value: number;
timestamp: number;
};
export type StickType = 'leftx' | 'lefty' | 'rightx' | 'righty';
export type OnStickMoveData = Message &
Player &
Value &
TimeStamp & { button: StickType };
export type ButtonType =
| 'a'
| 'b'
| 'x'
| 'y'
| 'back'
| 'guide'
| 'start'
| 'leftstick'
| 'misc1'
| 'rightstick'
| 'leftshoulder'
| 'rightshoulder'
| 'dpup'
| 'dpdown'
| 'dpright'
| 'dpleft';
export type ButtonTypeWithUpsAndDowns =
| `${ButtonType}:up`
| `${ButtonType}:down`
| ButtonType;
export type ControllerButtonDown = Message &
Player & { button: ButtonType; pressed: boolean };
export type FieldUpdateHandler = (update: any) => unknown;
export type Handlers = Record<string, FieldUpdateHandler>;
export type CallBack<T = Record<string, unknown>> = (data: T) => void;
type ON<TEventName, TCallBack> = (
eventName: TEventName,
callBack: CallBack<TCallBack>
) => void;
type OnStickMove = ON<StickType, OnStickMoveData>;
type OnButtonPressCall = ON<ButtonTypeWithUpsAndDowns, OnButtonPress>;
type OnErrorCall = ON<'error', Error>;
type OnControllerButtonUp = ON<'controller-button-up', OnButtonPress>;
type OnControllerButtonDown = ON<'controller-button-down', OnButtonPress>;
type OnTrigger = ON<'righttrigger' | 'lefttrigger', OnTriggerPress>;
type AllOnOptions = OnButtonPressCall &
OnStickMove &
OnErrorCall &
OnControllerButtonUp &
OnControllerButtonDown &
OnTrigger;
type Gamecontroller = {
rumbleTriggers: (
buttonType: ButtonType,
callBack: CallBack<OnTriggerPress>
) => void;
on: AllOnOptions;
};