@kmamal/sdl 0.9.6-0 → 0.10.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 (48) hide show
  1. package/README.md +79 -90
  2. package/package.json +4 -3
  3. package/scripts/util/common.js +2 -0
  4. package/src/javascript/audio/audio-instance.js +1 -1
  5. package/src/javascript/audio/index.js +1 -0
  6. package/src/javascript/clipboard/index.js +6 -1
  7. package/src/javascript/controller/controller-instance.js +12 -9
  8. package/src/javascript/controller/index.js +5 -2
  9. package/src/javascript/enums.js +0 -8
  10. package/src/javascript/events/events-via-poll.js +3 -3
  11. package/src/javascript/events/index.js +57 -55
  12. package/src/javascript/globals.js +1 -1
  13. package/src/javascript/joystick/device.js +0 -3
  14. package/src/javascript/joystick/index.js +5 -2
  15. package/src/javascript/joystick/joystick-instance.js +23 -13
  16. package/src/javascript/keyboard/index.js +7 -3
  17. package/src/javascript/keyboard/key-mapping.js +2 -2
  18. package/src/javascript/mouse/index.js +2 -2
  19. package/src/javascript/power/index.js +1 -6
  20. package/src/javascript/sensor/sensor-instance.js +1 -1
  21. package/src/javascript/video/index.js +5 -6
  22. package/src/javascript/video/window.js +1 -1
  23. package/src/native/audio.cpp +10 -2
  24. package/src/native/controller.cpp +9 -1
  25. package/src/native/controller.h +5 -0
  26. package/src/native/enums.cpp +3 -141
  27. package/src/native/enums.h +0 -55
  28. package/src/native/events.cpp +115 -63
  29. package/src/native/events.h +55 -0
  30. package/src/native/global.cpp +184 -13
  31. package/src/native/joystick.cpp +20 -10
  32. package/src/native/joystick.h +7 -0
  33. package/src/native/keyboard.cpp +5 -3
  34. package/src/native/power.cpp +6 -1
  35. package/src/native/power.h +5 -0
  36. package/src/native/sensor.cpp +9 -2
  37. package/src/native/sensor.h +6 -0
  38. package/src/native/video.cpp +6 -1
  39. package/src/native/video.h +4 -0
  40. package/src/native/window.cpp +24 -97
  41. package/src/native/window.h +1 -0
  42. package/src/types/index.d.ts +84 -45
  43. package/scripts/install-deps-mac.sh +0 -2
  44. package/scripts/install-deps-raspbian.sh +0 -5
  45. package/scripts/install-deps-ubuntu.sh +0 -5
  46. package/scripts/release-rpi-qemu.sh +0 -116
  47. package/scripts/release.mjs +0 -13
  48. package/scripts/upload-release.mjs +0 -86
package/README.md CHANGED
@@ -118,8 +118,8 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
118
118
  * [sdl.info](#sdlinfo)
119
119
  * [sdl.video](#sdlvideo)
120
120
  * [Image data](#image-data)
121
+ * [High-DPI](#high-dpi)
121
122
  * [Pixel formats](#pixel-formats)
122
- * [High-DPI](#highdpi)
123
123
  * [Event: 'displayAdd'](#event-displayadd)
124
124
  * [Event: 'displayRemove'](#event-displayremove)
125
125
  * [Event: 'displayOrient'](#event-displayorient)
@@ -207,7 +207,6 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
207
207
  * [sdl.keyboard.getScancode(key)](#sdlkeyboardgetscancodekey)
208
208
  * [sdl.keyboard.getState()](#sdlkeyboardgetstate)
209
209
  * [sdl.mouse](#sdlmouse)
210
- * [Mouse cursors](#mouse-cursors)
211
210
  * [Enum: BUTTON](#enum-button)
212
211
  * [sdl.mouse.getButton(button)](#sdlmousegetbuttonbutton)
213
212
  * [sdl.mouse.position](#sdlmouseposition)
@@ -221,9 +220,7 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
221
220
  * [sdl.mouse.capture([capture])](#sdlmousecapturecapture)
222
221
  * [sdl.mouse.uncapture()](#sdlmouseuncapture)
223
222
  * [sdl.joystick](#sdljoystick)
224
- * [Joystick types](#joystick-types)
225
223
  * [Hat positions](#hat-positions)
226
- * [Power levels](#power-levels)
227
224
  * [Event: 'deviceAdd'](#joystick-event-deviceadd)
228
225
  * [Event: 'deviceRemove'](#joystick-event-deviceremove)
229
226
  * [sdl.joystick.devices](#sdljoystickdevices)
@@ -429,6 +426,14 @@ for (let i = 0; i < height; i++) {
429
426
  window.render(width, height, stride, 'rgba32', buffer)
430
427
  ```
431
428
 
429
+ ### High-DPI
430
+
431
+ On a high-dpi display, windows have more pixels that their `width` and `height` would indicate.
432
+ On such systems `width` and `height` (and all other measurements such as `x` and `y`) are in "points".
433
+ Points are abstract and don't have to correspond to pixels.
434
+ If you need to know a window's width and height in pixels, you should use the `pixelWidth` and `pixelHeight` properties.
435
+ You should be doing this always, since you don't know beforehand if your program will be running on a high-dpi system.
436
+
432
437
  ### Pixel formats
433
438
 
434
439
  String values used to represent how the pixels of an image are stored in a Buffer.
@@ -473,15 +478,6 @@ String values used to represent how the pixels of an image are stored in a Buffe
473
478
  | `'nv21'` | `SDL_PIXELFORMAT_NV21` | planar mode: Y + V/U interleaved (2 planes) |
474
479
 
475
480
 
476
- ### High-DPI
477
-
478
- On a high-dpi display, windows have more pixels that their `width` and `height` would indicate.
479
- On such systems `width` and `height` (and all other measurements such as `x` and `y`) are in "points".
480
- Points are abstract and don't have to correspond to pixels.
481
- If you need to know a window's width and height in pixels, you should use the `pixelWidth` and `pixelHeight` properties.
482
- You should be doing this always, since you don't know beforehand if your program will be running on a high-dpi system.
483
-
484
-
485
481
  ### Event: 'displayAdd'
486
482
 
487
483
  * `device: <object>`: An object from [`sdl.video.displays`](#sdlvideodisplays) indicating the display that caused the event.
@@ -489,7 +485,6 @@ You should be doing this always, since you don't know beforehand if your program
489
485
  Fired when a display is added to the system.
490
486
  Check [`sdl.video.displays`](#sdlvideodisplays) to get the new list of displays.
491
487
 
492
-
493
488
  ### Event: 'displayRemove'
494
489
 
495
490
  * `device: <object>`: An object from [`sdl.video.displays`](#sdlvideodisplays) indicating the display that caused the event.
@@ -497,7 +492,6 @@ Check [`sdl.video.displays`](#sdlvideodisplays) to get the new list of displays.
497
492
  Fired when a display is removed from the system.
498
493
  Check [`sdl.video.displays`](#sdlvideodisplays) to get the new list of displays.
499
494
 
500
-
501
495
  ### Event: 'displayOrient'
502
496
 
503
497
  * `device: <object>`: An object from [`sdl.video.displays`](#sdlvideodisplays) indicating the display that caused the event.
@@ -1085,6 +1079,16 @@ Trying to handle text input by manually translating key presses to text is not a
1085
1079
  It's better to let the OS handle all the text logic, and get the final text by handling the rasulting ([`'textInput'`](#event-textinput)) events.
1086
1080
 
1087
1081
 
1082
+ ### Virtual keys
1083
+
1084
+ String values used to represent virtual keys in the context of the current keyboard mapping.
1085
+ Note that some keys do not correspond to any virtual key.
1086
+ A Key can be either one of the values below __or__ any unicode character.
1087
+ Keys that produce characters are represented by that character.
1088
+ All others are represented by one of these values:
1089
+
1090
+ `'&&'`, `'+/-'`, `'||'`, `'00'`, `'000'`, `'again'`, `'alt'`, `'altErase'`, `'app1'`, `'app2'`, `'application'`, `'audioFastForward'`, `'audioMute'`, `'audioNext'`, `'audioPlay'`, `'audioPrev'`, `'audioRewind'`, `'audioStop'`, `'back'`, `'backspace'`, `'binary'`, `'bookmarks'`, `'brightnessDown'`, `'brightnessUp'`, `'calculator'`, `'cancel'`, `'capsLock'`, `'clear'`, `'clearEntry'`, `'computer'`, `'copy'`, `'crSel'`, `'ctrl'`, `'currencySubUnit'`, `'currencyUnit'`, `'cut'`, `'decimal'`, `'decimalSeparator'`, `'delete'`, `'displaySwitch'`, `'down'`, `'eject'`, `'end'`, `'enter'`, `'escape'`, `'execute'`, `'exSel'`, `'f1'`, `'f2'`, `'f3'`, `'f4'`, `'f5'`, `'f6'`, `'f7'`, `'f8'`, `'f9'`, `'f10'`, `'f11'`, `'f12'`, `'f13'`, `'f14'`, `'f15'`, `'f16'`, `'f17'`, `'f18'`, `'f19'`, `'f20'`, `'f21'`, `'f22'`, `'f23'`, `'f24'`, `'find'`, `'forward'`, `'gui'`, `'help'`, `'hexadecimal'`, `'home'`, `'illumDown'`, `'illumToggle'`, `'illumUp'`, `'insert'`, `'left'`, `'mail'`, `'mediaSelect'`, `'memAdd'`, `'memClear'`, `'memDivide'`, `'memMultiply'`, `'memRecall'`, `'memStore'`, `'memSubtract'`, `'menu'`, `'modeSwitch'`, `'mute'`, `'numlock'`, `'octal'`, `'oper'`, `'out'`, `'pageDown'`, `'pageUp'`, `'paste'`, `'pause'`, `'power'`, `'printScreen'`, `'prior'`, `'refresh'`, `'return'`, `'right'`, `'scrollLock'`, `'search'`, `'select'`, `'separator'`, `'shift'`, `'sleep'`, `'space'`, `'stop'`, `'sysReq'`, `'tab'`, `'thousandsSeparator'`, `'undo'`, `'up'`, `'volumeDown'`, `'volumeUp'`, `'www'`, `'xor'`.
1091
+
1088
1092
  ### Enum: SCANCODE
1089
1093
 
1090
1094
  Used to represent physical keys on the keyboard.
@@ -1340,16 +1344,6 @@ Values are based on the [USB usage page standard](https://www.usb.org/sites/defa
1340
1344
  | `sdl.keyboard.SCANCODE.AUDIOFASTFORWARD` | `SDL_SCANCODE_AUDIOFASTFORWARD` | |
1341
1345
  </details>
1342
1346
 
1343
- ### Virtual keys
1344
-
1345
- String values used to represent virtual keys in the context of the current keyboard mapping.
1346
- Note that some keys do not correspond to any virtual key.
1347
- A Key can be either one of the values below __or__ any unicode character.
1348
- Keys that produce characters are represented by that character.
1349
- All others are represented by one of these values:
1350
-
1351
- `'&&'`, `'+/-'`, `'||'`, `'00'`, `'000'`, `'again'`, `'alt'`, `'altErase'`, `'app1'`, `'app2'`, `'application'`, `'audioFastForward'`, `'audioMute'`, `'audioNext'`, `'audioPlay'`, `'audioPrev'`, `'audioRewind'`, `'audioStop'`, `'back'`, `'backspace'`, `'binary'`, `'bookmarks'`, `'brightnessDown'`, `'brightnessUp'`, `'calculator'`, `'cancel'`, `'capsLock'`, `'clear'`, `'clearEntry'`, `'computer'`, `'copy'`, `'crSel'`, `'ctrl'`, `'currencySubUnit'`, `'currencyUnit'`, `'cut'`, `'decimal'`, `'decimalSeparator'`, `'delete'`, `'displaySwitch'`, `'down'`, `'eject'`, `'end'`, `'enter'`, `'escape'`, `'execute'`, `'exSel'`, `'f1'`, `'f2'`, `'f3'`, `'f4'`, `'f5'`, `'f6'`, `'f7'`, `'f8'`, `'f9'`, `'f10'`, `'f11'`, `'f12'`, `'f13'`, `'f14'`, `'f15'`, `'f16'`, `'f17'`, `'f18'`, `'f19'`, `'f20'`, `'f21'`, `'f22'`, `'f23'`, `'f24'`, `'find'`, `'forward'`, `'gui'`, `'help'`, `'hexadecimal'`, `'home'`, `'illumDown'`, `'illumToggle'`, `'illumUp'`, `'insert'`, `'left'`, `'mail'`, `'mediaSelect'`, `'memAdd'`, `'memClear'`, `'memDivide'`, `'memMultiply'`, `'memRecall'`, `'memStore'`, `'memSubtract'`, `'menu'`, `'modeSwitch'`, `'mute'`, `'numlock'`, `'octal'`, `'oper'`, `'out'`, `'pageDown'`, `'pageUp'`, `'paste'`, `'pause'`, `'power'`, `'printScreen'`, `'prior'`, `'refresh'`, `'return'`, `'right'`, `'scrollLock'`, `'search'`, `'select'`, `'separator'`, `'shift'`, `'sleep'`, `'space'`, `'stop'`, `'sysReq'`, `'tab'`, `'thousandsSeparator'`, `'undo'`, `'up'`, `'volumeDown'`, `'volumeUp'`, `'www'`, `'xor'`.
1352
-
1353
1347
  ### sdl.keyboard.getKey(scancode)
1354
1348
 
1355
1349
  * `scancode: `[`<Scancode>`](#enum-scancode)
@@ -1377,25 +1371,6 @@ The values will be `true` for keys that are pressed and `false` otherwise.
1377
1371
 
1378
1372
  ## sdl.mouse
1379
1373
 
1380
- ### Mouse cursors
1381
-
1382
- String values used to represent the types of cursors available on most systems.
1383
-
1384
- | Value | Corresponding `SDL_SystemCursor` | Description |
1385
- | --- | --- | --- |
1386
- | `'arrow'` | `SDL_SYSTEM_CURSOR_ARROW` | arrow |
1387
- | `'ibeam'` | `SDL_SYSTEM_CURSOR_IBEAM` | i-beam |
1388
- | `'wait'` | `SDL_SYSTEM_CURSOR_WAIT` | wait |
1389
- | `'crosshair'` | `SDL_SYSTEM_CURSOR_CROSSHAIR` | crosshair |
1390
- | `'waitarrow'` | `SDL_SYSTEM_CURSOR_WAITARROW` | small wait cursor (or wait if not available) |
1391
- | `'sizenwse'` | `SDL_SYSTEM_CURSOR_SIZENWSE` | double arrow pointing northwest and southeast |
1392
- | `'sizenesw'` | `SDL_SYSTEM_CURSOR_SIZENESW` | double arrow pointing northeast and southwest |
1393
- | `'sizewe'` | `SDL_SYSTEM_CURSOR_SIZEWE` | double arrow pointing west and east |
1394
- | `'sizens'` | `SDL_SYSTEM_CURSOR_SIZENS` | double arrow pointing north and south |
1395
- | `'sizeall'` | `SDL_SYSTEM_CURSOR_SIZEALL` | four pointed arrow pointing north, south, east, and west |
1396
- | `'no'` | `SDL_SYSTEM_CURSOR_NO` | slashed circle or crossbones |
1397
- | `'hand'` | `SDL_SYSTEM_CURSOR_HAND` | hand |
1398
-
1399
1374
  ### Enum: BUTTON
1400
1375
 
1401
1376
  Used to represent the buttons on a mouse.
@@ -1431,10 +1406,27 @@ Moves the mouse to the specified position.
1431
1406
 
1432
1407
  ### sdl.mouse.setCursor(cursor)
1433
1408
 
1434
- * `cursor: `[`<MouseCursor>`](#mouse-cursors) The icon to use for the cursor.
1409
+ * `cursor: <MouseCursor>` The icon to use for the cursor.
1435
1410
 
1436
1411
  Changes the icon that is displayed for the mouse cursor.
1437
1412
 
1413
+ Possible values for `cursor` are:
1414
+
1415
+ | Value | Corresponding `SDL_SystemCursor` | Description |
1416
+ | --- | --- | --- |
1417
+ | `'arrow'` | `SDL_SYSTEM_CURSOR_ARROW` | arrow |
1418
+ | `'ibeam'` | `SDL_SYSTEM_CURSOR_IBEAM` | i-beam |
1419
+ | `'wait'` | `SDL_SYSTEM_CURSOR_WAIT` | wait |
1420
+ | `'crosshair'` | `SDL_SYSTEM_CURSOR_CROSSHAIR` | crosshair |
1421
+ | `'waitarrow'` | `SDL_SYSTEM_CURSOR_WAITARROW` | small wait cursor (or wait if not available) |
1422
+ | `'sizenwse'` | `SDL_SYSTEM_CURSOR_SIZENWSE` | double arrow pointing northwest and southeast |
1423
+ | `'sizenesw'` | `SDL_SYSTEM_CURSOR_SIZENESW` | double arrow pointing northeast and southwest |
1424
+ | `'sizewe'` | `SDL_SYSTEM_CURSOR_SIZEWE` | double arrow pointing west and east |
1425
+ | `'sizens'` | `SDL_SYSTEM_CURSOR_SIZENS` | double arrow pointing north and south |
1426
+ | `'sizeall'` | `SDL_SYSTEM_CURSOR_SIZEALL` | four pointed arrow pointing north, south, east, and west |
1427
+ | `'no'` | `SDL_SYSTEM_CURSOR_NO` | slashed circle or crossbones |
1428
+ | `'hand'` | `SDL_SYSTEM_CURSOR_HAND` | hand |
1429
+
1438
1430
  ### sdl.mouse.resetCursor()
1439
1431
 
1440
1432
  Switched back to the default cursor.
@@ -1475,27 +1467,11 @@ Equivalent to [`sdl.mouse.capture(false)`](#sdlmousecapturecapture).
1475
1467
 
1476
1468
  ## sdl.joystick
1477
1469
 
1478
- ### Joystick types
1479
-
1480
- String values used to represent the type of a joystick device.
1481
-
1482
- | Value | Corresponding `SDL_JoystickType` |
1483
- | --- | --- |
1484
- | `'gamecontroller'` | `SDL_JOYSTICK_TYPE_GAMECONTROLLER` |
1485
- | `'wheel'` | `SDL_JOYSTICK_TYPE_WHEEL` |
1486
- | `'arcadestick'` | `SDL_JOYSTICK_TYPE_ARCADE_STICK` |
1487
- | `'flightstick'` | `SDL_JOYSTICK_TYPE_FLIGHT_STICK` |
1488
- | `'dancepad'` | `SDL_JOYSTICK_TYPE_DANCE_PAD` |
1489
- | `'guitar'` | `SDL_JOYSTICK_TYPE_GUITAR` |
1490
- | `'drumkit'` | `SDL_JOYSTICK_TYPE_DRUM_KIT` |
1491
- | `'arcadepad'` | `SDL_JOYSTICK_TYPE_ARCADE_PAD` |
1492
- | `'throttle'` | `SDL_JOYSTICK_TYPE_THROTTLE` |
1493
-
1494
1470
  ### Hat positions
1495
1471
 
1496
1472
  String values used to represent the positions of a joystick hat
1497
1473
 
1498
- | Value | Corresponding SDL enum |
1474
+ | Value | Corresponding `SDL_HAT_*` |
1499
1475
  | --- | --- |
1500
1476
  | `'centered'` | `SDL_HAT_CENTERED` |
1501
1477
  | `'up'` | `SDL_HAT_UP` |
@@ -1507,19 +1483,6 @@ String values used to represent the positions of a joystick hat
1507
1483
  | `'leftup'` | `SDL_HAT_LEFTUP` |
1508
1484
  | `'leftdown'` | `SDL_HAT_LEFTDOWN` |
1509
1485
 
1510
- ### Power levels
1511
-
1512
- String values used to represent the power level of a joystick device.
1513
-
1514
- | Value | Corresponding `SDL_JoystickPowerLevel` |
1515
- | --- | --- |
1516
- | `'empty'` | `SDL_JOYSTICK_POWER_EMPTY` |
1517
- | `'low'` | `SDL_JOYSTICK_POWER_LOW` |
1518
- | `'medium'` | `SDL_JOYSTICK_POWER_MEDIUM` |
1519
- | `'full'` | `SDL_JOYSTICK_POWER_FULL` |
1520
- | `'wired'` | `SDL_JOYSTICK_POWER_WIRED` |
1521
- | `'max'` | `SDL_JOYSTICK_POWER_MAX` |
1522
-
1523
1486
  <a id="joystick-event-deviceadd"></a>
1524
1487
 
1525
1488
  ### Event: 'deviceAdd'
@@ -1543,16 +1506,31 @@ When this event is emitted, all instances that were opened from the removed devi
1543
1506
 
1544
1507
  * `<object>[]`
1545
1508
  * `id: <number>` The unique id for the device.
1546
- * `type:`[`<JoystickType>`](#joystick-types) The type of the device.
1509
+ * `type: <JoystickType>` The type of the device.
1547
1510
  * `name: <string>` The name of the device.
1548
1511
  * `path: <string>` The implementation dependent path of the device.
1549
1512
  * `guid: <string>` The GUID of the device.
1550
- * `vendor: <number>` The USB vendor ID of the device.
1551
- * `product: <number>` The USB product ID of the device.
1552
- * `version: <number>` The USB product version of the device.
1553
- * `player: <number>` The player index for the device.
1513
+ * `vendor: <number>|<null>` The USB vendor ID of the device. Will be `null` if it can't be determined.
1514
+ * `product: <number>|<null>` The USB product ID of the device. Will be `null` if it can't be determined.
1515
+ * `version: <number>|<null>` The USB product version of the device. Will be `null` if it can't be determined.
1516
+ * `player: <number>|<null>` The player index for the device. Will be `null` if it can't be determined.
1554
1517
 
1555
1518
  A list of all the detected joystick devices.
1519
+
1520
+ Possible values for `type` are:
1521
+
1522
+ | Value | Corresponding `SDL_JoystickType` |
1523
+ | --- | --- |
1524
+ | `'gamecontroller'` | `SDL_JOYSTICK_TYPE_GAMECONTROLLER` |
1525
+ | `'wheel'` | `SDL_JOYSTICK_TYPE_WHEEL` |
1526
+ | `'arcadestick'` | `SDL_JOYSTICK_TYPE_ARCADE_STICK` |
1527
+ | `'flightstick'` | `SDL_JOYSTICK_TYPE_FLIGHT_STICK` |
1528
+ | `'dancepad'` | `SDL_JOYSTICK_TYPE_DANCE_PAD` |
1529
+ | `'guitar'` | `SDL_JOYSTICK_TYPE_GUITAR` |
1530
+ | `'drumkit'` | `SDL_JOYSTICK_TYPE_DRUM_KIT` |
1531
+ | `'arcadepad'` | `SDL_JOYSTICK_TYPE_ARCADE_PAD` |
1532
+ | `'throttle'` | `SDL_JOYSTICK_TYPE_THROTTLE` |
1533
+
1556
1534
  Sample output:
1557
1535
 
1558
1536
  ```js
@@ -1679,9 +1657,20 @@ An array of values, each corresponding to the position of one of the joystick's
1679
1657
 
1680
1658
  ### joystickInstance.power
1681
1659
 
1682
- * [`<PowerLevel>`](#power-levels)`|<null>`
1660
+ * `<PowerLevel>|<null>`
1661
+
1662
+ The current power level of the joystick device, or `null` if it is unknown.
1683
1663
 
1684
- The current power level of the joystick device, or `null` if it is unknown;
1664
+ Possible values are:
1665
+
1666
+ | Value | Corresponding `SDL_JoystickPowerLevel` |
1667
+ | --- | --- |
1668
+ | `'empty'` | `SDL_JOYSTICK_POWER_EMPTY` |
1669
+ | `'low'` | `SDL_JOYSTICK_POWER_LOW` |
1670
+ | `'medium'` | `SDL_JOYSTICK_POWER_MEDIUM` |
1671
+ | `'full'` | `SDL_JOYSTICK_POWER_FULL` |
1672
+ | `'wired'` | `SDL_JOYSTICK_POWER_WIRED` |
1673
+ | `'max'` | `SDL_JOYSTICK_POWER_MAX` |
1685
1674
 
1686
1675
  ### joystickInstance.setPlayer(index)
1687
1676
 
@@ -1813,10 +1802,10 @@ This can cause already opened controller instances to be [remapped](#event-remap
1813
1802
  * `name: <string>` The name of the device.
1814
1803
  * `path: <string>` The implementation dependent path of the device.
1815
1804
  * `guid: <string>` The GUID of the device.
1816
- * `vendor: <number>` The USB vendor ID of the device.
1817
- * `product: <number>` The USB product ID of the device.
1818
- * `version: <number>` The USB product version of the device.
1819
- * `player: <number>` The player index for the device.
1805
+ * `vendor: <number>|<null>` The USB vendor ID of the device. Will be `null` if it can't be determined.
1806
+ * `product: <number>|<null>` The USB product ID of the device. Will be `null` if it can't be determined.
1807
+ * `version: <number>|<null>` The USB product version of the device. Will be `null` if it can't be determined.
1808
+ * `player: <number>|<null>` The player index for the device. Will be `null` if it can't be determined.
1820
1809
  * `mapping: <string>` The axis and button mapping for this device.
1821
1810
 
1822
1811
  A list of all the detected controller devices.
@@ -1854,7 +1843,7 @@ Instead, objects returned by [`sdl.controller.openDevice()`](#sdlcontrolleropend
1854
1843
 
1855
1844
  ### Event: 'axisMotion'
1856
1845
 
1857
- * `axis: <string>` The name of the axis that moved.
1846
+ * `axis:`[`<Axis>`](#controllerinstanceaxes) The axis that moved.
1858
1847
  * `value: <number>` The new axis position.
1859
1848
 
1860
1849
  Fired when one of the controller's axes moves.
@@ -1863,7 +1852,7 @@ Fired when one of the controller's axes moves.
1863
1852
 
1864
1853
  ### Event: 'buttonDown'
1865
1854
 
1866
- * `button: <string>` The name of the button that was pressed.
1855
+ * `button:`[`<Button>`](#controllerinstancebuttons) The button that was pressed.
1867
1856
 
1868
1857
  Fired when one of the controller's buttons is pressed.
1869
1858
 
@@ -2041,7 +2030,7 @@ Use this constant to correct for that if your application requires it.
2041
2030
  * `<object>[]`
2042
2031
  * `id: <number>` The unique id of the device.
2043
2032
  * `name: <string>` The name of the device.
2044
- * `type: <string>` Will be either `'accelerometer'`, `'gyroscope'`, or `'unknown'`.
2033
+ * `type: <string>|<null>` Either `'accelerometer'`, `'gyroscope'`. Will be `null` if it can't be determined.
2045
2034
  * `side: <string>|<null>` Some sensors (such as those on the Joy-Con controller) have a `'left'` or `'right'` side, otherwise this value will be `null`.
2046
2035
 
2047
2036
  A list of all the detected sensor devices.
@@ -2536,7 +2525,7 @@ Changes the text contents of the clipboard.
2536
2525
  ### sdl.power.info
2537
2526
 
2538
2527
  * `<object>`
2539
- * `state: <string>` One of `'unknown'`, `'noBattery'`, `'battery'`, `'charging'`, `'charged'`.
2528
+ * `state: <string>|null` One of `'noBattery'`, `'battery'`, `'charging'`, `'charged'`. Will be `null` if it can't be determinded.
2540
2529
  * `seconds: <number>|<null>` Seconds of battery life left. Will be `null` if not running on battery, or if it can't be determinded.
2541
2530
  * `percent: <number>|<null>` Percentage of battery life left. Will be `null` if not running on battery, or if it can't be determinded.
2542
2531
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.9.6-0",
2
+ "version": "0.10.0",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
@@ -64,8 +64,9 @@
64
64
  "version": "2.26.4"
65
65
  },
66
66
  "devDependencies": {
67
- "@kmamal/testing": "^0.0.27",
68
- "@types/node": "^20.11.5",
67
+ "@kmamal/evdev": "^0.0.1",
68
+ "@kmamal/testing": "^0.0.28",
69
+ "@types/node": "^20.11.6",
69
70
  "node-addon-api": "^7.1.0",
70
71
  "node-gyp": "^10.0.1"
71
72
  }
@@ -11,6 +11,7 @@ dir.publish = Path.join(dir.root, 'publish')
11
11
  const pkgPath = Path.join(dir.root, 'package.json')
12
12
  const pkg = JSON.parse(Fs.readFileSync(pkgPath).toString())
13
13
  const version = pkg.version
14
+ const isPrerelease = version.includes('-')
14
15
  const [ , owner, repo ] = pkg.repository.url.match(/([^/:]+)\/([^/]+).git$/u)
15
16
 
16
17
  const { platform, arch } = process
@@ -23,6 +24,7 @@ sdl.assetName = `SDL-v${sdl.version}-${platform}-${targetArch}.tar.gz`
23
24
  module.exports = {
24
25
  dir,
25
26
  version,
27
+ isPrerelease,
26
28
  owner,
27
29
  repo,
28
30
  platform,
@@ -1,6 +1,6 @@
1
+ const Globals = require('../globals')
1
2
  const Bindings = require('../bindings')
2
3
  const Enums = require('../enums')
3
- const Globals = require('../globals')
4
4
  const { EventsViaPoll } = require('../events/events-via-poll')
5
5
  const { AudioFormatHelpers } = require('./format-helpers')
6
6
 
@@ -22,6 +22,7 @@ const audio = new class extends EventsViaPoll {
22
22
  constructor () { super(validEvents) }
23
23
 
24
24
  get devices () {
25
+ Globals.events.poll()
25
26
  return [
26
27
  ...Globals.audioDevices.playback,
27
28
  ...Globals.audioDevices.recording,
@@ -1,3 +1,4 @@
1
+ const Globals = require('../globals')
1
2
  const Bindings = require('../bindings')
2
3
  const { EventsViaPoll } = require('../events/events-via-poll')
3
4
 
@@ -6,7 +7,11 @@ const validEvents = [ 'update' ]
6
7
  const clipboard = new class extends EventsViaPoll {
7
8
  constructor () { super(validEvents) }
8
9
 
9
- get text () { return Bindings.clipboard_getText() }
10
+ get text () {
11
+ Globals.events.poll() // TODO
12
+ return Bindings.clipboard_getText()
13
+ }
14
+
10
15
  setText (text) {
11
16
  if (typeof text !== 'string') { throw Object.assign(new Error("text must be a string"), { text }) }
12
17
 
@@ -1,6 +1,5 @@
1
- const Bindings = require('../bindings')
2
- const Enums = require('../enums')
3
1
  const Globals = require('../globals')
2
+ const Bindings = require('../bindings')
4
3
  const { EventsViaPoll } = require('../events/events-via-poll')
5
4
 
6
5
  const validEvents = [
@@ -44,14 +43,18 @@ class ControllerInstance extends EventsViaPoll {
44
43
  get firmwareVersion () { return this._firmwareVersion }
45
44
  get serialNumber () { return this._serialNumber }
46
45
 
47
- get axes () { return this._axes }
48
- get buttons () { return this._buttons }
46
+ get axes () {
47
+ Globals.events.poll() // TODO
48
+ return this._axes
49
+ }
49
50
 
50
- get power () {
51
- const power = Bindings.joystick_getPower(this._device.id)
52
- return Enums.powerLevelNames[power]
51
+ get buttons () {
52
+ Globals.events.poll() // TODO
53
+ return this._buttons
53
54
  }
54
55
 
56
+ get power () { return Bindings.joystick_getPower(this._device.id) }
57
+
55
58
  setPlayer (player) {
56
59
  if (this._closed) { throw Object.assign(new Error("instance is closed"), { id: this._device.id }) }
57
60
 
@@ -91,7 +94,7 @@ class ControllerInstance extends EventsViaPoll {
91
94
  if (highFreqRumble < 0 || highFreqRumble > 1) { throw Object.assign(new Error("highFreqRumble must be between 0 and 1"), { highFreqRumble }) }
92
95
  if (!Number.isFinite(duration)) { throw Object.assign(new Error("duration must be a number"), { duration }) }
93
96
 
94
- Globals.events.poll()
97
+ // Globals.events.poll() // Errors if it hasn't been called at least once
95
98
  Bindings.joystick_rumble(this._device.id, lowFreqRumble, highFreqRumble, duration)
96
99
  clearTimeout(this._rumbleTimeout)
97
100
  this._rumbleTimeout = setTimeout(() => { this.stopRumble() }, duration)
@@ -114,7 +117,7 @@ class ControllerInstance extends EventsViaPoll {
114
117
  if (rightRumble < 0 || rightRumble > 1) { throw Object.assign(new Error("rightRumble must be between 0 and 1"), { rightRumble }) }
115
118
  if (!Number.isFinite(duration)) { throw Object.assign(new Error("duration must be a number"), { duration }) }
116
119
 
117
- Globals.events.poll()
120
+ // Globals.events.poll() // Errors if it hasn't been called at least once
118
121
  Bindings.joystick_rumbleTriggers(this._device.id, leftRumble, rightRumble, duration)
119
122
  clearTimeout(this._rumbleTriggersTimeout)
120
123
  this._rumbleTriggersTimeout = setTimeout(() => { this.stopRumble() }, duration)
@@ -1,5 +1,5 @@
1
- const Bindings = require('../bindings')
2
1
  const Globals = require('../globals')
2
+ const Bindings = require('../bindings')
3
3
  const {
4
4
  make: makeControllerDevice,
5
5
  filter: filterControllerDevice,
@@ -19,7 +19,10 @@ const validEvents = [ 'deviceAdd', 'deviceRemove' ]
19
19
  const controller = new class extends EventsViaPoll {
20
20
  constructor () { super(validEvents) }
21
21
 
22
- get devices () { return Globals.controllerDevices }
22
+ get devices () {
23
+ Globals.events.poll()
24
+ return Globals.controllerDevices
25
+ }
23
26
 
24
27
  openDevice (device) { return new ControllerInstance(device) }
25
28
 
@@ -2,12 +2,4 @@ const Bindings = require('./bindings')
2
2
 
3
3
  const enums = Bindings.enums_get()
4
4
 
5
- for (const [ key, obj ] of Object.entries(enums)) {
6
- const names = {}
7
- for (const [ name, value ] of Object.entries(obj)) {
8
- names[value] = name
9
- }
10
- enums[`${key}Names`] = names
11
- }
12
-
13
5
  module.exports = enums
@@ -1,5 +1,5 @@
1
- const { EventEmitter } = require('events')
2
1
  const Globals = require('../globals')
2
+ const { EventEmitter } = require('events')
3
3
 
4
4
  let _ID = 0
5
5
  const activeEmitters = new Set()
@@ -27,7 +27,7 @@ class EventsViaPoll extends EventEmitter {
27
27
  activeEmitters.delete(id)
28
28
  if (activeEmitters.size !== 0) { return }
29
29
 
30
- Globals.events.stopPolling()
30
+ Globals.events.switchToPollingSlow()
31
31
  })
32
32
 
33
33
  this.on('newListener', (type) => {
@@ -41,7 +41,7 @@ class EventsViaPoll extends EventEmitter {
41
41
  activeEmitters.add(id)
42
42
  if (activeEmitters.size !== 1) { return }
43
43
 
44
- Globals.events.startPolling()
44
+ Globals.events.switchToPollingFast()
45
45
  })
46
46
  }
47
47