@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 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
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.11.3",
2
+ "version": "0.11.4",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
@@ -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 firmware = SDL_JoystickGetFirmwareVersion(joystick);
122
- Napi::Value firmware_version = firmware == 0 ? env.Null() : Napi::Number::New(env, firmware);
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 *serial = SDL_JoystickGetSerial(joystick);
125
- Napi::Value serial_number = serial == 0 ? env.Null() : Napi::String::New(env, serial);
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
 
@@ -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 vendor_number = SDL_JoystickGetDeviceVendor(i);
68
- Napi::Value vendor = vendor_number == 0 ? env.Null() : Napi::Number::New(env, vendor_number);
67
+ int _vendor = SDL_JoystickGetDeviceVendor(i);
68
+ Napi::Value vendor = _vendor == 0 ? env.Null() : Napi::Number::New(env, _vendor);
69
69
 
70
- int product_number = SDL_JoystickGetDeviceProduct(i);
71
- Napi::Value product = product_number == 0 ? env.Null() : Napi::Number::New(env, product_number);
70
+ int _product = SDL_JoystickGetDeviceProduct(i);
71
+ Napi::Value product = _product == 0 ? env.Null() : Napi::Number::New(env, _product);
72
72
 
73
- int version_number = SDL_JoystickGetDeviceProductVersion(i);
74
- Napi::Value version = version_number == 0 ? env.Null() : Napi::Number::New(env, version_number);
73
+ int _Version = SDL_JoystickGetDeviceProductVersion(i);
74
+ Napi::Value version = _Version == 0 ? env.Null() : Napi::Number::New(env, _Version);
75
75
 
76
- int player_number = SDL_JoystickGetDevicePlayerIndex(i);
77
- Napi::Value player = player_number == -1 ? env.Null() : Napi::Number::New(env, player_number);
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 firmware = SDL_JoystickGetFirmwareVersion(joystick);
148
- Napi::Value firmware_version = firmware == 0 ? env.Null() : Napi::Number::New(env, firmware);
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 *serial = SDL_JoystickGetSerial(joystick);
151
- Napi::Value serial_number = serial == nullptr ? env.Null() : Napi::String::New(env, serial);
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);
@@ -11,13 +11,17 @@ power::getInfo (const Napi::CallbackInfo &info)
11
11
  {
12
12
  Napi::Env env = info.Env();
13
13
 
14
- int seconds, percent;
15
- SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
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 == SDL_POWERSTATE_UNKNOWN ? env.Null() : Napi::String::New(env, power::states[state]));
19
- result.Set("seconds", seconds == -1 ? env.Null() : Napi::Number::New(env, seconds));
20
- result.Set("percent", percent == -1 ? env.Null() : Napi::Number::New(env, percent));
22
+ result.Set("state", state);
23
+ result.Set("seconds", seconds);
24
+ result.Set("percent", percent);
21
25
 
22
26
  return result;
23
27
  }
@@ -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 type = SDL_SensorGetDeviceType(i);
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 == 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]));
48
+ device.Set("type", type);
49
+ device.Set("side", side);
48
50
 
49
51
  devices.Set(i, device);
50
52
  }
@@ -179,48 +179,39 @@ window::create (const Napi::CallbackInfo &info)
179
179
  throw Napi::Error::New(env, message.str());
180
180
  }
181
181
 
182
- int native_handle_size = sizeof(NativeWindowHandle);
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
- *native_handle = sys_wm_info.info.x11.window;
184
+ native_handle = sys_wm_info.info.x11.window;
189
185
  #elif defined(__WIN32__)
190
- *native_handle = sys_wm_info.info.win.window;
186
+ native_handle = sys_wm_info.info.win.window;
191
187
  #elif defined(__MACOSX__)
192
- *native_handle = getCocoaWindowHandle(sys_wm_info.info.cocoa.window);
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
- int native_gl_size = sizeof(GL_NativeWindow);
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
- *native_gl = sys_wm_info.info.x11.window;
195
+ native_gl = sys_wm_info.info.x11.window;
203
196
  #elif defined(__WIN32__)
204
- *native_gl = sys_wm_info.info.win.window;
197
+ native_gl = sys_wm_info.info.win.window;
205
198
  #elif defined(__MACOSX__)
206
- *native_gl = getCocoaGlView(sys_wm_info.info.cocoa.window);
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
- int native_gpu_size = sizeof(GPU_NativeData);
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->display = sys_wm_info.info.x11.display;
217
- native_gpu->window = sys_wm_info.info.x11.window;
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->hwnd = sys_wm_info.info.win.window;
220
- native_gpu->hinstance = sys_wm_info.info.win.hinstance;
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->layer = getCocoaGpuView(sys_wm_info.info.cocoa.window);
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] = {};
@@ -985,6 +985,7 @@ export namespace Sdl {
985
985
  readonly device: Device
986
986
  readonly firmwareVersion: number
987
987
  readonly serialNumber: string
988
+ readonly steamHandle: Buffer | null
988
989
 
989
990
  readonly axes: {
990
991
  readonly leftStickX: number