@kmamal/sdl 0.9.6-0 → 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.
- package/README.md +79 -90
- package/package.json +1 -1
- package/src/javascript/controller/controller-instance.js +1 -4
- package/src/javascript/enums.js +0 -8
- package/src/javascript/events/index.js +38 -47
- package/src/javascript/joystick/device.js +0 -3
- package/src/javascript/joystick/joystick-instance.js +2 -7
- package/src/javascript/keyboard/index.js +2 -2
- package/src/javascript/keyboard/key-mapping.js +2 -2
- package/src/javascript/mouse/index.js +2 -2
- package/src/javascript/power/index.js +1 -6
- package/src/javascript/video/index.js +0 -5
- package/src/native/controller.cpp +6 -0
- package/src/native/controller.h +5 -0
- package/src/native/enums.cpp +3 -141
- package/src/native/enums.h +0 -55
- package/src/native/events.cpp +113 -61
- package/src/native/events.h +55 -0
- package/src/native/global.cpp +175 -1
- package/src/native/joystick.cpp +13 -7
- package/src/native/joystick.h +7 -0
- package/src/native/keyboard.cpp +2 -6
- package/src/native/power.cpp +6 -1
- package/src/native/power.h +5 -0
- package/src/native/sensor.cpp +9 -2
- package/src/native/sensor.h +6 -0
- package/src/native/video.cpp +6 -1
- package/src/native/video.h +4 -0
- package/src/types/index.d.ts +84 -45
package/src/native/joystick.h
CHANGED
|
@@ -2,9 +2,16 @@
|
|
|
2
2
|
#define _JOYSTICK_H_
|
|
3
3
|
|
|
4
4
|
#include <napi.h>
|
|
5
|
+
#include <SDL.h>
|
|
6
|
+
#include <map>
|
|
7
|
+
#include <string>
|
|
5
8
|
|
|
6
9
|
namespace joystick {
|
|
7
10
|
|
|
11
|
+
extern std::map<SDL_JoystickType, std::string> joystick_types;
|
|
12
|
+
extern std::map<Uint8, std::string> hat_positions;
|
|
13
|
+
extern std::map<SDL_JoystickPowerLevel, std::string> power_levels;
|
|
14
|
+
|
|
8
15
|
double mapAxis (int value);
|
|
9
16
|
Napi::Array _getDevices (Napi::Env &env);
|
|
10
17
|
|
package/src/native/keyboard.cpp
CHANGED
|
@@ -28,14 +28,10 @@ keyboard::getScancode(const Napi::CallbackInfo &info)
|
|
|
28
28
|
std::string keyname = info[0].As<Napi::String>().Utf8Value();
|
|
29
29
|
|
|
30
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
|
-
}
|
|
31
|
+
if (keycode == SDLK_UNKNOWN) { return env.Null(); }
|
|
37
32
|
|
|
38
33
|
int scancode = SDL_GetScancodeFromKey(keycode);
|
|
34
|
+
if (scancode == 0) { return env.Null(); }
|
|
39
35
|
|
|
40
36
|
return Napi::Number::New(env, scancode);
|
|
41
37
|
}
|
package/src/native/power.cpp
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
#include "power.h"
|
|
2
2
|
#include <SDL.h>
|
|
3
|
+
#include <map>
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
std::map<SDL_PowerState, std::string> power::states;
|
|
7
|
+
|
|
3
8
|
|
|
4
9
|
Napi::Value
|
|
5
10
|
power::getInfo (const Napi::CallbackInfo &info)
|
|
@@ -10,7 +15,7 @@ power::getInfo (const Napi::CallbackInfo &info)
|
|
|
10
15
|
SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
|
|
11
16
|
|
|
12
17
|
Napi::Object result = Napi::Object::New(env);
|
|
13
|
-
result.Set("state", Napi::
|
|
18
|
+
result.Set("state", state == SDL_POWERSTATE_UNKNOWN ? env.Null() : Napi::String::New(env, power::states[state]));
|
|
14
19
|
result.Set("seconds", seconds == -1 ? env.Null() : Napi::Number::New(env, seconds));
|
|
15
20
|
result.Set("percent", percent == -1 ? env.Null() : Napi::Number::New(env, percent));
|
|
16
21
|
|
package/src/native/power.h
CHANGED
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
#define _POWER_H_
|
|
3
3
|
|
|
4
4
|
#include <napi.h>
|
|
5
|
+
#include <SDL.h>
|
|
6
|
+
#include <map>
|
|
7
|
+
#include <string>
|
|
5
8
|
|
|
6
9
|
namespace power {
|
|
7
10
|
|
|
11
|
+
extern std::map<SDL_PowerState, std::string> states;
|
|
12
|
+
|
|
8
13
|
Napi::Value getInfo(const Napi::CallbackInfo &info);
|
|
9
14
|
|
|
10
15
|
}; // namespace power
|
package/src/native/sensor.cpp
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
#include "sensor.h"
|
|
2
2
|
#include <SDL.h>
|
|
3
|
+
#include <map>
|
|
3
4
|
#include <string>
|
|
4
5
|
#include <sstream>
|
|
5
6
|
|
|
7
|
+
|
|
8
|
+
std::map<SDL_SensorType, std::string> sensor::types;
|
|
9
|
+
std::map<SDL_SensorType, std::string> sensor::sides;
|
|
10
|
+
|
|
11
|
+
|
|
6
12
|
Napi::Value
|
|
7
13
|
sensor::getDevices (const Napi::CallbackInfo &info)
|
|
8
14
|
{
|
|
@@ -27,7 +33,7 @@ sensor::getDevices (const Napi::CallbackInfo &info)
|
|
|
27
33
|
throw Napi::Error::New(env, message.str());
|
|
28
34
|
}
|
|
29
35
|
|
|
30
|
-
|
|
36
|
+
SDL_SensorType type = SDL_SensorGetDeviceType(i);
|
|
31
37
|
// This function can only error if the index is invalid.
|
|
32
38
|
|
|
33
39
|
const char *name = SDL_SensorGetDeviceName(i);
|
|
@@ -36,8 +42,9 @@ sensor::getDevices (const Napi::CallbackInfo &info)
|
|
|
36
42
|
Napi::Object device = Napi::Object::New(env);
|
|
37
43
|
device.Set("_index", Napi::Number::New(env, i));
|
|
38
44
|
device.Set("id", Napi::Number::New(env, id));
|
|
39
|
-
device.Set("type", Napi::Number::New(env, type));
|
|
40
45
|
device.Set("name", Napi::String::New(env, name));
|
|
46
|
+
device.Set("type", type == SDL_SENSOR_UNKNOWN ? env.Null() : Napi::String::New(env, sensor::types[type]));
|
|
47
|
+
device.Set("side", type == SDL_SENSOR_UNKNOWN || type == SDL_SENSOR_ACCEL || type == SDL_SENSOR_GYRO ? env.Null() : Napi::String::New(env, sensor::sides[type]));
|
|
41
48
|
|
|
42
49
|
devices.Set(i, device);
|
|
43
50
|
}
|
package/src/native/sensor.h
CHANGED
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
#define _SENSOR_H_
|
|
3
3
|
|
|
4
4
|
#include <napi.h>
|
|
5
|
+
#include <SDL.h>
|
|
6
|
+
#include <map>
|
|
7
|
+
#include <string>
|
|
5
8
|
|
|
6
9
|
namespace sensor {
|
|
7
10
|
|
|
11
|
+
extern std::map<SDL_SensorType, std::string> types;
|
|
12
|
+
extern std::map<SDL_SensorType, std::string> sides;
|
|
13
|
+
|
|
8
14
|
Napi::Value getDevices(const Napi::CallbackInfo &info);
|
|
9
15
|
Napi::Value open(const Napi::CallbackInfo &info);
|
|
10
16
|
Napi::Value getData(const Napi::CallbackInfo &info);
|
package/src/native/video.cpp
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
#include <SDL.h>
|
|
3
3
|
#include <string>
|
|
4
4
|
#include <sstream>
|
|
5
|
+
#include <map>
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
std::map<SDL_PixelFormatEnum, std::string> video::formats;
|
|
9
|
+
|
|
5
10
|
|
|
6
11
|
Napi::Value
|
|
7
12
|
video::getDisplays(const Napi::CallbackInfo &info)
|
|
@@ -77,7 +82,7 @@ video::getDisplays(const Napi::CallbackInfo &info)
|
|
|
77
82
|
|
|
78
83
|
Napi::Object display = Napi::Object::New(env);
|
|
79
84
|
display.Set("name", Napi::String::New(env, name));
|
|
80
|
-
display.Set("format",
|
|
85
|
+
display.Set("format", video::formats[(SDL_PixelFormatEnum) mode.format]);
|
|
81
86
|
display.Set("frequency", Napi::Number::New(env, mode.refresh_rate));
|
|
82
87
|
display.Set("geometry", geometry);
|
|
83
88
|
display.Set("usable", usable);
|
package/src/native/video.h
CHANGED
package/src/types/index.d.ts
CHANGED
|
@@ -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:
|
|
200
|
+
readonly axis: Sdl.Controller.Axis
|
|
201
201
|
readonly value: number
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
interface ButtonEvent extends ControllerEvent {
|
|
205
|
-
readonly button:
|
|
205
|
+
readonly button: Sdl.Controller.Button
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
export interface ButtonDown extends ButtonEvent { readonly type: 'buttonDown' }
|
|
@@ -824,6 +824,17 @@ export namespace Sdl {
|
|
|
824
824
|
y: number
|
|
825
825
|
}
|
|
826
826
|
|
|
827
|
+
export type JoystickType
|
|
828
|
+
= 'gamecontroller'
|
|
829
|
+
| 'wheel'
|
|
830
|
+
| 'arcadestick'
|
|
831
|
+
| 'flightstick'
|
|
832
|
+
| 'dancepad'
|
|
833
|
+
| 'guitar'
|
|
834
|
+
| 'drumkit'
|
|
835
|
+
| 'arcadepad'
|
|
836
|
+
| 'throttle'
|
|
837
|
+
|
|
827
838
|
export type HatPosition
|
|
828
839
|
= 'centered'
|
|
829
840
|
| 'up'
|
|
@@ -845,14 +856,14 @@ export namespace Sdl {
|
|
|
845
856
|
|
|
846
857
|
export interface Device {
|
|
847
858
|
readonly id: number
|
|
848
|
-
readonly type:
|
|
859
|
+
readonly type: JoystickType
|
|
849
860
|
readonly name: string
|
|
850
861
|
readonly path: string
|
|
851
862
|
readonly guid: string
|
|
852
|
-
readonly vendor: number
|
|
853
|
-
readonly product: number
|
|
854
|
-
readonly version: number
|
|
855
|
-
readonly player: number
|
|
863
|
+
readonly vendor: number | null
|
|
864
|
+
readonly product: number | null
|
|
865
|
+
readonly version: number | null
|
|
866
|
+
readonly player: number | null
|
|
856
867
|
}
|
|
857
868
|
|
|
858
869
|
export class JoystickInstance {
|
|
@@ -873,7 +884,7 @@ export namespace Sdl {
|
|
|
873
884
|
readonly hats: HatPosition[]
|
|
874
885
|
readonly buttons: boolean[]
|
|
875
886
|
|
|
876
|
-
readonly power: PowerLevel
|
|
887
|
+
readonly power: PowerLevel | null
|
|
877
888
|
|
|
878
889
|
setPlayer (index: number): void
|
|
879
890
|
resetPlayer (): void
|
|
@@ -919,6 +930,35 @@ export namespace Sdl {
|
|
|
919
930
|
readonly mapping: string
|
|
920
931
|
}
|
|
921
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
|
+
|
|
922
962
|
export class ControllerInstance {
|
|
923
963
|
on (event: 'axisMotion', listener: (event: Events.Controller.AxisMotion) => void): this
|
|
924
964
|
on (event: 'buttonDown', listener: (event: Events.Controller.ButtonDown) => void): this
|
|
@@ -932,34 +972,34 @@ export namespace Sdl {
|
|
|
932
972
|
readonly serialNumber: string
|
|
933
973
|
|
|
934
974
|
readonly axes: {
|
|
935
|
-
readonly leftStickX: number
|
|
936
|
-
readonly leftStickY: number
|
|
937
|
-
readonly rightStickX: number
|
|
938
|
-
readonly rightStickY: number
|
|
939
|
-
readonly leftTrigger: number
|
|
940
|
-
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
|
|
941
981
|
}
|
|
942
982
|
|
|
943
983
|
readonly buttons: {
|
|
944
|
-
readonly dpadLeft: boolean
|
|
945
|
-
readonly dpadRight: boolean
|
|
946
|
-
readonly dpadUp: boolean
|
|
947
|
-
readonly dpadDown: boolean
|
|
948
|
-
readonly a: boolean
|
|
949
|
-
readonly b: boolean
|
|
950
|
-
readonly x: boolean
|
|
951
|
-
readonly y: boolean
|
|
952
|
-
readonly guide: boolean
|
|
953
|
-
readonly back: boolean
|
|
954
|
-
readonly start: boolean
|
|
955
|
-
readonly leftStick: boolean
|
|
956
|
-
readonly rightStick: boolean
|
|
957
|
-
readonly leftShoulder: boolean
|
|
958
|
-
readonly rightShoulder: boolean
|
|
959
|
-
readonly paddle1: boolean
|
|
960
|
-
readonly paddle2: boolean
|
|
961
|
-
readonly paddle3: boolean
|
|
962
|
-
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
|
|
963
1003
|
}
|
|
964
1004
|
|
|
965
1005
|
readonly power: Joystick.PowerLevel
|
|
@@ -1010,15 +1050,15 @@ export namespace Sdl {
|
|
|
1010
1050
|
export interface Device {
|
|
1011
1051
|
readonly id: number
|
|
1012
1052
|
readonly name: string
|
|
1013
|
-
readonly type: Type
|
|
1053
|
+
readonly type: Type | null
|
|
1014
1054
|
readonly side: Side | null
|
|
1015
1055
|
}
|
|
1016
1056
|
|
|
1017
1057
|
export interface Data {
|
|
1018
|
-
timestamp: number | null
|
|
1019
|
-
x: number
|
|
1020
|
-
y: number
|
|
1021
|
-
z: number
|
|
1058
|
+
readonly timestamp: number | null
|
|
1059
|
+
readonly x: number
|
|
1060
|
+
readonly y: number
|
|
1061
|
+
readonly z: number
|
|
1022
1062
|
}
|
|
1023
1063
|
|
|
1024
1064
|
export class SensorInstance {
|
|
@@ -1035,7 +1075,7 @@ export namespace Sdl {
|
|
|
1035
1075
|
}
|
|
1036
1076
|
|
|
1037
1077
|
interface Module {
|
|
1038
|
-
STANDARD_GRAVITY: 9.80665
|
|
1078
|
+
readonly STANDARD_GRAVITY: 9.80665
|
|
1039
1079
|
|
|
1040
1080
|
readonly devices: Device[]
|
|
1041
1081
|
|
|
@@ -1158,14 +1198,13 @@ export namespace Sdl {
|
|
|
1158
1198
|
export namespace Power {
|
|
1159
1199
|
|
|
1160
1200
|
export type PowerState
|
|
1161
|
-
= '
|
|
1162
|
-
| 'noBattery'
|
|
1201
|
+
= 'noBattery'
|
|
1163
1202
|
| 'battery'
|
|
1164
1203
|
| 'charging'
|
|
1165
1204
|
| 'charged'
|
|
1166
1205
|
|
|
1167
1206
|
export interface PowerInfo {
|
|
1168
|
-
state: PowerState
|
|
1207
|
+
state: PowerState | null
|
|
1169
1208
|
seconds: number | null
|
|
1170
1209
|
percent: number | null
|
|
1171
1210
|
}
|