@kmamal/sdl 0.11.3 → 0.11.4
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 +8 -0
- package/package.json +1 -1
- package/src/javascript/controller/controller-instance.js +2 -0
- package/src/native/controller.cpp +8 -4
- package/src/native/joystick.cpp +12 -12
- package/src/native/power.cpp +9 -5
- package/src/native/sensor.cpp +5 -3
- package/src/native/window.cpp +17 -26
- package/src/types/index.d.ts +1 -0
package/README.md
CHANGED
|
@@ -281,6 +281,7 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
|
|
|
281
281
|
* [controllerInstance.device](#controllerinstancedevice)
|
|
282
282
|
* [controllerInstance.firmwareVersion](#controllerinstancefirmwareversion)
|
|
283
283
|
* [controllerInstance.serialNumber](#controllerinstanceserialnumber)
|
|
284
|
+
* [controllerInstance.steamHandle](#controllerinstancesteamhandle)
|
|
284
285
|
* [controllerInstance.axes](#controllerinstanceaxes)
|
|
285
286
|
* [controllerInstance.buttons](#controllerinstancebuttons)
|
|
286
287
|
* [controllerInstance.power](#controllerinstancepower)
|
|
@@ -1947,6 +1948,13 @@ The controller's firmware version.
|
|
|
1947
1948
|
|
|
1948
1949
|
The controller's serial number, or `null` if it's not available.
|
|
1949
1950
|
|
|
1951
|
+
### controllerInstance.steamHandle
|
|
1952
|
+
|
|
1953
|
+
* `<Buffer>|<null>`
|
|
1954
|
+
|
|
1955
|
+
The controller's steam handle, or `null` if it's not available.
|
|
1956
|
+
The `Buffer` will contain an `InputHandle_t` for the controller that can be used with the [Steam Input API](https://partner.steamgames.com/doc/api/ISteamInput)
|
|
1957
|
+
|
|
1950
1958
|
### controllerInstance.axes
|
|
1951
1959
|
|
|
1952
1960
|
* `<object>`
|
package/package.json
CHANGED
|
@@ -21,6 +21,7 @@ class ControllerInstance extends EventsViaPoll {
|
|
|
21
21
|
this._hasLed = result.hasLed
|
|
22
22
|
this._hasRumble = result.hasRumble
|
|
23
23
|
this._hasRumbleTriggers = result.hasRumbleTriggers
|
|
24
|
+
this._steamHandle = result.steamHandle
|
|
24
25
|
this._axes = result.axes
|
|
25
26
|
this._buttons = result.buttons
|
|
26
27
|
|
|
@@ -42,6 +43,7 @@ class ControllerInstance extends EventsViaPoll {
|
|
|
42
43
|
get device () { return this._device }
|
|
43
44
|
get firmwareVersion () { return this._firmwareVersion }
|
|
44
45
|
get serialNumber () { return this._serialNumber }
|
|
46
|
+
get steamHandle () { return this._steamHandle }
|
|
45
47
|
|
|
46
48
|
get axes () {
|
|
47
49
|
Globals.events.poll()
|
|
@@ -118,16 +118,19 @@ controller::open (const Napi::CallbackInfo &info)
|
|
|
118
118
|
throw Napi::Error::New(env, message.str());
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
int
|
|
122
|
-
Napi::Value firmware_version =
|
|
121
|
+
int _firmware_version = SDL_JoystickGetFirmwareVersion(joystick);
|
|
122
|
+
Napi::Value firmware_version = _firmware_version == 0 ? env.Null() : Napi::Number::New(env, _firmware_version);
|
|
123
123
|
|
|
124
|
-
const char *
|
|
125
|
-
Napi::Value serial_number =
|
|
124
|
+
const char *_serial_number = SDL_JoystickGetSerial(joystick);
|
|
125
|
+
Napi::Value serial_number = _serial_number == 0 ? env.Null() : Napi::String::New(env, _serial_number);
|
|
126
126
|
|
|
127
127
|
bool has_led = SDL_JoystickHasLED(joystick);
|
|
128
128
|
bool has_rumble = SDL_JoystickHasRumble(joystick);
|
|
129
129
|
bool has_rumble_triggers = SDL_JoystickHasRumbleTriggers(joystick);
|
|
130
130
|
|
|
131
|
+
Uint64 _steam_handle = SDL_GameControllerGetSteamHandle(controller);
|
|
132
|
+
Napi::Value steam_handle = _steam_handle == 0 ? env.Null() : Napi::Buffer<Uint64>::Copy(env, &_steam_handle, 1);
|
|
133
|
+
|
|
131
134
|
Napi::Object result = Napi::Object::New(env);
|
|
132
135
|
// result.Set("id", Napi::Number::New(env, joystick_id)); // NOTE: Unused. Same as the device id
|
|
133
136
|
result.Set("firmwareVersion", firmware_version);
|
|
@@ -135,6 +138,7 @@ controller::open (const Napi::CallbackInfo &info)
|
|
|
135
138
|
result.Set("hasLed", Napi::Boolean::New(env, has_led));
|
|
136
139
|
result.Set("hasRumble", Napi::Boolean::New(env, has_rumble));
|
|
137
140
|
result.Set("hasRumbleTriggers", Napi::Boolean::New(env, has_rumble_triggers));
|
|
141
|
+
result.Set("steamHandle", steam_handle);
|
|
138
142
|
|
|
139
143
|
controller::getState(env, controller, result);
|
|
140
144
|
|
package/src/native/joystick.cpp
CHANGED
|
@@ -64,17 +64,17 @@ joystick::_getDevices (Napi::Env &env)
|
|
|
64
64
|
char guid_string[33];
|
|
65
65
|
SDL_JoystickGetGUIDString(guid, guid_string, 33);
|
|
66
66
|
|
|
67
|
-
int
|
|
68
|
-
Napi::Value vendor =
|
|
67
|
+
int _vendor = SDL_JoystickGetDeviceVendor(i);
|
|
68
|
+
Napi::Value vendor = _vendor == 0 ? env.Null() : Napi::Number::New(env, _vendor);
|
|
69
69
|
|
|
70
|
-
int
|
|
71
|
-
Napi::Value product =
|
|
70
|
+
int _product = SDL_JoystickGetDeviceProduct(i);
|
|
71
|
+
Napi::Value product = _product == 0 ? env.Null() : Napi::Number::New(env, _product);
|
|
72
72
|
|
|
73
|
-
int
|
|
74
|
-
Napi::Value version =
|
|
73
|
+
int _Version = SDL_JoystickGetDeviceProductVersion(i);
|
|
74
|
+
Napi::Value version = _Version == 0 ? env.Null() : Napi::Number::New(env, _Version);
|
|
75
75
|
|
|
76
|
-
int
|
|
77
|
-
Napi::Value player =
|
|
76
|
+
int _player = SDL_JoystickGetDevicePlayerIndex(i);
|
|
77
|
+
Napi::Value player = _player == -1 ? env.Null() : Napi::Number::New(env, _player);
|
|
78
78
|
|
|
79
79
|
bool is_controller = SDL_IsGameController(i);
|
|
80
80
|
|
|
@@ -144,11 +144,11 @@ joystick::open (const Napi::CallbackInfo &info)
|
|
|
144
144
|
throw Napi::Error::New(env, message.str());
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
int
|
|
148
|
-
Napi::Value firmware_version =
|
|
147
|
+
int _firmware_version = SDL_JoystickGetFirmwareVersion(joystick);
|
|
148
|
+
Napi::Value firmware_version = _firmware_version == 0 ? env.Null() : Napi::Number::New(env, _firmware_version);
|
|
149
149
|
|
|
150
|
-
const char *
|
|
151
|
-
Napi::Value serial_number =
|
|
150
|
+
const char *_serial_number = SDL_JoystickGetSerial(joystick);
|
|
151
|
+
Napi::Value serial_number = _serial_number == nullptr ? env.Null() : Napi::String::New(env, _serial_number);
|
|
152
152
|
|
|
153
153
|
SDL_bool has_led = SDL_JoystickHasLED(joystick);
|
|
154
154
|
SDL_bool has_rumble = SDL_JoystickHasRumble(joystick);
|
package/src/native/power.cpp
CHANGED
|
@@ -11,13 +11,17 @@ power::getInfo (const Napi::CallbackInfo &info)
|
|
|
11
11
|
{
|
|
12
12
|
Napi::Env env = info.Env();
|
|
13
13
|
|
|
14
|
-
int
|
|
15
|
-
SDL_PowerState
|
|
14
|
+
int _seconds, _percent;
|
|
15
|
+
SDL_PowerState _state = SDL_GetPowerInfo(&_seconds, &_percent);
|
|
16
|
+
|
|
17
|
+
Napi::Value state = _state == SDL_POWERSTATE_UNKNOWN ? env.Null() : Napi::String::New(env, power::states[_state]);
|
|
18
|
+
Napi::Value seconds = _seconds == -1 ? env.Null() : Napi::Number::New(env, _seconds);
|
|
19
|
+
Napi::Value percent = _percent == -1 ? env.Null() : Napi::Number::New(env, _percent);
|
|
16
20
|
|
|
17
21
|
Napi::Object result = Napi::Object::New(env);
|
|
18
|
-
result.Set("state", state
|
|
19
|
-
result.Set("seconds", seconds
|
|
20
|
-
result.Set("percent", percent
|
|
22
|
+
result.Set("state", state);
|
|
23
|
+
result.Set("seconds", seconds);
|
|
24
|
+
result.Set("percent", percent);
|
|
21
25
|
|
|
22
26
|
return result;
|
|
23
27
|
}
|
package/src/native/sensor.cpp
CHANGED
|
@@ -33,8 +33,10 @@ sensor::getDevices (const Napi::CallbackInfo &info)
|
|
|
33
33
|
throw Napi::Error::New(env, message.str());
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
SDL_SensorType
|
|
36
|
+
SDL_SensorType _type = SDL_SensorGetDeviceType(i);
|
|
37
37
|
// This function can only error if the index is invalid.
|
|
38
|
+
Napi::Value type = _type == SDL_SENSOR_UNKNOWN ? env.Null() : Napi::String::New(env, sensor::types[_type]);
|
|
39
|
+
Napi::Value side = _type == SDL_SENSOR_UNKNOWN || _type == SDL_SENSOR_ACCEL || _type == SDL_SENSOR_GYRO ? env.Null() : Napi::String::New(env, sensor::sides[_type]);
|
|
38
40
|
|
|
39
41
|
const char *name = SDL_SensorGetDeviceName(i);
|
|
40
42
|
// This function can only error if the index is invalid.
|
|
@@ -43,8 +45,8 @@ sensor::getDevices (const Napi::CallbackInfo &info)
|
|
|
43
45
|
device.Set("_index", Napi::Number::New(env, i));
|
|
44
46
|
device.Set("id", Napi::Number::New(env, id));
|
|
45
47
|
device.Set("name", Napi::String::New(env, name));
|
|
46
|
-
device.Set("type", type
|
|
47
|
-
device.Set("side",
|
|
48
|
+
device.Set("type", type);
|
|
49
|
+
device.Set("side", side);
|
|
48
50
|
|
|
49
51
|
devices.Set(i, device);
|
|
50
52
|
}
|
package/src/native/window.cpp
CHANGED
|
@@ -179,48 +179,39 @@ window::create (const Napi::CallbackInfo &info)
|
|
|
179
179
|
throw Napi::Error::New(env, message.str());
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
Napi::Buffer<char> native_handle_buffer = Napi::Buffer<char>::New(env, native_handle_size);
|
|
184
|
-
NativeWindowHandle *native_handle = (NativeWindowHandle *) native_handle_buffer.Data();
|
|
185
|
-
native.Set("handle", native_handle_buffer);
|
|
186
|
-
|
|
182
|
+
NativeWindowHandle native_handle;
|
|
187
183
|
#if defined(__LINUX__)
|
|
188
|
-
|
|
184
|
+
native_handle = sys_wm_info.info.x11.window;
|
|
189
185
|
#elif defined(__WIN32__)
|
|
190
|
-
|
|
186
|
+
native_handle = sys_wm_info.info.win.window;
|
|
191
187
|
#elif defined(__MACOSX__)
|
|
192
|
-
|
|
188
|
+
native_handle = getCocoaWindowHandle(sys_wm_info.info.cocoa.window);
|
|
193
189
|
#endif
|
|
190
|
+
native.Set("handle", Napi::Buffer<NativeWindowHandle>::Copy(env, &native_handle, 1));
|
|
194
191
|
|
|
195
192
|
if (is_opengl) {
|
|
196
|
-
|
|
197
|
-
Napi::Buffer<char> native_gl_buffer = Napi::Buffer<char>::New(env, native_gl_size);
|
|
198
|
-
GL_NativeWindow *native_gl = (GL_NativeWindow *) native_gl_buffer.Data();
|
|
199
|
-
native.Set("gl", native_gl_buffer);
|
|
200
|
-
|
|
193
|
+
GL_NativeWindow native_gl;
|
|
201
194
|
#if defined(__LINUX__)
|
|
202
|
-
|
|
195
|
+
native_gl = sys_wm_info.info.x11.window;
|
|
203
196
|
#elif defined(__WIN32__)
|
|
204
|
-
|
|
197
|
+
native_gl = sys_wm_info.info.win.window;
|
|
205
198
|
#elif defined(__MACOSX__)
|
|
206
|
-
|
|
199
|
+
native_gl = getCocoaGlView(sys_wm_info.info.cocoa.window);
|
|
207
200
|
#endif
|
|
201
|
+
native.Set("gl", Napi::Buffer<GL_NativeWindow>::Copy(env, &native_gl, 1));
|
|
208
202
|
}
|
|
209
203
|
else if (is_webgpu) {
|
|
210
|
-
|
|
211
|
-
Napi::Buffer<char> native_gpu_buffer = Napi::Buffer<char>::New(env, native_gpu_size);
|
|
212
|
-
GPU_NativeData *native_gpu = (GPU_NativeData *) native_gpu_buffer.Data();
|
|
213
|
-
native.Set("gpu", native_gpu_buffer);
|
|
214
|
-
|
|
204
|
+
GPU_NativeData native_gpu;
|
|
215
205
|
#if defined(__LINUX__)
|
|
216
|
-
native_gpu
|
|
217
|
-
native_gpu
|
|
206
|
+
native_gpu.display = sys_wm_info.info.x11.display;
|
|
207
|
+
native_gpu.window = sys_wm_info.info.x11.window;
|
|
218
208
|
#elif defined(__WIN32__)
|
|
219
|
-
native_gpu
|
|
220
|
-
native_gpu
|
|
209
|
+
native_gpu.hwnd = sys_wm_info.info.win.window;
|
|
210
|
+
native_gpu.hinstance = sys_wm_info.info.win.hinstance;
|
|
221
211
|
#elif defined(__MACOSX__)
|
|
222
|
-
native_gpu
|
|
212
|
+
native_gpu.layer = getCocoaGpuView(sys_wm_info.info.cocoa.window);
|
|
223
213
|
#endif
|
|
214
|
+
native.Set("gpu", Napi::Buffer<GPU_NativeData>::Copy(env, &native_gpu, 1));
|
|
224
215
|
}
|
|
225
216
|
else {
|
|
226
217
|
cachedTextures[window] = {};
|
package/src/types/index.d.ts
CHANGED