@sensslen/node-gamepad 1.0.10-beta.21 → 1.0.10-beta.24

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 (2) hide show
  1. package/NodeGamepad.js +16 -18
  2. package/package.json +1 -1
package/NodeGamepad.js CHANGED
@@ -5,17 +5,20 @@ const node_hid_1 = require("node-hid");
5
5
  const events_1 = require("events");
6
6
  const mathjs_1 = require("mathjs");
7
7
  class NodeGamepad extends events_1.EventEmitter {
8
+ config;
9
+ logger;
10
+ _usb = undefined;
11
+ _running = false;
12
+ _joystickStates = {};
13
+ _buttonStates = {};
14
+ _statusStates = {};
15
+ _scaleStates = {};
16
+ _connectRetryTimeout;
17
+ _connectionRetryTimeoutInMs = 500;
8
18
  constructor(config, logger) {
9
19
  super();
10
20
  this.config = config;
11
21
  this.logger = logger;
12
- this._usb = undefined;
13
- this._running = false;
14
- this._joystickStates = {};
15
- this._buttonStates = {};
16
- this._statusStates = {};
17
- this._scaleStates = {};
18
- this._connectionRetryTimeoutInMs = 500;
19
22
  }
20
23
  start() {
21
24
  if (this._running) {
@@ -35,8 +38,7 @@ class NodeGamepad extends events_1.EventEmitter {
35
38
  // todo
36
39
  }
37
40
  logDebug(toLog) {
38
- var _a;
39
- if ((_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug) {
41
+ if (this.logger?.debug) {
40
42
  this.logger.debug(`NodeGamepad (Debug):${toLog}`);
41
43
  }
42
44
  }
@@ -59,7 +61,7 @@ class NodeGamepad extends events_1.EventEmitter {
59
61
  return;
60
62
  }
61
63
  const deviceToConnectTo = deviceList[0];
62
- if ((deviceToConnectTo === null || deviceToConnectTo === void 0 ? void 0 : deviceToConnectTo.path) === undefined) {
64
+ if (deviceToConnectTo?.path === undefined) {
63
65
  this.logDebug('Failed to connect. Checking again later.');
64
66
  this._connectRetryTimeout = setTimeout(() => this.connect(), this._connectionRetryTimeoutInMs);
65
67
  return;
@@ -122,8 +124,7 @@ class NodeGamepad extends events_1.EventEmitter {
122
124
  this.processScales(data);
123
125
  }
124
126
  processJoysticks(data) {
125
- var _a;
126
- (_a = this.config.joysticks) === null || _a === void 0 ? void 0 : _a.forEach((joystick) => {
127
+ this.config.joysticks?.forEach((joystick) => {
127
128
  if (data.length > joystick.x.pin || data.length > joystick.y.pin) {
128
129
  this.processJoystick(joystick, data);
129
130
  }
@@ -141,8 +142,7 @@ class NodeGamepad extends events_1.EventEmitter {
141
142
  this._joystickStates[joystick.name] = newState;
142
143
  }
143
144
  processButtons(data) {
144
- var _a;
145
- (_a = this.config.buttons) === null || _a === void 0 ? void 0 : _a.forEach((button) => {
145
+ this.config.buttons?.forEach((button) => {
146
146
  if (data.length > button.pin) {
147
147
  this.processButton(data, button);
148
148
  }
@@ -163,8 +163,7 @@ class NodeGamepad extends events_1.EventEmitter {
163
163
  this._buttonStates[config.name] = newState;
164
164
  }
165
165
  processScales(data) {
166
- var _a;
167
- (_a = this.config.scales) === null || _a === void 0 ? void 0 : _a.forEach((scale) => {
166
+ this.config.scales?.forEach((scale) => {
168
167
  if (data.length > scale.pin) {
169
168
  this.processScale(scale, data);
170
169
  }
@@ -179,8 +178,7 @@ class NodeGamepad extends events_1.EventEmitter {
179
178
  this._scaleStates[config.name] = newState;
180
179
  }
181
180
  processStates(data) {
182
- var _a;
183
- (_a = this.config.status) === null || _a === void 0 ? void 0 : _a.forEach((status) => {
181
+ this.config.status?.forEach((status) => {
184
182
  if (data.length > status.pin) {
185
183
  this.processState(status, data);
186
184
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sensslen/node-gamepad",
3
- "version": "1.0.10-beta.21",
3
+ "version": "1.0.10-beta.24",
4
4
  "description": "node-gamepad is a package for node that allows you to effortlessly interface your node applications with a variety of gamepad controllers. This is a port of node-gamepad library to typescript by also removing some of the restrictions implied by this library (namely allowing gamepads to be subcleassed and also improving usb interaction)",
5
5
  "homepage": "https://github.com/sensslen/node-gamepad",
6
6
  "bugs": {