@kmamal/sdl 0.9.4 → 0.9.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.
Files changed (55) hide show
  1. package/README.md +34 -15
  2. package/binding.gyp +25 -5
  3. package/package.json +7 -4
  4. package/src/javascript/audio/audio-instance.js +9 -6
  5. package/src/javascript/cleanup.js +1 -1
  6. package/src/javascript/clipboard/index.js +2 -1
  7. package/src/javascript/controller/controller-instance.js +6 -0
  8. package/src/javascript/enums.js +1 -1
  9. package/src/javascript/events/index.js +302 -305
  10. package/src/javascript/index.js +1 -1
  11. package/src/javascript/joystick/joystick-instance.js +7 -0
  12. package/src/javascript/keyboard/index.js +3 -3
  13. package/src/javascript/keyboard/key-mapping.js +14 -6
  14. package/src/javascript/mouse/index.js +13 -12
  15. package/src/javascript/power/index.js +0 -2
  16. package/src/javascript/sensor/sensor-instance.js +1 -5
  17. package/src/javascript/video/window.js +17 -16
  18. package/src/native/audio.cpp +178 -0
  19. package/src/native/audio.h +21 -0
  20. package/src/native/clipboard.cpp +45 -0
  21. package/src/native/clipboard.h +13 -0
  22. package/src/native/cocoa-global.h +8 -0
  23. package/src/native/cocoa-global.mm +8 -0
  24. package/src/native/cocoa-window.h +9 -4
  25. package/src/native/cocoa-window.mm +6 -9
  26. package/src/native/controller.cpp +154 -0
  27. package/src/native/controller.h +17 -0
  28. package/src/native/enums.cpp +477 -0
  29. package/src/native/enums.h +67 -0
  30. package/src/native/events.cpp +339 -0
  31. package/src/native/events.h +15 -0
  32. package/src/native/global.cpp +187 -0
  33. package/src/native/global.h +15 -0
  34. package/src/native/joystick.cpp +388 -0
  35. package/src/native/joystick.h +22 -0
  36. package/src/native/keyboard.cpp +55 -0
  37. package/src/native/keyboard.h +18 -0
  38. package/src/native/module.cpp +98 -0
  39. package/src/native/mouse.cpp +186 -0
  40. package/src/native/mouse.h +21 -0
  41. package/src/native/power.cpp +18 -0
  42. package/src/native/power.h +12 -0
  43. package/src/native/sensor.cpp +117 -0
  44. package/src/native/sensor.h +15 -0
  45. package/src/native/video.cpp +90 -0
  46. package/src/native/video.h +12 -0
  47. package/src/native/window.cpp +755 -0
  48. package/src/native/window.h +29 -0
  49. package/src/types/index.d.ts +7 -4
  50. package/scripts/test.mjs +0 -12
  51. package/src/native/asprintf.c +0 -47
  52. package/src/native/asprintf.h +0 -37
  53. package/src/native/binding.cpp +0 -1680
  54. package/src/native/sdl-helpers.cpp +0 -2619
  55. package/src/native/sdl-helpers.h +0 -182
@@ -0,0 +1,388 @@
1
+ #include "joystick.h"
2
+ #include "global.h"
3
+ #include <SDL.h>
4
+ #include <string>
5
+ #include <sstream>
6
+
7
+
8
+ double
9
+ joystick::mapAxis (int value) {
10
+ const static int SDL_JOYSTICK_AXIS_RANGE = SDL_JOYSTICK_AXIS_MAX - SDL_JOYSTICK_AXIS_MIN;
11
+ return (value - SDL_JOYSTICK_AXIS_MIN) / (SDL_JOYSTICK_AXIS_RANGE / 2.0) - 1;
12
+ }
13
+
14
+ Napi::Array
15
+ joystick::_getDevices (Napi::Env &env)
16
+ {
17
+ int num_devices = SDL_NumJoysticks();
18
+ if (num_devices < 0) {
19
+ std::ostringstream message;
20
+ message << "SDL_NumJoysticks() error: " << SDL_GetError();
21
+ SDL_ClearError();
22
+ throw Napi::Error::New(env, message.str());
23
+ }
24
+
25
+ Napi::Array devices = Napi::Array::New(env, num_devices);
26
+
27
+ for (int i = 0; i < num_devices; i++) {
28
+ int id = SDL_JoystickGetDeviceInstanceID(i);
29
+ if (id == -1) {
30
+ std::ostringstream message;
31
+ message << "SDL_JoystickGetDeviceInstanceID(" << i << ") error: " << SDL_GetError();
32
+ SDL_ClearError();
33
+ throw Napi::Error::New(env, message.str());
34
+ }
35
+
36
+ int type = SDL_JoystickGetDeviceType(i);
37
+ // This function can only error if the index is invalid.
38
+
39
+ const char *name = SDL_JoystickNameForIndex(i);
40
+ if (name == nullptr) {
41
+ std::ostringstream message;
42
+ message << "SDL_JoystickNameForIndex(" << i << ") error: " << SDL_GetError();
43
+ SDL_ClearError();
44
+ throw Napi::Error::New(env, message.str());
45
+ }
46
+
47
+ const char *path = SDL_JoystickPathForIndex(i);
48
+ if (path == nullptr) {
49
+ std::ostringstream message;
50
+ message << "SDL_JoystickPathForIndex(" << i << ") error: " << SDL_GetError();
51
+ SDL_ClearError();
52
+ throw Napi::Error::New(env, message.str());
53
+ }
54
+
55
+ SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(i);
56
+ // This function can only error if the index is invalid.
57
+
58
+ char guid_string[33];
59
+ SDL_JoystickGetGUIDString(guid, guid_string, 33);
60
+
61
+ int vendor_number = SDL_JoystickGetDeviceVendor(i);
62
+ Napi::Value vendor = vendor_number == 0 ? env.Null() : Napi::Number::New(env, vendor_number);
63
+
64
+ int product_number = SDL_JoystickGetDeviceProduct(i);
65
+ Napi::Value product = product_number == 0 ? env.Null() : Napi::Number::New(env, product_number);
66
+
67
+ int version_number = SDL_JoystickGetDeviceProductVersion(i);
68
+ Napi::Value version = version_number == 0 ? env.Null() : Napi::Number::New(env, version_number);
69
+
70
+ int player_number = SDL_JoystickGetDevicePlayerIndex(i);
71
+ Napi::Value player = player_number == -1 ? env.Null() : Napi::Number::New(env, player_number);
72
+
73
+ bool is_controller = SDL_IsGameController(i);
74
+
75
+ Napi::Value mapping;
76
+ if (is_controller) {
77
+ const char *device_mapping = SDL_GameControllerMappingForDeviceIndex(i);
78
+ if (device_mapping == nullptr) {
79
+ std::ostringstream message;
80
+ message << "SDL_GameControllerMappingForDeviceIndex(" << i << ") error: " << SDL_GetError();
81
+ SDL_ClearError();
82
+ throw Napi::Error::New(env, message.str());
83
+ }
84
+ mapping = Napi::String::New(env, device_mapping);
85
+ } else {
86
+ mapping = env.Null();
87
+ }
88
+
89
+ Napi::Object device = Napi::Object::New(env);
90
+ device.Set("_index", Napi::Number::New(env, i));
91
+ device.Set("id", Napi::Number::New(env, id));
92
+ device.Set("type", Napi::Number::New(env, type));
93
+ device.Set("name", Napi::String::New(env, name));
94
+ device.Set("path", Napi::String::New(env, path));
95
+ device.Set("guid", Napi::String::New(env, guid_string));
96
+ device.Set("vendor", vendor);
97
+ device.Set("product", product);
98
+ device.Set("version", version);
99
+ device.Set("player", player);
100
+ device.Set("isController", Napi::Boolean::New(env, is_controller));
101
+ device.Set("mapping", mapping);
102
+
103
+ devices.Set(i, device);
104
+ }
105
+
106
+ return devices;
107
+ }
108
+
109
+
110
+ Napi::Value
111
+ joystick::getDevices(const Napi::CallbackInfo &info)
112
+ {
113
+ Napi::Env env = info.Env();
114
+
115
+ return joystick::_getDevices(env);
116
+ }
117
+
118
+ Napi::Value
119
+ joystick::open (const Napi::CallbackInfo &info)
120
+ {
121
+ Napi::Env env = info.Env();
122
+
123
+ int index = info[0].As<Napi::Number>().Int32Value();
124
+
125
+ SDL_Joystick *joystick = SDL_JoystickOpen(index);
126
+ if (joystick == nullptr) {
127
+ std::ostringstream message;
128
+ message << "SDL_JoystickOpen(" << index << ") error: " << SDL_GetError();
129
+ SDL_ClearError();
130
+ throw Napi::Error::New(env, message.str());
131
+ }
132
+
133
+ SDL_JoystickID joystick_id = SDL_JoystickInstanceID(joystick);
134
+ if (joystick_id < 0) {
135
+ std::ostringstream message;
136
+ message << "SDL_JoystickInstanceID(" << index << ") error: " << SDL_GetError();
137
+ SDL_ClearError();
138
+ throw Napi::Error::New(env, message.str());
139
+ }
140
+
141
+ int firmware = SDL_JoystickGetFirmwareVersion(joystick);
142
+ Napi::Value firmware_version = firmware == 0 ? env.Null() : Napi::Number::New(env, firmware);
143
+
144
+ const char *serial = SDL_JoystickGetSerial(joystick);
145
+ Napi::Value serial_number = serial == 0 ? env.Null() : Napi::String::New(env, serial);
146
+
147
+ SDL_bool has_led = SDL_JoystickHasLED(joystick);
148
+ SDL_bool has_rumble = SDL_JoystickHasRumble(joystick);
149
+ SDL_bool has_rumble_triggers = SDL_JoystickHasRumbleTriggers(joystick);
150
+
151
+ int num_axes = SDL_JoystickNumAxes(joystick);
152
+ if (num_axes < 0) {
153
+ std::ostringstream message;
154
+ message << "SDL_JoystickNumAxes(" << index << ") error: " << SDL_GetError();
155
+ SDL_ClearError();
156
+ throw Napi::Error::New(env, message.str());
157
+ }
158
+
159
+ Napi::Array axes = Napi::Array::New(env, num_axes);
160
+
161
+ for (int i = 0; i < num_axes; i++) {
162
+ double value = joystick::mapAxis(SDL_JoystickGetAxis(joystick, i));
163
+ const char *error = SDL_GetError();
164
+ if (error != global::no_error) {
165
+ std::ostringstream message;
166
+ message << "SDL_JoystickGetAxis(" << index << ", " << i << ") error: " << SDL_GetError();
167
+ SDL_ClearError();
168
+ throw Napi::Error::New(env, message.str());
169
+ }
170
+ axes.Set(i, Napi::Number::New(env, value));
171
+ }
172
+
173
+ int num_balls = SDL_JoystickNumBalls(joystick);
174
+ if (num_balls < 0) {
175
+ std::ostringstream message;
176
+ message << "SDL_JoystickNumBalls(" << index << ") error: " << SDL_GetError();
177
+ SDL_ClearError();
178
+ throw Napi::Error::New(env, message.str());
179
+ }
180
+
181
+ Napi::Array balls = Napi::Array::New(env, num_balls);
182
+
183
+ for (int i = 0; i < num_balls; i++) {
184
+ int dx, dy;
185
+ if (SDL_JoystickGetBall(joystick, i, &dx, &dy) == -1) {
186
+ std::ostringstream message;
187
+ message << "SDL_JoystickGetBall(" << index << ", " << i << ") error: " << SDL_GetError();
188
+ SDL_ClearError();
189
+ throw Napi::Error::New(env, message.str());
190
+ }
191
+
192
+ Napi::Object ball = Napi::Object::New(env);
193
+ ball.Set("x", Napi::Number::New(env, dx));
194
+ ball.Set("y", Napi::Number::New(env, dy));
195
+
196
+ balls.Set(i, ball);
197
+ }
198
+
199
+ int num_buttons = SDL_JoystickNumButtons(joystick);
200
+ if (num_buttons < 0) {
201
+ std::ostringstream message;
202
+ message << "SDL_JoystickNumButtons(" << index << ") error: " << SDL_GetError();
203
+ SDL_ClearError();
204
+ throw Napi::Error::New(env, message.str());
205
+ }
206
+
207
+ Napi::Array buttons = Napi::Array::New(env, num_buttons);
208
+
209
+ for (int i = 0; i < num_buttons; i++) {
210
+ int pressed = SDL_JoystickGetButton(joystick, i);
211
+ buttons.Set(i, Napi::Boolean::New(env, pressed));
212
+ }
213
+
214
+ int num_hats = SDL_JoystickNumHats(joystick);
215
+ if (num_hats < 0) {
216
+ std::ostringstream message;
217
+ message << "SDL_JoystickNumHats(" << index << ") error: " << SDL_GetError();
218
+ SDL_ClearError();
219
+ throw Napi::Error::New(env, message.str());
220
+ }
221
+
222
+ Napi::Array hats = Napi::Array::New(env, num_hats);
223
+
224
+ for (int i = 0; i < num_hats; i++) {
225
+ int position = SDL_JoystickGetHat(joystick, i);
226
+ hats.Set(i, Napi::Number::New(env, position));
227
+ }
228
+
229
+ Napi::Object result = Napi::Object::New(env);
230
+ // result.Set("id", Napi::Number::New(env, joystick_id)); // NOTE: Unused. Same as the device id
231
+ result.Set("firmwareVersion", firmware_version);
232
+ result.Set("serialNumber", serial_number);
233
+ result.Set("hasLed", Napi::Boolean::New(env, has_led));
234
+ result.Set("hasRumble", Napi::Boolean::New(env, has_rumble));
235
+ result.Set("hasRumbleTriggers", Napi::Boolean::New(env, has_rumble_triggers));
236
+ result.Set("axes", axes);
237
+ result.Set("balls", balls);
238
+ result.Set("buttons", buttons);
239
+ result.Set("hats", hats);
240
+
241
+ return result;
242
+ }
243
+
244
+ Napi::Value
245
+ joystick::getPower (const Napi::CallbackInfo &info)
246
+ {
247
+ Napi::Env env = info.Env();
248
+
249
+ int joystick_id = info[0].As<Napi::Number>().Int32Value();
250
+
251
+ SDL_Joystick *joystick = SDL_JoystickFromInstanceID(joystick_id);
252
+ if (joystick == nullptr) {
253
+ std::ostringstream message;
254
+ message << "SDL_JoystickFromInstanceID(" << joystick_id << ") error: " << SDL_GetError();
255
+ SDL_ClearError();
256
+ throw Napi::Error::New(env, message.str());
257
+ }
258
+
259
+ SDL_JoystickPowerLevel power = SDL_JoystickCurrentPowerLevel(joystick);
260
+ if (power == SDL_JOYSTICK_POWER_UNKNOWN) { return env.Null(); }
261
+
262
+ return Napi::Number::New(env, power);
263
+ }
264
+
265
+ Napi::Value
266
+ joystick::rumble (const Napi::CallbackInfo &info)
267
+ {
268
+ Napi::Env env = info.Env();
269
+
270
+ int joystick_id = info[0].As<Napi::Number>().Int32Value();
271
+ double low_freq_rumble = info[1].As<Napi::Number>().DoubleValue();
272
+ double high_freq_rumble = info[2].As<Napi::Number>().DoubleValue();
273
+ int duration = info[3].As<Napi::Number>().Int32Value();
274
+
275
+ SDL_Joystick *joystick = SDL_JoystickFromInstanceID(joystick_id);
276
+ if (joystick == nullptr) {
277
+ std::ostringstream message;
278
+ message << "SDL_JoystickFromInstanceID(" << joystick_id << ") error: " << SDL_GetError();
279
+ SDL_ClearError();
280
+ throw Napi::Error::New(env, message.str());
281
+ }
282
+
283
+ if (SDL_JoystickRumble(joystick, low_freq_rumble * 0xFFFF, high_freq_rumble * 0xFFFF, duration) == -1) {
284
+ std::ostringstream message;
285
+ message << "SDL_JoystickRumble(" << joystick_id << ") error: " << SDL_GetError();
286
+ SDL_ClearError();
287
+ throw Napi::Error::New(env, message.str());
288
+ }
289
+
290
+ return env.Undefined();
291
+ }
292
+
293
+ Napi::Value
294
+ joystick::setLed (const Napi::CallbackInfo &info)
295
+ {
296
+ Napi::Env env = info.Env();
297
+
298
+ int joystick_id = info[0].As<Napi::Number>().Int32Value();
299
+ double red = info[1].As<Napi::Number>().DoubleValue();
300
+ double green = info[2].As<Napi::Number>().DoubleValue();
301
+ double blue = info[3].As<Napi::Number>().DoubleValue();
302
+
303
+ SDL_Joystick *joystick = SDL_JoystickFromInstanceID(joystick_id);
304
+ if (joystick == nullptr) {
305
+ std::ostringstream message;
306
+ message << "SDL_JoystickFromInstanceID(" << joystick_id << ") error: " << SDL_GetError();
307
+ SDL_ClearError();
308
+ throw Napi::Error::New(env, message.str());
309
+ }
310
+
311
+ if (SDL_JoystickSetLED(joystick, red * 0xFF, green * 0xFF, blue * 0xFF) == -1) {
312
+ std::ostringstream message;
313
+ message << "SDL_JoystickSetLED(" << joystick_id << ") error: " << SDL_GetError();
314
+ SDL_ClearError();
315
+ throw Napi::Error::New(env, message.str());
316
+ }
317
+
318
+ return env.Undefined();
319
+ }
320
+
321
+ Napi::Value
322
+ joystick::setPlayer (const Napi::CallbackInfo &info)
323
+ {
324
+ Napi::Env env = info.Env();
325
+
326
+ int joystick_id = info[0].As<Napi::Number>().Int32Value();
327
+ int player = info[1].As<Napi::Number>().Int32Value();
328
+
329
+ SDL_Joystick *joystick = SDL_JoystickFromInstanceID(joystick_id);
330
+ if (joystick == nullptr) {
331
+ std::ostringstream message;
332
+ message << "SDL_JoystickFromInstanceID(" << joystick_id << ") error: " << SDL_GetError();
333
+ SDL_ClearError();
334
+ throw Napi::Error::New(env, message.str());
335
+ }
336
+
337
+ SDL_JoystickSetPlayerIndex(joystick, player);
338
+
339
+ return env.Undefined();
340
+ }
341
+
342
+ Napi::Value
343
+ joystick::rumbleTriggers (const Napi::CallbackInfo &info)
344
+ {
345
+ Napi::Env env = info.Env();
346
+
347
+ int joystick_id = info[0].As<Napi::Number>().Int32Value();
348
+ double left_rumble = info[1].As<Napi::Number>().DoubleValue();
349
+ double right_rumble = info[2].As<Napi::Number>().DoubleValue();
350
+ int duration = info[3].As<Napi::Number>().Int32Value();
351
+
352
+ SDL_Joystick *joystick = SDL_JoystickFromInstanceID(joystick_id);
353
+ if (joystick == nullptr) {
354
+ std::ostringstream message;
355
+ message << "SDL_JoystickFromInstanceID(" << joystick_id << ") error: " << SDL_GetError();
356
+ SDL_ClearError();
357
+ throw Napi::Error::New(env, message.str());
358
+ }
359
+
360
+ if (SDL_JoystickRumbleTriggers(joystick, left_rumble * 0xFFFF, right_rumble * 0xFFFF, duration) == -1) {
361
+ std::ostringstream message;
362
+ message << "SDL_JoystickRumbleTriggers(" << joystick_id << ") error: " << SDL_GetError();
363
+ SDL_ClearError();
364
+ throw Napi::Error::New(env, message.str());
365
+ }
366
+
367
+ return env.Undefined();
368
+ }
369
+
370
+ Napi::Value
371
+ joystick::close (const Napi::CallbackInfo &info)
372
+ {
373
+ Napi::Env env = info.Env();
374
+
375
+ int joystick_id = info[0].As<Napi::Number>().Int32Value();
376
+
377
+ SDL_Joystick *joystick = SDL_JoystickFromInstanceID(joystick_id);
378
+ if (joystick == nullptr) {
379
+ std::ostringstream message;
380
+ message << "SDL_JoystickFromInstanceID(" << joystick_id << ") error: " << SDL_GetError();
381
+ SDL_ClearError();
382
+ throw Napi::Error::New(env, message.str());
383
+ }
384
+
385
+ SDL_JoystickClose(joystick);
386
+
387
+ return env.Undefined();
388
+ }
@@ -0,0 +1,22 @@
1
+ #ifndef _JOYSTICK_H_
2
+ #define _JOYSTICK_H_
3
+
4
+ #include <napi.h>
5
+
6
+ namespace joystick {
7
+
8
+ double mapAxis (int value);
9
+ Napi::Array _getDevices (Napi::Env &env);
10
+
11
+ Napi::Value getDevices(const Napi::CallbackInfo &info);
12
+ Napi::Value open(const Napi::CallbackInfo &info);
13
+ Napi::Value getPower(const Napi::CallbackInfo &info);
14
+ Napi::Value setLed(const Napi::CallbackInfo &info);
15
+ Napi::Value setPlayer(const Napi::CallbackInfo &info);
16
+ Napi::Value rumble(const Napi::CallbackInfo &info);
17
+ Napi::Value rumbleTriggers(const Napi::CallbackInfo &info);
18
+ Napi::Value close(const Napi::CallbackInfo &info);
19
+
20
+ }; // namespace joystick
21
+
22
+ #endif // _JOYSTICK_H_
@@ -0,0 +1,55 @@
1
+ #include "keyboard.h"
2
+ #include <SDL.h>
3
+ #include <string>
4
+ #include <sstream>
5
+
6
+ int keyboard::num_keys;
7
+ const Uint8 *keyboard::keys;
8
+
9
+
10
+ Napi::Value
11
+ keyboard::getKey(const Napi::CallbackInfo &info)
12
+ {
13
+ Napi::Env env = info.Env();
14
+
15
+ int scancode = info[0].As<Napi::Number>().Int32Value();
16
+
17
+ int keycode = SDL_GetKeyFromScancode((SDL_Scancode) scancode);
18
+ const char *keyname = SDL_GetKeyName(keycode);
19
+
20
+ return Napi::String::New(env, keyname);
21
+ }
22
+
23
+ Napi::Value
24
+ keyboard::getScancode(const Napi::CallbackInfo &info)
25
+ {
26
+ Napi::Env env = info.Env();
27
+
28
+ std::string keyname = info[0].As<Napi::String>().Utf8Value();
29
+
30
+ SDL_Keycode keycode = SDL_GetKeyFromName(keyname.c_str());
31
+ if (keycode == SDLK_UNKNOWN) {
32
+ std::ostringstream message;
33
+ message << "SDL_GetKeyFromName(" << keyname << ") error: " << SDL_GetError();
34
+ SDL_ClearError();
35
+ throw Napi::Error::New(env, message.str());
36
+ }
37
+
38
+ int scancode = SDL_GetScancodeFromKey(keycode);
39
+
40
+ return Napi::Number::New(env, scancode);
41
+ }
42
+
43
+ Napi::Value
44
+ keyboard::getState(const Napi::CallbackInfo &info)
45
+ {
46
+ Napi::Env env = info.Env();
47
+
48
+ Napi::Array result = Napi::Array::New(env, keyboard::num_keys);
49
+
50
+ for (int i = 0 ; i < keyboard::num_keys; i++) {
51
+ result.Set(i, Napi::Boolean::New(env, !!keyboard::keys[i]));
52
+ }
53
+
54
+ return result;
55
+ }
@@ -0,0 +1,18 @@
1
+ #ifndef _KEYBOARD_H_
2
+ #define _KEYBOARD_H_
3
+
4
+ #include <napi.h>
5
+ #include <SDL.h>
6
+
7
+ namespace keyboard {
8
+
9
+ extern int num_keys;
10
+ extern const Uint8 *keys;
11
+
12
+ Napi::Value getKey(const Napi::CallbackInfo &info);
13
+ Napi::Value getScancode(const Napi::CallbackInfo &info);
14
+ Napi::Value getState(const Napi::CallbackInfo &info);
15
+
16
+ }; // namespace keyboard
17
+
18
+ #endif // _KEYBOARD_H_
@@ -0,0 +1,98 @@
1
+ #include <napi.h>
2
+
3
+ #include "enums.h"
4
+ #include "global.h"
5
+ #include "events.h"
6
+ #include "video.h"
7
+ #include "window.h"
8
+ #include "keyboard.h"
9
+ #include "mouse.h"
10
+ #include "joystick.h"
11
+ #include "controller.h"
12
+ #include "sensor.h"
13
+ #include "audio.h"
14
+ #include "clipboard.h"
15
+ #include "power.h"
16
+
17
+
18
+ Napi::Object
19
+ init (Napi::Env env, Napi::Object exports)
20
+ {
21
+ exports.Set("enums_get", Napi::Function::New<enums::get>(env));
22
+
23
+ exports.Set("global_initialize", Napi::Function::New<global::initialize>(env));
24
+ exports.Set("global_cleanup", Napi::Function::New<global::cleanup>(env));
25
+
26
+ exports.Set("events_poll", Napi::Function::New<events::poll>(env));
27
+
28
+ exports.Set("video_getDisplays", Napi::Function::New<video::getDisplays>(env));
29
+
30
+ exports.Set("window_create", Napi::Function::New<window::create>(env));
31
+ exports.Set("window_setTitle", Napi::Function::New<window::setTitle>(env));
32
+ exports.Set("window_setPosition", Napi::Function::New<window::setPosition>(env));
33
+ exports.Set("window_setSize", Napi::Function::New<window::setSize>(env));
34
+ exports.Set("window_setFullscreen", Napi::Function::New<window::setFullscreen>(env));
35
+ exports.Set("window_setResizable", Napi::Function::New<window::setResizable>(env));
36
+ exports.Set("window_setBorderless", Napi::Function::New<window::setBorderless>(env));
37
+ exports.Set("window_setAcceleratedAndVsync", Napi::Function::New<window::setAcceleratedAndVsync>(env));
38
+ exports.Set("window_focus", Napi::Function::New<window::focus>(env));
39
+ exports.Set("window_show", Napi::Function::New<window::show>(env));
40
+ exports.Set("window_hide", Napi::Function::New<window::hide>(env));
41
+ exports.Set("window_maximize", Napi::Function::New<window::maximize>(env));
42
+ exports.Set("window_minimize", Napi::Function::New<window::minimize>(env));
43
+ exports.Set("window_restore", Napi::Function::New<window::restore>(env));
44
+ exports.Set("window_render", Napi::Function::New<window::render>(env));
45
+ exports.Set("window_setIcon", Napi::Function::New<window::setIcon>(env));
46
+ exports.Set("window_flash", Napi::Function::New<window::flash>(env));
47
+ exports.Set("window_destroy", Napi::Function::New<window::destroy>(env));
48
+
49
+ exports.Set("keyboard_getKey", Napi::Function::New<keyboard::getKey>(env));
50
+ exports.Set("keyboard_getScancode", Napi::Function::New<keyboard::getScancode>(env));
51
+ exports.Set("keyboard_getState", Napi::Function::New<keyboard::getState>(env));
52
+
53
+ exports.Set("mouse_getButton", Napi::Function::New<mouse::getButton>(env));
54
+ exports.Set("mouse_getPosition", Napi::Function::New<mouse::getPosition>(env));
55
+ exports.Set("mouse_setPosition", Napi::Function::New<mouse::setPosition>(env));
56
+ exports.Set("mouse_capture", Napi::Function::New<mouse::capture>(env));
57
+ exports.Set("mouse_setCursor", Napi::Function::New<mouse::setCursor>(env));
58
+ exports.Set("mouse_resetCursor", Napi::Function::New<mouse::resetCursor>(env));
59
+ exports.Set("mouse_setCursorImage", Napi::Function::New<mouse::setCursorImage>(env));
60
+ exports.Set("mouse_showCursor", Napi::Function::New<mouse::showCursor>(env));
61
+ exports.Set("mouse_redrawCursor", Napi::Function::New<mouse::redrawCursor>(env));
62
+
63
+ exports.Set("joystick_getDevices", Napi::Function::New<joystick::getDevices>(env));
64
+ exports.Set("joystick_open", Napi::Function::New<joystick::open>(env));
65
+ exports.Set("joystick_getPower", Napi::Function::New<joystick::getPower>(env));
66
+ exports.Set("joystick_setLed", Napi::Function::New<joystick::setLed>(env));
67
+ exports.Set("joystick_setPlayer", Napi::Function::New<joystick::setPlayer>(env));
68
+ exports.Set("joystick_rumble", Napi::Function::New<joystick::rumble>(env));
69
+ exports.Set("joystick_rumbleTriggers", Napi::Function::New<joystick::rumbleTriggers>(env));
70
+ exports.Set("joystick_close", Napi::Function::New<joystick::close>(env));
71
+
72
+ exports.Set("controller_addMappings", Napi::Function::New<controller::addMappings>(env));
73
+ exports.Set("controller_open", Napi::Function::New<controller::open>(env));
74
+ exports.Set("controller_close", Napi::Function::New<controller::close>(env));
75
+
76
+ exports.Set("sensor_getDevices", Napi::Function::New<sensor::getDevices>(env));
77
+ exports.Set("sensor_open", Napi::Function::New<sensor::open>(env));
78
+ exports.Set("sensor_getData", Napi::Function::New<sensor::getData>(env));
79
+ exports.Set("sensor_close", Napi::Function::New<sensor::close>(env));
80
+
81
+ exports.Set("audio_getDevices", Napi::Function::New<audio::getDevices>(env));
82
+ exports.Set("audio_open", Napi::Function::New<audio::open>(env));
83
+ exports.Set("audio_play", Napi::Function::New<audio::play>(env));
84
+ exports.Set("audio_getQueueSize", Napi::Function::New<audio::getQueueSize>(env));
85
+ exports.Set("audio_enqueue", Napi::Function::New<audio::enqueue>(env));
86
+ exports.Set("audio_dequeue", Napi::Function::New<audio::dequeue>(env));
87
+ exports.Set("audio_clearQueue", Napi::Function::New<audio::clearQueue>(env));
88
+ exports.Set("audio_close", Napi::Function::New<audio::close>(env));
89
+
90
+ exports.Set("clipboard_getText", Napi::Function::New<clipboard::getText>(env));
91
+ exports.Set("clipboard_setText", Napi::Function::New<clipboard::setText>(env));
92
+
93
+ exports.Set("power_getInfo", Napi::Function::New<power::getInfo>(env));
94
+
95
+ return exports;
96
+ }
97
+
98
+ NODE_API_MODULE(NODE_GYP_MODULE_NAME, init)