@kmamal/sdl 0.9.5 → 0.9.6-1

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 (57) hide show
  1. package/README.md +111 -103
  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 +7 -4
  8. package/src/javascript/enums.js +1 -9
  9. package/src/javascript/events/index.js +293 -305
  10. package/src/javascript/index.js +1 -1
  11. package/src/javascript/joystick/device.js +0 -3
  12. package/src/javascript/joystick/joystick-instance.js +8 -6
  13. package/src/javascript/keyboard/index.js +3 -3
  14. package/src/javascript/keyboard/key-mapping.js +14 -6
  15. package/src/javascript/mouse/index.js +14 -13
  16. package/src/javascript/power/index.js +1 -8
  17. package/src/javascript/sensor/sensor-instance.js +1 -5
  18. package/src/javascript/video/index.js +0 -5
  19. package/src/javascript/video/window.js +17 -16
  20. package/src/native/audio.cpp +178 -0
  21. package/src/native/audio.h +21 -0
  22. package/src/native/clipboard.cpp +45 -0
  23. package/src/native/clipboard.h +13 -0
  24. package/src/native/cocoa-global.h +8 -0
  25. package/src/native/cocoa-global.mm +8 -0
  26. package/src/native/cocoa-window.h +9 -4
  27. package/src/native/cocoa-window.mm +6 -9
  28. package/src/native/controller.cpp +160 -0
  29. package/src/native/controller.h +22 -0
  30. package/src/native/enums.cpp +339 -0
  31. package/src/native/enums.h +12 -0
  32. package/src/native/events.cpp +391 -0
  33. package/src/native/events.h +70 -0
  34. package/src/native/global.cpp +361 -0
  35. package/src/native/global.h +15 -0
  36. package/src/native/joystick.cpp +394 -0
  37. package/src/native/joystick.h +29 -0
  38. package/src/native/keyboard.cpp +51 -0
  39. package/src/native/keyboard.h +18 -0
  40. package/src/native/module.cpp +98 -0
  41. package/src/native/mouse.cpp +186 -0
  42. package/src/native/mouse.h +21 -0
  43. package/src/native/power.cpp +23 -0
  44. package/src/native/power.h +17 -0
  45. package/src/native/sensor.cpp +124 -0
  46. package/src/native/sensor.h +21 -0
  47. package/src/native/video.cpp +95 -0
  48. package/src/native/video.h +16 -0
  49. package/src/native/window.cpp +755 -0
  50. package/src/native/window.h +29 -0
  51. package/src/types/index.d.ts +91 -49
  52. package/scripts/test.mjs +0 -12
  53. package/src/native/asprintf.c +0 -47
  54. package/src/native/asprintf.h +0 -37
  55. package/src/native/binding.cpp +0 -1680
  56. package/src/native/sdl-helpers.cpp +0 -2617
  57. package/src/native/sdl-helpers.h +0 -182
@@ -0,0 +1,29 @@
1
+ #ifndef _WINDOW_H_
2
+ #define _WINDOW_H_
3
+
4
+ #include <napi.h>
5
+
6
+ namespace window {
7
+
8
+ Napi::Value create(const Napi::CallbackInfo &info);
9
+ Napi::Value setTitle(const Napi::CallbackInfo &info);
10
+ Napi::Value setPosition(const Napi::CallbackInfo &info);
11
+ Napi::Value setSize(const Napi::CallbackInfo &info);
12
+ Napi::Value setFullscreen(const Napi::CallbackInfo &info);
13
+ Napi::Value setResizable(const Napi::CallbackInfo &info);
14
+ Napi::Value setBorderless(const Napi::CallbackInfo &info);
15
+ Napi::Value setAcceleratedAndVsync(const Napi::CallbackInfo &info);
16
+ Napi::Value focus(const Napi::CallbackInfo &info);
17
+ Napi::Value show(const Napi::CallbackInfo &info);
18
+ Napi::Value hide(const Napi::CallbackInfo &info);
19
+ Napi::Value maximize(const Napi::CallbackInfo &info);
20
+ Napi::Value minimize(const Napi::CallbackInfo &info);
21
+ Napi::Value restore(const Napi::CallbackInfo &info);
22
+ Napi::Value render(const Napi::CallbackInfo &info);
23
+ Napi::Value setIcon(const Napi::CallbackInfo &info);
24
+ Napi::Value flash(const Napi::CallbackInfo &info);
25
+ Napi::Value destroy(const Napi::CallbackInfo &info);
26
+
27
+ }; // namespace window
28
+
29
+ #endif // _WINDOW_H_
@@ -142,13 +142,13 @@ export namespace Events {
142
142
 
143
143
  export interface AxisMotion extends JoystickEvent {
144
144
  readonly type: 'axisMotion'
145
- readonly axis: number,
145
+ readonly axis: number
146
146
  readonly value: number
147
147
  }
148
148
 
149
149
  export interface BallMotion extends JoystickEvent {
150
150
  readonly type: 'ballMotion'
151
- readonly ball: number,
151
+ readonly ball: number
152
152
  readonly x: number
153
153
  readonly y: number
154
154
  }
@@ -162,7 +162,7 @@ export namespace Events {
162
162
 
163
163
  export interface HatMotion extends JoystickEvent {
164
164
  readonly type: 'hatMotion'
165
- readonly hat: number,
165
+ readonly hat: number
166
166
  readonly value: Sdl.Joystick.HatPosition
167
167
  }
168
168
 
@@ -197,12 +197,12 @@ export namespace Events {
197
197
 
198
198
  export interface AxisMotion extends ControllerEvent {
199
199
  readonly type: 'axisMotion'
200
- readonly axis: number,
200
+ readonly axis: Sdl.Controller.Axis
201
201
  readonly value: number
202
202
  }
203
203
 
204
204
  interface ButtonEvent extends ControllerEvent {
205
- readonly button: number
205
+ readonly button: Sdl.Controller.Button
206
206
  }
207
207
 
208
208
  export interface ButtonDown extends ButtonEvent { readonly type: 'buttonDown' }
@@ -761,8 +761,8 @@ export namespace Sdl {
761
761
  interface Module {
762
762
  readonly SCANCODE: { [name in ScancodeNames]: Scancode }
763
763
 
764
- getKey (scancode: Scancode): Key
765
- getScancode (key: Key): Scancode
764
+ getKey (scancode: Scancode): Key | null
765
+ getScancode (key: Key): Scancode | null
766
766
 
767
767
  getState (): boolean[]
768
768
  }
@@ -804,10 +804,12 @@ export namespace Sdl {
804
804
  setPosition (x: number, y: number): void
805
805
 
806
806
  setCursor (cursor: Cursor): void
807
+ resetCursor (): void
807
808
  setCursorImage (width: number, height: number, stride: number, format: Video.Format, buffer: Buffer): void
808
809
 
809
810
  showCursor (show?: boolean): void
810
811
  hideCursor (): void
812
+ redrawCursor (): void
811
813
 
812
814
  capture (): void
813
815
  uncapture (): void
@@ -822,6 +824,17 @@ export namespace Sdl {
822
824
  y: number
823
825
  }
824
826
 
827
+ export type JoystickType
828
+ = 'gamecontroller'
829
+ | 'wheel'
830
+ | 'arcadestick'
831
+ | 'flightstick'
832
+ | 'dancepad'
833
+ | 'guitar'
834
+ | 'drumkit'
835
+ | 'arcadepad'
836
+ | 'throttle'
837
+
825
838
  export type HatPosition
826
839
  = 'centered'
827
840
  | 'up'
@@ -834,8 +847,7 @@ export namespace Sdl {
834
847
  | 'leftdown'
835
848
 
836
849
  export type PowerLevel
837
- = 'unknown'
838
- | 'empty'
850
+ = 'empty'
839
851
  | 'low'
840
852
  | 'medium'
841
853
  | 'full'
@@ -844,14 +856,14 @@ export namespace Sdl {
844
856
 
845
857
  export interface Device {
846
858
  readonly id: number
847
- readonly type: string
859
+ readonly type: JoystickType
848
860
  readonly name: string
849
861
  readonly path: string
850
862
  readonly guid: string
851
- readonly vendor: number
852
- readonly product: number
853
- readonly version: number
854
- readonly player: number
863
+ readonly vendor: number | null
864
+ readonly product: number | null
865
+ readonly version: number | null
866
+ readonly player: number | null
855
867
  }
856
868
 
857
869
  export class JoystickInstance {
@@ -872,9 +884,10 @@ export namespace Sdl {
872
884
  readonly hats: HatPosition[]
873
885
  readonly buttons: boolean[]
874
886
 
875
- readonly power: PowerLevel
887
+ readonly power: PowerLevel | null
876
888
 
877
889
  setPlayer (index: number): void
890
+ resetPlayer (): void
878
891
 
879
892
  readonly hasLed: boolean
880
893
  setLed (red: number, green: number, blue: number): void
@@ -917,6 +930,35 @@ export namespace Sdl {
917
930
  readonly mapping: string
918
931
  }
919
932
 
933
+ export type Axis
934
+ = 'leftStickX'
935
+ | 'leftStickY'
936
+ | 'rightStickX'
937
+ | 'rightStickY'
938
+ | 'leftTrigger'
939
+ | 'rightTrigger'
940
+
941
+ export type Button
942
+ = 'dpadLeft'
943
+ | 'dpadRight'
944
+ | 'dpadUp'
945
+ | 'dpadDown'
946
+ | 'a'
947
+ | 'b'
948
+ | 'x'
949
+ | 'y'
950
+ | 'guide'
951
+ | 'back'
952
+ | 'start'
953
+ | 'leftStick'
954
+ | 'rightStick'
955
+ | 'leftShoulder'
956
+ | 'rightShoulder'
957
+ | 'paddle1'
958
+ | 'paddle2'
959
+ | 'paddle3'
960
+ | 'paddle4'
961
+
920
962
  export class ControllerInstance {
921
963
  on (event: 'axisMotion', listener: (event: Events.Controller.AxisMotion) => void): this
922
964
  on (event: 'buttonDown', listener: (event: Events.Controller.ButtonDown) => void): this
@@ -930,39 +972,40 @@ export namespace Sdl {
930
972
  readonly serialNumber: string
931
973
 
932
974
  readonly axes: {
933
- readonly leftStickX: number,
934
- readonly leftStickY: number,
935
- readonly rightStickX: number,
936
- readonly rightStickY: number,
937
- readonly leftTrigger: number,
938
- readonly rightTrigger: number,
975
+ readonly leftStickX: number
976
+ readonly leftStickY: number
977
+ readonly rightStickX: number
978
+ readonly rightStickY: number
979
+ readonly leftTrigger: number
980
+ readonly rightTrigger: number
939
981
  }
940
982
 
941
983
  readonly buttons: {
942
- readonly dpadLeft: boolean,
943
- readonly dpadRight: boolean,
944
- readonly dpadUp: boolean,
945
- readonly dpadDown: boolean,
946
- readonly a: boolean,
947
- readonly b: boolean,
948
- readonly x: boolean,
949
- readonly y: boolean,
950
- readonly guide: boolean,
951
- readonly back: boolean,
952
- readonly start: boolean,
953
- readonly leftStick: boolean,
954
- readonly rightStick: boolean,
955
- readonly leftShoulder: boolean,
956
- readonly rightShoulder: boolean,
957
- readonly paddle1: boolean,
958
- readonly paddle2: boolean,
959
- readonly paddle3: boolean,
960
- readonly paddle4: boolean,
984
+ readonly dpadLeft: boolean
985
+ readonly dpadRight: boolean
986
+ readonly dpadUp: boolean
987
+ readonly dpadDown: boolean
988
+ readonly a: boolean
989
+ readonly b: boolean
990
+ readonly x: boolean
991
+ readonly y: boolean
992
+ readonly guide: boolean
993
+ readonly back: boolean
994
+ readonly start: boolean
995
+ readonly leftStick: boolean
996
+ readonly rightStick: boolean
997
+ readonly leftShoulder: boolean
998
+ readonly rightShoulder: boolean
999
+ readonly paddle1: boolean
1000
+ readonly paddle2: boolean
1001
+ readonly paddle3: boolean
1002
+ readonly paddle4: boolean
961
1003
  }
962
1004
 
963
1005
  readonly power: Joystick.PowerLevel
964
1006
 
965
1007
  setPlayer (index: number): void
1008
+ resetPlayer (): void
966
1009
 
967
1010
  readonly hasLed: boolean
968
1011
  setLed (red: number, green: number, blue: number): void
@@ -1007,15 +1050,15 @@ export namespace Sdl {
1007
1050
  export interface Device {
1008
1051
  readonly id: number
1009
1052
  readonly name: string
1010
- readonly type: Type
1053
+ readonly type: Type | null
1011
1054
  readonly side: Side | null
1012
1055
  }
1013
1056
 
1014
1057
  export interface Data {
1015
- timestamp: number | null,
1016
- x: number,
1017
- y: number,
1018
- z: number,
1058
+ readonly timestamp: number | null
1059
+ readonly x: number
1060
+ readonly y: number
1061
+ readonly z: number
1019
1062
  }
1020
1063
 
1021
1064
  export class SensorInstance {
@@ -1032,7 +1075,7 @@ export namespace Sdl {
1032
1075
  }
1033
1076
 
1034
1077
  interface Module {
1035
- STANDARD_GRAVITY: 9.80665,
1078
+ readonly STANDARD_GRAVITY: 9.80665
1036
1079
 
1037
1080
  readonly devices: Device[]
1038
1081
 
@@ -1155,14 +1198,13 @@ export namespace Sdl {
1155
1198
  export namespace Power {
1156
1199
 
1157
1200
  export type PowerState
1158
- = 'unknown'
1159
- | 'noBattery'
1201
+ = 'noBattery'
1160
1202
  | 'battery'
1161
1203
  | 'charging'
1162
1204
  | 'charged'
1163
1205
 
1164
1206
  export interface PowerInfo {
1165
- state: PowerState
1207
+ state: PowerState | null
1166
1208
  seconds: number | null
1167
1209
  percent: number | null
1168
1210
  }
package/scripts/test.mjs DELETED
@@ -1,12 +0,0 @@
1
- import Path from 'node:path'
2
- import { execSync } from 'node:child_process'
3
- import Fs from 'node:fs'
4
- import { fileURLToPath } from 'url'
5
- const __dirname = Path.dirname(fileURLToPath(import.meta.url))
6
-
7
- process.chdir(Path.join(__dirname, '../tests'))
8
- const files = await Fs.promises.readdir('.')
9
- for (const name of files) {
10
- if (!name.endsWith('.test.js')) { continue }
11
- execSync(`node ${name}`, { stdio: 'inherit' })
12
- }
@@ -1,47 +0,0 @@
1
- /*
2
- Copyright (C) 2014 insane coder (http://insanecoding.blogspot.com/, http://asprintf.insanecoding.org/)
3
-
4
- Permission to use, copy, modify, and distribute this software for any
5
- purpose with or without fee is hereby granted, provided that the above
6
- copyright notice and this permission notice appear in all copies.
7
-
8
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
- #include "asprintf.h"
18
-
19
- #include <stdio.h>
20
- #include <stdlib.h>
21
- #include <limits.h>
22
-
23
- int asprintf(char **strp, const char *fmt, ...)
24
- {
25
- int r;
26
- va_list ap;
27
- va_start(ap, fmt);
28
- r = vasprintf(strp, fmt, ap);
29
- va_end(ap);
30
- return(r);
31
- }
32
-
33
- int vasprintf(char **strp, const char *fmt, va_list ap)
34
- {
35
- int r = -1, size = _vscprintf(fmt, ap);
36
- if ((size >= 0) && (size < INT_MAX))
37
- {
38
- *strp = (char *)malloc(size+1); //+1 for null
39
- if (*strp)
40
- {
41
- r = vsnprintf(*strp, size+1, fmt, ap); //+1 for null
42
- if (r == -1) { insane_free(*strp); }
43
- }
44
- }
45
- else { *strp = 0; }
46
- return(r);
47
- }
@@ -1,37 +0,0 @@
1
- /*
2
- Copyright (C) 2014 insane coder (http://insanecoding.blogspot.com/, http://asprintf.insanecoding.org/)
3
-
4
- Permission to use, copy, modify, and distribute this software for any
5
- purpose with or without fee is hereby granted, provided that the above
6
- copyright notice and this permission notice appear in all copies.
7
-
8
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
- #ifndef INSANE_ASPRINTF_H
18
- #define INSANE_ASPRINTF_H
19
-
20
- #ifndef __cplusplus
21
- #include <stdarg.h>
22
- #else
23
- #include <cstdarg>
24
- extern "C"
25
- {
26
- #endif
27
-
28
- #define insane_free(ptr) { free(ptr); ptr = 0; }
29
-
30
- int vasprintf(char **strp, const char *fmt, va_list ap);
31
- int asprintf(char **strp, const char *fmt, ...);
32
-
33
- #ifdef __cplusplus
34
- }
35
- #endif
36
-
37
- #endif