three-gamepad-controls 0.13.0 → 0.13.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.
@@ -47,18 +47,19 @@ var GamepadManager = class {
47
47
  return selectedGamepad;
48
48
  }
49
49
  /**
50
- * Clears the active gamepad when it is the disconnecting gamepad instance.
50
+ * Clears the active gamepad when its browser-assigned index matches the
51
+ * disconnecting gamepad.
51
52
  *
52
- * Identity is intentionally checked in addition to the browser-assigned
53
- * index. Indices may be reused, so a late event from a previous device must
54
- * not disconnect a replacement that now occupies the same slot.
55
- * A matching disconnection defers any replacement until the next update.
53
+ * Gamepad API snapshots are not guaranteed to preserve JavaScript object
54
+ * identity between events and polls, so the active device is correlated by
55
+ * its logical slot. A matching disconnection defers any replacement until
56
+ * the next update.
56
57
  *
57
58
  * @param gamepad - Gamepad snapshot that disconnected.
58
59
  * @returns The previously active gamepad when it was cleared, otherwise `null`.
59
60
  */
60
61
  disconnect(gamepad) {
61
- if (this.activeGamepad !== gamepad) return null;
62
+ if (this.activeGamepad === null || this.activeGamepad.index !== gamepad.index) return null;
62
63
  const disconnectedGamepad = this.activeGamepad;
63
64
  this.activeGamepad = null;
64
65
  this.#connectionDeferredUntilUpdate = true;
@@ -86,7 +87,7 @@ var GamepadManager = class {
86
87
  }
87
88
  const previousGamepad = this.activeGamepad;
88
89
  const nextGamepad = this.#getGamepadByIndex(previousGamepad.index);
89
- if (!previousGamepad.connected || nextGamepad === null || nextGamepad !== previousGamepad) {
90
+ if (nextGamepad === null) {
90
91
  this.activeGamepad = null;
91
92
  this.#connectionDeferredUntilUpdate = true;
92
93
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "three-gamepad-controls",
3
3
  "description": "Gamepad support for Three.js controls.",
4
- "version": "0.13.0",
4
+ "version": "0.13.1",
5
5
  "homepage": "https://github.com/luckasnix/three-gamepad-controls#readme",
6
6
  "author": {
7
7
  "name": "Kasnix",