dualsense-ts 2.1.39 → 2.2.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.
Files changed (53) hide show
  1. package/README.md +1 -1
  2. package/dist/elements/analog.d.ts +46 -3
  3. package/dist/elements/analog.d.ts.map +1 -1
  4. package/dist/elements/analog.js +41 -14
  5. package/dist/elements/analog.js.map +1 -1
  6. package/dist/elements/axis.js +3 -3
  7. package/dist/elements/axis.js.map +1 -1
  8. package/dist/elements/unisense.js +1 -1
  9. package/dist/elements/unisense.js.map +1 -1
  10. package/dist/input.d.ts +27 -0
  11. package/dist/input.d.ts.map +1 -1
  12. package/dist/input.js +9 -3
  13. package/dist/input.js.map +1 -1
  14. package/docs/Analog.md +81 -90
  15. package/docs/AnalogParams.md +7 -7
  16. package/docs/Axis.md +72 -79
  17. package/docs/Brightness.md +8 -8
  18. package/docs/CommandScopeA.md +16 -16
  19. package/docs/CommandScopeB.md +14 -14
  20. package/docs/Dpad.md +74 -81
  21. package/docs/DpadParams.md +8 -8
  22. package/docs/DualSenseCommand.md +45 -45
  23. package/docs/Dualsense.md +83 -90
  24. package/docs/DualsenseHID.md +47 -42
  25. package/docs/DualsenseHIDState.md +41 -41
  26. package/docs/DualsenseParams.md +17 -17
  27. package/docs/Exports.md +18 -21
  28. package/docs/Haptic.md +1 -1
  29. package/docs/Home.md +29 -31
  30. package/docs/Indicator.md +2 -2
  31. package/docs/Input.md +70 -79
  32. package/docs/InputId.md +84 -84
  33. package/docs/InputParams.md +4 -4
  34. package/docs/LedOptions.md +10 -10
  35. package/docs/Momentary.md +70 -77
  36. package/docs/Motion.md +2 -2
  37. package/docs/Mute.md +71 -89
  38. package/docs/PlayerID.md +12 -12
  39. package/docs/PulseOptions.md +8 -8
  40. package/docs/Touchpad.md +120 -94
  41. package/docs/Trigger.md +75 -82
  42. package/docs/TriggerMode.md +22 -22
  43. package/docs/Unisense.md +74 -81
  44. package/docs/UnisenseParams.md +7 -7
  45. package/package.json +2 -2
  46. package/src/elements/analog.spec.ts +17 -0
  47. package/src/elements/analog.ts +56 -18
  48. package/src/elements/axis.spec.ts +31 -0
  49. package/src/elements/axis.ts +3 -3
  50. package/src/elements/unisense.ts +1 -1
  51. package/src/input.ts +27 -9
  52. package/docs/Increment.md +0 -1554
  53. package/docs/Touch.md +0 -1781
@@ -1,8 +1,11 @@
1
1
  import { Axis } from "./axis";
2
2
  import { Momentary } from "./momentary";
3
3
  import { Input, InputParams } from "../input";
4
- import { Radians, Degrees, Magnitude } from "../math";
4
+ import { Radians, Degrees, Magnitude, Force } from "../math";
5
5
 
6
+ /**
7
+ * Configuration for an analog joystick and its basic inputs.
8
+ */
6
9
  export interface AnalogParams extends InputParams {
7
10
  button?: InputParams;
8
11
  x?: InputParams;
@@ -21,65 +24,100 @@ export interface AnalogParams extends InputParams {
21
24
  export class Analog extends Input<Analog> {
22
25
  public readonly state: Analog = this;
23
26
 
27
+ /**
28
+ * The left/right position of the input.
29
+ */
24
30
  public readonly x: Axis;
31
+ /**
32
+ * The up/down position of the input.
33
+ */
25
34
  public readonly y: Axis;
35
+ /**
36
+ * Button triggered by pressing the stick.
37
+ */
26
38
  public readonly button: Momentary;
27
39
 
28
40
  constructor(params?: AnalogParams) {
29
41
  super(params);
42
+ const { button, x, y, threshold } = params || {};
30
43
 
31
- this.button = new Momentary(
32
- params?.button || { icon: "3", name: "Button" }
33
- );
44
+ this.button = new Momentary(button || { icon: "3", name: "Button" });
34
45
  this.x = new Axis(
35
- params?.x || { icon: "↔", name: "X", threshold: (1 / 128) * 3 }
46
+ x || { icon: "↔", name: "X", threshold: threshold || 0.07 }
36
47
  );
37
48
  this.y = new Axis(
38
- params?.y || { icon: "↕", name: "Y", threshold: (1 / 128) * 3 }
49
+ y || { icon: "↕", name: "Y", threshold: threshold || 0.07 }
39
50
  );
40
51
  }
41
52
 
42
- // Returns true if the stick is away from the idle position, or the button is pressed.
53
+ /**
54
+ * Returns true if the stick is away from the idle position, or the button is pressed.
55
+ */
43
56
  public get active(): boolean {
44
- return this.magnitude > this.threshold || this.button.active;
57
+ return this.x.active || this.y.active || this.button.active;
45
58
  }
46
59
 
47
- // Returns a direction and magnitude representing the stick's position.
48
- public get vector(): { direction: number; magnitude: number } {
60
+ /**
61
+ * Returns a direction and magnitude representing the stick's position.
62
+ */
63
+ public get vector(): { direction: Radians; magnitude: Magnitude } {
49
64
  return { direction: this.direction, magnitude: this.magnitude };
50
65
  }
51
66
 
52
- // Returns the magnitude of the stick's position.
67
+ /**
68
+ * Returns an force from the stick's position.
69
+ */
70
+ public get force(): Force {
71
+ return this.active
72
+ ? Math.max(Math.min(Math.hypot(this.x.state, this.y.state), 1), -1)
73
+ : 0;
74
+ }
75
+
76
+ /**
77
+ * Returns a magnitude from the stick's position.
78
+ */
53
79
  public get magnitude(): Magnitude {
54
- return Math.min(Math.abs(Math.hypot(this.x.state, this.y.state)), 1);
80
+ return Math.abs(this.force);
55
81
  }
56
82
 
57
- // Returns the angle related to the stick's position in radians.
83
+ /**
84
+ * Returns the stick's angle in radians.
85
+ */
58
86
  public get direction(): Radians {
59
87
  return Math.atan2(this.y.state, this.x.state);
60
88
  }
61
89
 
62
- // Alias for `.direction`
90
+ /**
91
+ * Alias for `.direction`
92
+ */
63
93
  public get radians(): Radians {
64
94
  return this.direction;
65
95
  }
66
96
 
67
- // Alias for `.direction`
97
+ /**
98
+ * Alias for `.direction`
99
+ */
68
100
  public get angle(): Radians {
69
101
  return this.direction;
70
102
  }
71
103
 
72
- // Alias for `.direction` converted to degrees.
104
+ /**
105
+ * Alias for `.direction` converted to degrees.
106
+ */
73
107
  public get directionDegrees(): Degrees {
74
108
  return (this.direction * 180) / Math.PI;
75
109
  }
76
110
 
77
- // Alias for `.directionDegrees`.
111
+ /**
112
+ * Alias for `.directionDegrees`.
113
+ */
78
114
  public get degrees(): Degrees {
79
115
  return this.directionDegrees;
80
116
  }
81
117
 
82
- // Alias for `.directionDegrees`.
118
+ /**
119
+ * Alias for `.directionDegrees`.
120
+ */
83
121
  public get angleDegrees(): Degrees {
84
122
  return this.directionDegrees;
85
123
  }
@@ -1,7 +1,38 @@
1
1
  import { Axis } from "./axis";
2
+ import { InputSet } from "../input";
2
3
 
3
4
  describe("Axis", () => {
4
5
  it("should construct", () => {
5
6
  expect(new Axis()).toBeInstanceOf(Axis);
6
7
  });
8
+
9
+ it("should implement `active`", () => {
10
+ const axis = new Axis({ threshold: (1 / 128) * 10 });
11
+ expect(axis.active).toEqual(false);
12
+ axis[InputSet](1);
13
+ expect(axis.active).toEqual(true);
14
+ axis[InputSet](0);
15
+ expect(axis.active).toEqual(false);
16
+ axis[InputSet](-1);
17
+ expect(axis.active).toEqual(true);
18
+ axis[InputSet](0);
19
+ expect(axis.active).toEqual(false);
20
+ axis[InputSet]((1 / 128) * 2);
21
+ expect(axis.active).toEqual(false);
22
+ });
23
+
24
+ it("should implement `force`", () => {
25
+ const axis = new Axis({ threshold: (1 / 128) * 10 });
26
+ expect(axis.force).toEqual(0);
27
+ axis[InputSet](1);
28
+ expect(axis.force).toEqual(1);
29
+ axis[InputSet](0);
30
+ expect(axis.force).toEqual(0);
31
+ axis[InputSet](-1);
32
+ expect(axis.force).toEqual(-1);
33
+ axis[InputSet](0);
34
+ expect(axis.force).toEqual(0);
35
+ axis[InputSet]((1 / 128) * 2);
36
+ expect(axis.force).toEqual(0);
37
+ });
7
38
  });
@@ -5,14 +5,14 @@ export class Axis extends Input<Force> {
5
5
  public state: Force = 0;
6
6
 
7
7
  public get active(): boolean {
8
- return this.magnitude > this.threshold;
8
+ return Math.abs(this.state) > this.threshold;
9
9
  }
10
10
 
11
11
  public get force(): Force {
12
- return this.state;
12
+ return this.active ? this.state : 0;
13
13
  }
14
14
 
15
15
  public get magnitude(): Magnitude {
16
- return Math.abs(this.state);
16
+ return Math.abs(this.force);
17
17
  }
18
18
  }
@@ -33,7 +33,7 @@ export class Unisense extends Input<Unisense> {
33
33
  params?.bumper || { icon: "1", name: "Bumper" }
34
34
  );
35
35
  this.analog = new Analog(
36
- params?.analog || { icon: "⨁", name: "Analog", threshold: (1 / 128) * 3 }
36
+ params?.analog || { icon: "⨁", name: "Analog", threshold: 0.07 }
37
37
  );
38
38
  this.haptic = new Haptic();
39
39
  }
package/src/input.ts CHANGED
@@ -57,19 +57,29 @@ export abstract class Input<Type>
57
57
  {
58
58
  public readonly id: symbol;
59
59
 
60
- // Timestamp of the last received input that changed the state.
60
+ /**
61
+ * Timestamp of the last received input that changed the state.
62
+ */
61
63
  public lastChange: number = Date.now();
62
64
 
63
- // Timestamp of the last received input, even if it didn't change the state.
65
+ /**
66
+ * Timestamp of the last received input, even if it didn't change the state.
67
+ */
64
68
  public lastInput: number = Date.now();
65
69
 
66
- // For numeric inputs, ignore state changes smaller than this threshold.
70
+ /**
71
+ * For numeric inputs, ignore state changes smaller than this threshold.
72
+ */
67
73
  public threshold: number = 0;
68
74
 
69
- // Provide the type and default value for the input.
75
+ /**
76
+ * Provide the type and default value for the input.
77
+ */
70
78
  public abstract state: Type;
71
79
 
72
- // Implement a function that returns true if the user is actively engaged with the input.
80
+ /**
81
+ * Implement a function that returns true if the user is actively engaged with the input.
82
+ */
73
83
  public abstract get active(): boolean;
74
84
 
75
85
  /**
@@ -124,7 +134,9 @@ export abstract class Input<Type>
124
134
  });
125
135
  }
126
136
 
127
- // Optionally, implement a function that returns true if the provided state is worth an event
137
+ /**
138
+ * Optionally, implement a function that returns true if the provided state is worth an event
139
+ */
128
140
  [InputChanged]: (state: Type, newState: Type) => boolean;
129
141
 
130
142
  // TODO Support params for nested inputs
@@ -150,13 +162,19 @@ export abstract class Input<Type>
150
162
  return this.toString();
151
163
  }
152
164
 
153
- // A name for this input
165
+ /**
166
+ * The name of this input.
167
+ */
154
168
  readonly [InputName]: string;
155
169
 
156
- // A short name for this input
170
+ /**
171
+ * A short name for this input
172
+ */
157
173
  readonly [InputIcon]: string;
158
174
 
159
- // The Input's parent, if any
175
+ /**
176
+ * The Input's parent, if any
177
+ */
160
178
  [InputParent]?: Input<unknown>;
161
179
 
162
180
  [InputChildless]: boolean = true;