@kmamal/sdl 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1203 -589
- package/package.json +15 -3
- package/scripts/build.mjs +3 -6
- package/scripts/clean.mjs +1 -0
- package/scripts/download-sdl.mjs +17 -0
- package/scripts/install.mjs +1 -0
- package/scripts/util/common.js +5 -0
- package/src/javascript/audio/audio-instance.js +17 -10
- package/src/javascript/audio/device.js +18 -0
- package/src/javascript/audio/index.js +1 -1
- package/src/javascript/audio/prevent-exit.js +5 -2
- package/src/javascript/cleanup.js +3 -3
- package/src/javascript/controller/controller-instance.js +115 -0
- package/src/javascript/controller/device.js +15 -0
- package/src/javascript/controller/index.js +25 -0
- package/src/javascript/enums.js +1 -1
- package/src/javascript/events/index.js +293 -147
- package/src/javascript/globals.js +9 -7
- package/src/javascript/index.js +9 -2
- package/src/javascript/joystick/device.js +15 -0
- package/src/javascript/joystick/index.js +15 -0
- package/src/javascript/joystick/joystick-instance.js +120 -0
- package/src/javascript/keyboard/index.js +4 -4
- package/src/javascript/mouse/index.js +4 -4
- package/src/javascript/video/index.js +2 -2
- package/src/javascript/video/window.js +9 -7
- package/src/native/binding.cpp +415 -240
- package/src/native/sdl-helpers.cpp +868 -567
- package/src/native/sdl-helpers.h +50 -22
- package/src/types/index.d.ts +338 -100
- package/src/javascript/_controller/index.js +0 -47
- package/src/javascript/_joystick/index.js +0 -46
package/src/native/sdl-helpers.h
CHANGED
|
@@ -32,6 +32,8 @@ using VariantMap = std::map<const char *, Variant>;
|
|
|
32
32
|
using VariantList = std::vector<Variant>;
|
|
33
33
|
|
|
34
34
|
|
|
35
|
+
ErrorMessage * enum_getEventFamilies (Variant & object);
|
|
36
|
+
ErrorMessage * enum_getEventTypes (Variant & object);
|
|
35
37
|
ErrorMessage * enum_getPixelFormats (Variant & object);
|
|
36
38
|
ErrorMessage * enum_getAudioFormats (Variant & object);
|
|
37
39
|
ErrorMessage * enum_getScancodes (Variant & object);
|
|
@@ -39,11 +41,16 @@ ErrorMessage * enum_getMouseButtons (Variant & object);
|
|
|
39
41
|
ErrorMessage * enum_getCursors (Variant & object);
|
|
40
42
|
ErrorMessage * enum_getHatPositions (Variant & object);
|
|
41
43
|
ErrorMessage * enum_getPowerLevels (Variant & object);
|
|
42
|
-
|
|
44
|
+
ErrorMessage * enum_getJoystickTypes (Variant & object);
|
|
45
|
+
ErrorMessage * enum_getControllerAxes (Variant & object);
|
|
46
|
+
ErrorMessage * enum_getControllerButtons (Variant & object);
|
|
43
47
|
|
|
44
48
|
ErrorMessage * initialize (Variant & object);
|
|
45
49
|
ErrorMessage * cleanup ();
|
|
46
50
|
|
|
51
|
+
ErrorMessage * events_poll (Variant & event);
|
|
52
|
+
ErrorMessage * events_wait (int timeout, Variant & event);
|
|
53
|
+
|
|
47
54
|
ErrorMessage * video_getDisplays (Variant & list);
|
|
48
55
|
|
|
49
56
|
ErrorMessage * window_create (
|
|
@@ -64,7 +71,11 @@ ErrorMessage * window_setSize (int window_id, int width, int height);
|
|
|
64
71
|
ErrorMessage * window_setFullscreen (int window_id, bool * fullscreen);
|
|
65
72
|
ErrorMessage * window_setResizable (int window_id, bool * resizable);
|
|
66
73
|
ErrorMessage * window_setBorderless (int window_id, bool * borderless);
|
|
67
|
-
ErrorMessage * window_setAcceleratedAndVsync (
|
|
74
|
+
ErrorMessage * window_setAcceleratedAndVsync (
|
|
75
|
+
int window_id,
|
|
76
|
+
bool * accelerated,
|
|
77
|
+
bool * vsync
|
|
78
|
+
);
|
|
68
79
|
ErrorMessage * window_focus (int window_id);
|
|
69
80
|
ErrorMessage * window_show (int window_id);
|
|
70
81
|
ErrorMessage * window_hide (int window_id);
|
|
@@ -85,22 +96,6 @@ ErrorMessage * window_render (
|
|
|
85
96
|
);
|
|
86
97
|
ErrorMessage * window_destroy (int window_id);
|
|
87
98
|
|
|
88
|
-
ErrorMessage * audio_getDevices (bool capture, Variant & list);
|
|
89
|
-
ErrorMessage * audio_openDevice (
|
|
90
|
-
const char * name, bool capture,
|
|
91
|
-
int freq, int format, int channels, int samples,
|
|
92
|
-
int * device_id
|
|
93
|
-
);
|
|
94
|
-
ErrorMessage * audio_close (int device_id);
|
|
95
|
-
ErrorMessage * audio_play (int device_id, bool play);
|
|
96
|
-
ErrorMessage * audio_getQueueSize (int device_id, unsigned int * size);
|
|
97
|
-
ErrorMessage * audio_clearQueue (int device_id);
|
|
98
|
-
ErrorMessage * audio_enqueue (int device_id, void * src, int size);
|
|
99
|
-
ErrorMessage * audio_dequeue (int device_id, void * dst, int size, int * num);
|
|
100
|
-
|
|
101
|
-
ErrorMessage * events_poll (Variant & event);
|
|
102
|
-
ErrorMessage * events_wait (int timeout, Variant & event);
|
|
103
|
-
|
|
104
99
|
ErrorMessage * keyboard_getKey (int scancode, const char ** key);
|
|
105
100
|
ErrorMessage * keyboard_getScancode (const char * key, int * scancode);
|
|
106
101
|
ErrorMessage * keyboard_getState (Variant & list);
|
|
@@ -120,11 +115,44 @@ ErrorMessage * mouse_showCursor (bool show);
|
|
|
120
115
|
|
|
121
116
|
ErrorMessage * joystick_getDevices (Variant & list);
|
|
122
117
|
ErrorMessage * joystick_open (int index, Variant & device);
|
|
123
|
-
ErrorMessage * joystick_close (int
|
|
124
|
-
ErrorMessage * joystick_getPower (int
|
|
118
|
+
ErrorMessage * joystick_close (int joystick_id);
|
|
119
|
+
ErrorMessage * joystick_getPower (int joystick_id, int * power);
|
|
120
|
+
ErrorMessage * joystick_setLed (
|
|
121
|
+
int joystick_id,
|
|
122
|
+
double red,
|
|
123
|
+
double green,
|
|
124
|
+
double blue
|
|
125
|
+
);
|
|
126
|
+
ErrorMessage * joystick_setPlayer (int joystick_id, int player);
|
|
127
|
+
ErrorMessage * joystick_rumble (
|
|
128
|
+
int joystick_id,
|
|
129
|
+
double low_freq_rumble,
|
|
130
|
+
double high_freq_rumble,
|
|
131
|
+
int duration
|
|
132
|
+
);
|
|
133
|
+
ErrorMessage * joystick_rumbleTriggers (
|
|
134
|
+
int joystick_id,
|
|
135
|
+
double left_rumble,
|
|
136
|
+
double right_rumble,
|
|
137
|
+
int duration
|
|
138
|
+
);
|
|
125
139
|
|
|
126
|
-
ErrorMessage * controller_open (int index, Variant &
|
|
127
|
-
ErrorMessage * controller_close (int
|
|
140
|
+
ErrorMessage * controller_open (int index, Variant & object);
|
|
141
|
+
ErrorMessage * controller_close (int controller_id);
|
|
142
|
+
ErrorMessage * controller_addMappings (char ** mappings, int length);
|
|
143
|
+
|
|
144
|
+
ErrorMessage * audio_getDevices (bool capture, Variant & list);
|
|
145
|
+
ErrorMessage * audio_openDevice (
|
|
146
|
+
const char * name, bool capture,
|
|
147
|
+
int freq, int format, int channels, int samples,
|
|
148
|
+
int * audio_id
|
|
149
|
+
);
|
|
150
|
+
ErrorMessage * audio_close (int audio_id);
|
|
151
|
+
ErrorMessage * audio_play (int audio_id, bool play);
|
|
152
|
+
ErrorMessage * audio_getQueueSize (int audio_id, unsigned int * size);
|
|
153
|
+
ErrorMessage * audio_clearQueue (int audio_id);
|
|
154
|
+
ErrorMessage * audio_enqueue (int audio_id, void * src, int size);
|
|
155
|
+
ErrorMessage * audio_dequeue (int audio_id, void * dst, int size, int * num);
|
|
128
156
|
|
|
129
157
|
ErrorMessage * clipboard_getText (const char ** text);
|
|
130
158
|
ErrorMessage * clipboard_setText (const char * text);
|
package/src/types/index.d.ts
CHANGED
|
@@ -93,6 +93,71 @@ export namespace Events {
|
|
|
93
93
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
namespace Joystick {
|
|
97
|
+
|
|
98
|
+
interface DeviceEvent extends BaseEvent {
|
|
99
|
+
readonly device: Sdl.Joystick.Device
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface DeviceAdd extends DeviceEvent {}
|
|
103
|
+
interface DeviceRemove extends DeviceEvent {}
|
|
104
|
+
|
|
105
|
+
interface JoystickEvent extends BaseEvent {}
|
|
106
|
+
|
|
107
|
+
interface AxisMotion extends JoystickEvent {
|
|
108
|
+
axis: number,
|
|
109
|
+
value: number
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
interface BallMotion extends JoystickEvent {
|
|
113
|
+
ball: number,
|
|
114
|
+
x: number
|
|
115
|
+
y: number
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface ButtonEvent extends JoystickEvent {
|
|
119
|
+
button: number
|
|
120
|
+
}
|
|
121
|
+
interface ButtonDown extends ButtonEvent {}
|
|
122
|
+
interface ButtonUp extends ButtonEvent {}
|
|
123
|
+
|
|
124
|
+
interface HatMotion extends JoystickEvent {
|
|
125
|
+
hat: number,
|
|
126
|
+
value: Sdl.Joystick.HatPosition
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// interface Close extends JoystickEvent {}
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
namespace Controller {
|
|
134
|
+
|
|
135
|
+
interface DeviceEvent extends BaseEvent {
|
|
136
|
+
readonly device: Sdl.Controller.Device
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface DeviceAdd extends DeviceEvent {}
|
|
140
|
+
interface DeviceRemove extends DeviceEvent {}
|
|
141
|
+
|
|
142
|
+
interface ControllerEvent extends BaseEvent {}
|
|
143
|
+
|
|
144
|
+
interface AxisMotion extends ControllerEvent {
|
|
145
|
+
axis: number,
|
|
146
|
+
value: number
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
interface ButtonEvent extends ControllerEvent {
|
|
150
|
+
button: number
|
|
151
|
+
}
|
|
152
|
+
interface ButtonDown extends ButtonEvent {}
|
|
153
|
+
interface ButtonUp extends ButtonEvent {}
|
|
154
|
+
|
|
155
|
+
interface Remap extends ControllerEvent {}
|
|
156
|
+
|
|
157
|
+
// interface Close extends ControllerEvent {}
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
|
|
96
161
|
namespace Audio {
|
|
97
162
|
|
|
98
163
|
interface DeviceEvent extends BaseEvent {
|
|
@@ -102,6 +167,8 @@ export namespace Events {
|
|
|
102
167
|
interface DeviceAdd extends DeviceEvent {}
|
|
103
168
|
interface DeviceRemove extends DeviceEvent {}
|
|
104
169
|
|
|
170
|
+
// interface AudioEvent extends BaseEvent {}
|
|
171
|
+
// interface Close extends AudioEvent {}
|
|
105
172
|
}
|
|
106
173
|
|
|
107
174
|
namespace Clipboard {
|
|
@@ -230,7 +297,7 @@ export namespace Sdl {
|
|
|
230
297
|
on (event: 'dropFile', listener: (event: Events.Window.DropFile) => void): this
|
|
231
298
|
on (event: 'dropComplete', listener: () => void): this
|
|
232
299
|
|
|
233
|
-
readonly id:
|
|
300
|
+
readonly id: number
|
|
234
301
|
|
|
235
302
|
readonly title: string
|
|
236
303
|
setTitle (title: string): void
|
|
@@ -310,104 +377,6 @@ export namespace Sdl {
|
|
|
310
377
|
}
|
|
311
378
|
}
|
|
312
379
|
|
|
313
|
-
namespace Audio {
|
|
314
|
-
|
|
315
|
-
type Format
|
|
316
|
-
= 's8'
|
|
317
|
-
| 'u8'
|
|
318
|
-
| 's16lsb'
|
|
319
|
-
| 's16msb'
|
|
320
|
-
| 's16sys'
|
|
321
|
-
| 's16'
|
|
322
|
-
| 'u16lsb'
|
|
323
|
-
| 'u16msb'
|
|
324
|
-
| 'u16sys'
|
|
325
|
-
| 'u16'
|
|
326
|
-
| 's32lsb'
|
|
327
|
-
| 's32msb'
|
|
328
|
-
| 's32sys'
|
|
329
|
-
| 's32'
|
|
330
|
-
| 'f32lsb'
|
|
331
|
-
| 'f32msb'
|
|
332
|
-
| 'f32sys'
|
|
333
|
-
| 'f32'
|
|
334
|
-
|
|
335
|
-
interface Device {
|
|
336
|
-
readonly name: string
|
|
337
|
-
readonly recording: boolean
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
interface PlaybackDevice {
|
|
341
|
-
readonly name: string
|
|
342
|
-
readonly recording: false
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
interface RecordingDevice {
|
|
346
|
-
readonly name: string
|
|
347
|
-
readonly recording: true
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
class AudioInstance {
|
|
351
|
-
readonly id: any
|
|
352
|
-
readonly device: Device
|
|
353
|
-
readonly name: string
|
|
354
|
-
readonly channels: number
|
|
355
|
-
readonly frequency: number
|
|
356
|
-
readonly format: Format
|
|
357
|
-
readonly buffered: number
|
|
358
|
-
|
|
359
|
-
readonly playing: boolean
|
|
360
|
-
play (play?: boolean): void
|
|
361
|
-
pause (): void
|
|
362
|
-
|
|
363
|
-
readonly queued: number
|
|
364
|
-
clearQueue (): void
|
|
365
|
-
|
|
366
|
-
readonly bytesPerSample: number
|
|
367
|
-
readonly minSampleValue: number
|
|
368
|
-
readonly maxSampleValue: number
|
|
369
|
-
readonly zeroSampleValue: number
|
|
370
|
-
readSample (buffer: Buffer, offset?: number): number
|
|
371
|
-
writeSample (buffer: Buffer, value: number, offset?: number): number
|
|
372
|
-
|
|
373
|
-
readonly closed: boolean
|
|
374
|
-
close (): void
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
class AudioPlaybackInstance extends AudioInstance {
|
|
378
|
-
enqueue (buffer: Buffer, bytes?: number): void
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
class AudioRecordingInstance extends AudioInstance {
|
|
382
|
-
dequeue (buffer: Buffer, bytes?: number): number
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
interface AudioOptions {
|
|
386
|
-
name?: string
|
|
387
|
-
channels?: 1 | 2 | 4 | 6
|
|
388
|
-
frequency?: number
|
|
389
|
-
format?: Format
|
|
390
|
-
buffered?: number
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
interface Module {
|
|
394
|
-
on (event: 'deviceAdd', listener: (event: Events.Audio.DeviceAdd) => void): this
|
|
395
|
-
on (event: 'deviceRemove', listener: (event: Events.Audio.DeviceRemove) => void): this
|
|
396
|
-
|
|
397
|
-
readonly devices: Device[]
|
|
398
|
-
|
|
399
|
-
openDevice (device: PlaybackDevice, options?: AudioOptions): AudioPlaybackInstance
|
|
400
|
-
openDevice (device: RecordingDevice, options?: AudioOptions): AudioRecordingInstance
|
|
401
|
-
|
|
402
|
-
bytesPerSample (format: Format): number
|
|
403
|
-
minSampleValue (format: Format): number
|
|
404
|
-
maxSampleValue (format: Format): number
|
|
405
|
-
zeroSampleValue (format: Format): number
|
|
406
|
-
readSample (format: Format, buffer: Buffer, offset?: number): number
|
|
407
|
-
writeSample (format: Format, buffer: Buffer, value: number, offset?: number): number
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
380
|
namespace Keyboard {
|
|
412
381
|
|
|
413
382
|
type Scancode = number
|
|
@@ -715,6 +684,273 @@ export namespace Sdl {
|
|
|
715
684
|
|
|
716
685
|
}
|
|
717
686
|
|
|
687
|
+
namespace Joystick {
|
|
688
|
+
|
|
689
|
+
interface BallPosition {
|
|
690
|
+
x: number
|
|
691
|
+
y: number
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
type HatPosition
|
|
695
|
+
= 'centered'
|
|
696
|
+
| 'up'
|
|
697
|
+
| 'right'
|
|
698
|
+
| 'down'
|
|
699
|
+
| 'left'
|
|
700
|
+
| 'rightup'
|
|
701
|
+
| 'rightdown'
|
|
702
|
+
| 'leftup'
|
|
703
|
+
| 'leftdown'
|
|
704
|
+
|
|
705
|
+
type PowerLevel
|
|
706
|
+
= 'unknown'
|
|
707
|
+
| 'empty'
|
|
708
|
+
| 'low'
|
|
709
|
+
| 'medium'
|
|
710
|
+
| 'full'
|
|
711
|
+
| 'wired'
|
|
712
|
+
| 'max'
|
|
713
|
+
|
|
714
|
+
interface Device {
|
|
715
|
+
readonly id: number
|
|
716
|
+
readonly type: string
|
|
717
|
+
readonly name: string
|
|
718
|
+
readonly path: string
|
|
719
|
+
readonly guid: string
|
|
720
|
+
readonly vendor: number
|
|
721
|
+
readonly product: number
|
|
722
|
+
readonly version: number
|
|
723
|
+
readonly player: number
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
class JoystickInstance {
|
|
727
|
+
on (event: 'axisMotion', listener: (event: Events.Joystick.AxisMotion) => void): this
|
|
728
|
+
on (event: 'ballMotion', listener: (event: Events.Joystick.BallMotion) => void): this
|
|
729
|
+
on (event: 'buttonDown', listener: (event: Events.Joystick.ButtonDown) => void): this
|
|
730
|
+
on (event: 'buttonUp', listener: (event: Events.Joystick.ButtonUp) => void): this
|
|
731
|
+
on (event: 'hatMotion', listener: (event: Events.Joystick.HatMotion) => void): this
|
|
732
|
+
on (event: 'close', listener: () => void): this
|
|
733
|
+
|
|
734
|
+
readonly device: Device
|
|
735
|
+
readonly firmwareVersion: number
|
|
736
|
+
readonly serialNumber: string
|
|
737
|
+
|
|
738
|
+
readonly axes: number[]
|
|
739
|
+
readonly balls: BallPosition[]
|
|
740
|
+
readonly hats: HatPosition[]
|
|
741
|
+
readonly buttons: boolean[]
|
|
742
|
+
|
|
743
|
+
readonly power: PowerLevel
|
|
744
|
+
|
|
745
|
+
readonly hasLed: boolean
|
|
746
|
+
setLed (red: number, green: number, blue: number): void
|
|
747
|
+
|
|
748
|
+
readonly hasRumble: boolean
|
|
749
|
+
rumble (lowFreqRumble: number, highFreqRumble: number, duration: number): void
|
|
750
|
+
stopRumble (): void
|
|
751
|
+
|
|
752
|
+
readonly hasRumbleTriggers: boolean
|
|
753
|
+
rumbleTriggers (leftRumble: number, rightRumble: number, duration: number): void
|
|
754
|
+
stopRumbleTriggers (): void
|
|
755
|
+
|
|
756
|
+
readonly closed: boolean
|
|
757
|
+
close (): void
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
interface Module {
|
|
761
|
+
on (event: 'deviceAdd', listener: (event: Events.Joystick.DeviceAdd) => void): this
|
|
762
|
+
on (event: 'deviceRemove', listener: (event: Events.Joystick.DeviceRemove) => void): this
|
|
763
|
+
|
|
764
|
+
readonly devices: Device[]
|
|
765
|
+
|
|
766
|
+
openDevice (device: Device): JoystickInstance
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
namespace Controller {
|
|
772
|
+
|
|
773
|
+
interface Device {
|
|
774
|
+
readonly id: number
|
|
775
|
+
readonly name: string
|
|
776
|
+
readonly path: string
|
|
777
|
+
readonly guid: string
|
|
778
|
+
readonly vendor: number
|
|
779
|
+
readonly product: number
|
|
780
|
+
readonly version: number
|
|
781
|
+
readonly player: number
|
|
782
|
+
readonly mapping: string
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
class ControllerInstance {
|
|
786
|
+
on (event: 'axisMotion', listener: (event: Events.Controller.AxisMotion) => void): this
|
|
787
|
+
on (event: 'buttonDown', listener: (event: Events.Controller.ButtonDown) => void): this
|
|
788
|
+
on (event: 'buttonUp', listener: (event: Events.Controller.ButtonUp) => void): this
|
|
789
|
+
on (event: 'remap', listener: (event: Events.Controller.Remap) => void): this
|
|
790
|
+
on (event: 'close', listener: () => void): this
|
|
791
|
+
|
|
792
|
+
readonly device: Device
|
|
793
|
+
readonly firmwareVersion: number
|
|
794
|
+
readonly serialNumber: string
|
|
795
|
+
|
|
796
|
+
readonly axes: {
|
|
797
|
+
readonly leftStickX: number,
|
|
798
|
+
readonly leftStickY: number,
|
|
799
|
+
readonly rightStickX: number,
|
|
800
|
+
readonly rightStickY: number,
|
|
801
|
+
readonly leftTrigger: number,
|
|
802
|
+
readonly rightTrigger: number,
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
readonly buttons: {
|
|
806
|
+
readonly dpadLeft: boolean,
|
|
807
|
+
readonly dpadRight: boolean,
|
|
808
|
+
readonly dpadUp: boolean,
|
|
809
|
+
readonly dpadDown: boolean,
|
|
810
|
+
readonly a: boolean,
|
|
811
|
+
readonly b: boolean,
|
|
812
|
+
readonly x: boolean,
|
|
813
|
+
readonly y: boolean,
|
|
814
|
+
readonly guide: boolean,
|
|
815
|
+
readonly back: boolean,
|
|
816
|
+
readonly start: boolean,
|
|
817
|
+
readonly leftStick: boolean,
|
|
818
|
+
readonly rightStick: boolean,
|
|
819
|
+
readonly leftShoulder: boolean,
|
|
820
|
+
readonly rightShoulder: boolean,
|
|
821
|
+
readonly paddle1: boolean,
|
|
822
|
+
readonly paddle2: boolean,
|
|
823
|
+
readonly paddle3: boolean,
|
|
824
|
+
readonly paddle4: boolean,
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
readonly power: Joystick.PowerLevel
|
|
828
|
+
|
|
829
|
+
readonly hasLed: boolean
|
|
830
|
+
setLed (red: number, green: number, blue: number): void
|
|
831
|
+
|
|
832
|
+
readonly hasRumble: boolean
|
|
833
|
+
rumble (lowFreqRumble: number, highFreqRumble: number, duration: number): void
|
|
834
|
+
stopRumble (): void
|
|
835
|
+
|
|
836
|
+
readonly hasRumbleTriggers: boolean
|
|
837
|
+
rumbleTriggers (leftRumble: number, rightRumble: number, duration: number): void
|
|
838
|
+
stopRumbleTriggers (): void
|
|
839
|
+
|
|
840
|
+
readonly closed: boolean
|
|
841
|
+
close (): void
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
interface Module {
|
|
845
|
+
on (event: 'deviceAdd', listener: (event: Events.Controller.DeviceAdd) => void): this
|
|
846
|
+
on (event: 'deviceRemove', listener: (event: Events.Controller.DeviceRemove) => void): this
|
|
847
|
+
|
|
848
|
+
addMappings (mappings: string[]): void
|
|
849
|
+
|
|
850
|
+
readonly devices: Device[]
|
|
851
|
+
|
|
852
|
+
openDevice (device: Device): ControllerInstance
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
namespace Audio {
|
|
858
|
+
|
|
859
|
+
type Format
|
|
860
|
+
= 's8'
|
|
861
|
+
| 'u8'
|
|
862
|
+
| 's16lsb'
|
|
863
|
+
| 's16msb'
|
|
864
|
+
| 's16sys'
|
|
865
|
+
| 's16'
|
|
866
|
+
| 'u16lsb'
|
|
867
|
+
| 'u16msb'
|
|
868
|
+
| 'u16sys'
|
|
869
|
+
| 'u16'
|
|
870
|
+
| 's32lsb'
|
|
871
|
+
| 's32msb'
|
|
872
|
+
| 's32sys'
|
|
873
|
+
| 's32'
|
|
874
|
+
| 'f32lsb'
|
|
875
|
+
| 'f32msb'
|
|
876
|
+
| 'f32sys'
|
|
877
|
+
| 'f32'
|
|
878
|
+
|
|
879
|
+
interface Device {
|
|
880
|
+
readonly type: "recording"|"playback"
|
|
881
|
+
readonly name?: string
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
interface PlaybackDevice extends Device {
|
|
885
|
+
readonly type: "playback"
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
interface RecordingDevice extends Device {
|
|
889
|
+
readonly type: "recording"
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
class AudioInstance {
|
|
893
|
+
on (event: 'close', listener: () => void): this
|
|
894
|
+
|
|
895
|
+
readonly id: number
|
|
896
|
+
readonly device: Device
|
|
897
|
+
|
|
898
|
+
readonly channels: number
|
|
899
|
+
readonly frequency: number
|
|
900
|
+
readonly format: Format
|
|
901
|
+
readonly buffered: number
|
|
902
|
+
|
|
903
|
+
readonly playing: boolean
|
|
904
|
+
play (play?: boolean): void
|
|
905
|
+
pause (): void
|
|
906
|
+
|
|
907
|
+
readonly queued: number
|
|
908
|
+
clearQueue (): void
|
|
909
|
+
|
|
910
|
+
readonly bytesPerSample: number
|
|
911
|
+
readonly minSampleValue: number
|
|
912
|
+
readonly maxSampleValue: number
|
|
913
|
+
readonly zeroSampleValue: number
|
|
914
|
+
readSample (buffer: Buffer, offset?: number): number
|
|
915
|
+
writeSample (buffer: Buffer, value: number, offset?: number): number
|
|
916
|
+
|
|
917
|
+
readonly closed: boolean
|
|
918
|
+
close (): void
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
class AudioPlaybackInstance extends AudioInstance {
|
|
922
|
+
enqueue (buffer: Buffer, bytes?: number): void
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
class AudioRecordingInstance extends AudioInstance {
|
|
926
|
+
dequeue (buffer: Buffer, bytes?: number): number
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
interface AudioOptions {
|
|
930
|
+
channels?: 1 | 2 | 4 | 6
|
|
931
|
+
frequency?: number
|
|
932
|
+
format?: Format
|
|
933
|
+
buffered?: number
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
interface Module {
|
|
937
|
+
on (event: 'deviceAdd', listener: (event: Events.Audio.DeviceAdd) => void): this
|
|
938
|
+
on (event: 'deviceRemove', listener: (event: Events.Audio.DeviceRemove) => void): this
|
|
939
|
+
|
|
940
|
+
readonly devices: Device[]
|
|
941
|
+
|
|
942
|
+
openDevice (device: PlaybackDevice, options?: AudioOptions): AudioPlaybackInstance
|
|
943
|
+
openDevice (device: RecordingDevice, options?: AudioOptions): AudioRecordingInstance
|
|
944
|
+
|
|
945
|
+
bytesPerSample (format: Format): number
|
|
946
|
+
minSampleValue (format: Format): number
|
|
947
|
+
maxSampleValue (format: Format): number
|
|
948
|
+
zeroSampleValue (format: Format): number
|
|
949
|
+
readSample (format: Format, buffer: Buffer, offset?: number): number
|
|
950
|
+
writeSample (format: Format, buffer: Buffer, value: number, offset?: number): number
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
|
|
718
954
|
namespace Clipboard {
|
|
719
955
|
|
|
720
956
|
interface Module {
|
|
@@ -732,9 +968,11 @@ export namespace Sdl {
|
|
|
732
968
|
|
|
733
969
|
readonly info: Info
|
|
734
970
|
readonly video: Video.Module
|
|
735
|
-
readonly audio: Audio.Module
|
|
736
971
|
readonly keyboard: Keyboard.Module
|
|
737
972
|
readonly mouse: Mouse.Module
|
|
973
|
+
readonly joystick: Joystick.Module
|
|
974
|
+
readonly controller: Controller.Module
|
|
975
|
+
readonly audio: Audio.Module
|
|
738
976
|
readonly clipboard: Clipboard.Module
|
|
739
977
|
}
|
|
740
978
|
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
class Controller extends EventsViaPoll {
|
|
3
|
-
constructor (device) {
|
|
4
|
-
super()
|
|
5
|
-
|
|
6
|
-
const { name, index } = device
|
|
7
|
-
|
|
8
|
-
const { id, guid, sticks, triggers, shoulders, dpad, buttons } = Bindings.controller_open(index)
|
|
9
|
-
|
|
10
|
-
this._id = id
|
|
11
|
-
this._name = name
|
|
12
|
-
this._guid = guid
|
|
13
|
-
|
|
14
|
-
this._sticks = sticks
|
|
15
|
-
this._triggers = triggers
|
|
16
|
-
this._shoulders = shoulders
|
|
17
|
-
this._dpad = dpad
|
|
18
|
-
this._buttons = buttons
|
|
19
|
-
|
|
20
|
-
this._closed = false
|
|
21
|
-
|
|
22
|
-
controllers.set(this._id, this)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get id () { return this._id }
|
|
26
|
-
get name () { return this._name }
|
|
27
|
-
get guid () { return this._guid }
|
|
28
|
-
|
|
29
|
-
get sticks () { return this._sticks }
|
|
30
|
-
get triggers () { return this._triggers }
|
|
31
|
-
get shoulders () { return this._shoulders }
|
|
32
|
-
get dpad () { return this._dpad }
|
|
33
|
-
get buttons () { return this._buttons }
|
|
34
|
-
|
|
35
|
-
get closed () { return this._closed }
|
|
36
|
-
close () {
|
|
37
|
-
this._closed = true
|
|
38
|
-
Bindings.controller_close(this._id)
|
|
39
|
-
controllers.delete(this._id)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
sdl.controller = {
|
|
44
|
-
get devices () { return sdl.joystick.devices.filter(({ controller }) => controller) },
|
|
45
|
-
|
|
46
|
-
open: (device) => new Controller(device),
|
|
47
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
class Joystick extends EventsViaPoll {
|
|
3
|
-
constructor (device) {
|
|
4
|
-
super()
|
|
5
|
-
|
|
6
|
-
const { name, index } = device
|
|
7
|
-
|
|
8
|
-
const { id, guid, axes, balls, buttons, hats } = Bindings.joystick_open(index)
|
|
9
|
-
|
|
10
|
-
this._id = id
|
|
11
|
-
this._name = name
|
|
12
|
-
this._guid = guid
|
|
13
|
-
this._axes = axes
|
|
14
|
-
this._balls = balls
|
|
15
|
-
this._buttons = buttons
|
|
16
|
-
this._hats = hats
|
|
17
|
-
|
|
18
|
-
this._closed = false
|
|
19
|
-
|
|
20
|
-
joysticks.set(this._id, this)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
get id () { return this._id }
|
|
24
|
-
get name () { return this._name }
|
|
25
|
-
get guid () { return this._guid }
|
|
26
|
-
|
|
27
|
-
get axes () { return this._axes }
|
|
28
|
-
get balls () { return this._balls }
|
|
29
|
-
get buttons () { return this._buttons }
|
|
30
|
-
get hats () { return this._hats }
|
|
31
|
-
|
|
32
|
-
get power () { return Bindings.joystick_getPower() }
|
|
33
|
-
|
|
34
|
-
get closed () { return this._closed }
|
|
35
|
-
close () {
|
|
36
|
-
this._closed = true
|
|
37
|
-
Bindings.joystick_close(this._id)
|
|
38
|
-
joysticks.delete(this._id)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
sdl.joystick = {
|
|
43
|
-
get devices () { return Bindings.joystick_getDevices() },
|
|
44
|
-
|
|
45
|
-
open (device) { return new Joystick(device) },
|
|
46
|
-
}
|