dualsense-ts 3.0.0 → 3.1.0

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.
@@ -10,6 +10,7 @@ export interface AnalogParams extends InputParams {
10
10
  x?: InputParams;
11
11
  y?: InputParams;
12
12
  threshold?: Magnitude;
13
+ deadzone?: Magnitude;
13
14
  }
14
15
  /**
15
16
  * Represents an analog joystick.
@@ -33,6 +34,10 @@ export declare class Analog extends Input<Analog> {
33
34
  * Button triggered by pressing the stick.
34
35
  */
35
36
  readonly button: Momentary;
37
+ /**
38
+ * Ignores stick movement below this value (0 to 1).
39
+ */
40
+ deadzone: number;
36
41
  constructor(params?: AnalogParams);
37
42
  /**
38
43
  * Returns true if the stick is away from the idle position, or the button is pressed.
@@ -46,7 +51,8 @@ export declare class Analog extends Input<Analog> {
46
51
  magnitude: Magnitude;
47
52
  };
48
53
  /**
49
- * Returns an force from the stick's position.
54
+ * Returns a force from the stick's position.
55
+ * This ignores the deadzone value.
50
56
  */
51
57
  get force(): Force;
52
58
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"analog.d.ts","sourceRoot":"","sources":["../../src/elements/analog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,CAAC,CAAC,EAAE,WAAW,CAAC;IAChB,CAAC,CAAC,EAAE,WAAW,CAAC;IAChB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,qBAAa,MAAO,SAA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AAW,CAAC;IAGhB,CAAC,CAAC,EAAE,WAAW,CAAC;IAGhB,SAAS,CAAC,EAAE,SAAS,CAAC;IAGtB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,qBAAa,MAAO,SAAQ,KAAK,CAAC,MAAM,CAAC;IACvC,SAAgB,KAAK,EAAE,IAAI,CAAQ;IAEnC;;OAEG;IACH,SAAgB,CAAC,EAAE,IAAI,CAAC;IACxB;;OAEG;IACH,SAAgB,CAAC,EAAE,IAAI,CAAC;IACxB;;OAEG;IACH,SAAgB,MAAM,EAAE,SAAS,CAAC;IAClC;;OAEG;IACI,QAAQ,EAAE,MAAM,CAAQ;gBAEnB,MAAM,CAAC,EAAE,YAAY;IAqBjC;;OAEG;IACH,IAAW,MAAM,IAAI,OAAO,CAE3B;IAED;;OAEG;IACH,IAAW,MAAM,IAAI;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,SAAS,CAAA;KAAE,CAEhE;IAED;;;OAGG;IACH,IAAW,KAAK,IAAI,KAAK,CAExB;IAED;;OAEG;IACH,IAAW,SAAS,IAAI,SAAS,CAIhC;IAED;;OAEG;IACH,IAAW,SAAS,IAAI,OAAO,CAE9B;IAED;;OAEG;IACH,IAAW,OAAO,IAAI,OAAO,CAE5B;IAED;;OAEG;IACH,IAAW,KAAK,IAAI,OAAO,CAE1B;IAED;;OAEG;IACH,IAAW,gBAAgB,IAAI,OAAO,CAErC;IAED;;OAEG;IACH,IAAW,OAAO,IAAI,OAAO,CAE5B;IAED;;OAEG;IACH,IAAW,YAAY,IAAI,OAAO,CAEjC;CACF"}
@@ -16,18 +16,26 @@ class Analog extends input_1.Input {
16
16
  constructor(params) {
17
17
  super(params);
18
18
  this.state = this;
19
- const { button, x, y, threshold } = params || {};
19
+ /**
20
+ * Ignores stick movement below this value (0 to 1).
21
+ */
22
+ this.deadzone = 0.05;
23
+ const { button, x, y, deadzone, threshold } = params || {};
24
+ if (threshold)
25
+ this.threshold = threshold;
26
+ if (deadzone)
27
+ this.deadzone = deadzone;
20
28
  this.button = new momentary_1.Momentary({ icon: "3", name: "Button", ...button });
21
29
  this.x = new axis_1.Axis({
22
30
  icon: "↔",
23
31
  name: "X",
24
- threshold: threshold || 0.01,
32
+ ...params,
25
33
  ...x,
26
34
  });
27
35
  this.y = new axis_1.Axis({
28
36
  icon: "↕",
29
37
  name: "Y",
30
- threshold: threshold || 0.01,
38
+ ...params,
31
39
  ...y,
32
40
  });
33
41
  }
@@ -35,7 +43,7 @@ class Analog extends input_1.Input {
35
43
  * Returns true if the stick is away from the idle position, or the button is pressed.
36
44
  */
37
45
  get active() {
38
- return this.x.active || this.y.active || this.button.active;
46
+ return this.magnitude > 0 || this.button.active;
39
47
  }
40
48
  /**
41
49
  * Returns a direction and magnitude representing the stick's position.
@@ -44,18 +52,20 @@ class Analog extends input_1.Input {
44
52
  return { direction: this.direction, magnitude: this.magnitude };
45
53
  }
46
54
  /**
47
- * Returns an force from the stick's position.
55
+ * Returns a force from the stick's position.
56
+ * This ignores the deadzone value.
48
57
  */
49
58
  get force() {
50
- return this.active
51
- ? Math.max(Math.min(Math.hypot(this.x.state, this.y.state), 1), -1)
52
- : 0;
59
+ return Math.max(Math.min(Math.hypot(this.x.state, this.y.state), 1), -1);
53
60
  }
54
61
  /**
55
62
  * Returns a magnitude from the stick's position.
56
63
  */
57
64
  get magnitude() {
58
- return Math.abs(this.force);
65
+ const magnitude = Math.abs(this.force);
66
+ if (magnitude < this.deadzone)
67
+ return 0;
68
+ return (magnitude - this.deadzone) / (1 - this.deadzone);
59
69
  }
60
70
  /**
61
71
  * Returns the stick's angle in radians.
@@ -1 +1 @@
1
- {"version":3,"file":"analog.js","sourceRoot":"","sources":["../../src/elements/analog.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAC9B,2CAAwC;AACxC,oCAA8C;AAa9C;;;;;;;GAOG;AACH,MAAa,MAAO,SAAQ,aAAa;IAgBvC,YAAY,MAAqB;QA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AC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3D,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAW,gBAAgB;QACzB,OAAO,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAW,YAAY;QACrB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAjHD,wBAiHC"}
@@ -8,6 +8,7 @@ export declare class Touch extends Analog {
8
8
  readonly state: this;
9
9
  readonly contact: import("./momentary").Momentary;
10
10
  readonly tracker: Increment;
11
+ deadzone: number;
11
12
  get active(): boolean;
12
13
  }
13
14
  //# sourceMappingURL=touch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"touch.d.ts","sourceRoot":"","sources":["../../src/elements/touch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,qBAAa,KAAM,SAAQ,MAAM;IAC/B,SAAgB,KAAK,EAAE,IAAI,CAAQ;IACnC,SAAgB,OAAO,kCAAe;IACtC,SAAgB,OAAO,EAAE,SAAS,CAAmB;IAErD,IAAW,MAAM,IAAI,OAAO,CAE3B;CACF"}
1
+ {"version":3,"file":"touch.d.ts","sourceRoot":"","sources":["../../src/elements/touch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,qBAAa,KAAM,SAAQ,MAAM;IAC/B,SAAgB,KAAK,EAAE,IAAI,CAAQ;IACnC,SAAgB,OAAO,kCAAe;IACtC,SAAgB,OAAO,EAAE,SAAS,CAAmB;IAC9C,QAAQ,SAAK;IAEpB,IAAW,MAAM,IAAI,OAAO,CAE3B;CACF"}
@@ -13,6 +13,7 @@ class Touch extends analog_1.Analog {
13
13
  this.state = this;
14
14
  this.contact = this.button;
15
15
  this.tracker = new increment_1.Increment();
16
+ this.deadzone = 0;
16
17
  }
17
18
  get active() {
18
19
  return this.contact.active;
@@ -1 +1 @@
1
- {"version":3,"file":"touch.js","sourceRoot":"","sources":["../../src/elements/touch.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAClC,2CAAwC;AAExC;;;GAGG;AACH,MAAa,KAAM,SAAQ,eAAM;IAAjC;;QACkB,UAAK,GAAS,IAAI,CAAC;QACnB,YAAO,GAAG,IAAI,CAAC,MAAM,CAAC;QACtB,YAAO,GAAc,IAAI,qBAAS,EAAE,CAAC;IAKvD,CAAC;IAHC,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;CACF;AARD,sBAQC"}
1
+ {"version":3,"file":"touch.js","sourceRoot":"","sources":["../../src/elements/touch.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAClC,2CAAwC;AAExC;;;GAGG;AACH,MAAa,KAAM,SAAQ,eAAM;IAAjC;;QACkB,UAAK,GAAS,IAAI,CAAC;QACnB,YAAO,GAAG,IAAI,CAAC,MAAM,CAAC;QACtB,YAAO,GAAc,IAAI,qBAAS,EAAE,CAAC;QAC9C,aAAQ,GAAG,CAAC,CAAC;IAKtB,CAAC;IAHC,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;CACF;AATD,sBASC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dualsense-ts",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "A natural interface for your DualSense controller, with Typescript",
5
5
  "keywords": [
6
6
  "dualsense",
@@ -25,8 +25,8 @@ describe("Analog", () => {
25
25
  expect(analog.active).toEqual(false);
26
26
  });
27
27
 
28
- it("should utilize `threshold`", () => {
29
- const analog = new Analog({ threshold: 0.5 });
28
+ it("should utilize `deadzone`", () => {
29
+ const analog = new Analog({ deadzone: 0.5 });
30
30
  expect(analog.active).toEqual(false);
31
31
  analog.x[InputSet](0.4);
32
32
  expect(analog.active).toEqual(false);
@@ -42,19 +42,6 @@ describe("Analog", () => {
42
42
  expect(analog.active).toEqual(false);
43
43
  });
44
44
 
45
- it("children inherit `threshold`", () => {
46
- const analog = new Analog({ threshold: 0.5 });
47
- expect(analog.x.active).toEqual(false);
48
- analog.x[InputSet](0.4);
49
- expect(analog.x.active).toEqual(false);
50
- analog.x[InputSet](0.5);
51
- expect(analog.x.active).toEqual(false);
52
- analog.x[InputSet](0.6);
53
- expect(analog.x.active).toEqual(true);
54
- analog.x[InputSet](0);
55
- expect(analog.x.active).toEqual(false);
56
- });
57
-
58
45
  it("should return good directions", () => {
59
46
  const analog = new Analog();
60
47
  expect(analog.radians).toBeCloseTo(0);
@@ -7,10 +7,20 @@ import { Radians, Degrees, Magnitude, Force } from "../math";
7
7
  * Configuration for an analog joystick and its basic inputs.
8
8
  */
9
9
  export interface AnalogParams extends InputParams {
10
+ // Configuration for the input's button
10
11
  button?: InputParams;
12
+
13
+ // Configuration for the input's x axis
11
14
  x?: InputParams;
15
+
16
+ // Configuration for the input's y axis
12
17
  y?: InputParams;
18
+
19
+ // Do not produce callbacks for input changes below this threshold
13
20
  threshold?: Magnitude;
21
+
22
+ // Ignore input while magnitude is less than or equal to this value
23
+ deadzone?: Magnitude;
14
24
  }
15
25
 
16
26
  /**
@@ -36,22 +46,28 @@ export class Analog extends Input<Analog> {
36
46
  * Button triggered by pressing the stick.
37
47
  */
38
48
  public readonly button: Momentary;
49
+ /**
50
+ * Ignores stick movement below this value (0 to 1).
51
+ */
52
+ public deadzone: number = 0.05;
39
53
 
40
54
  constructor(params?: AnalogParams) {
41
55
  super(params);
42
- const { button, x, y, threshold } = params || {};
56
+ const { button, x, y, deadzone, threshold } = params || {};
43
57
 
58
+ if (threshold) this.threshold = threshold;
59
+ if (deadzone) this.deadzone = deadzone;
44
60
  this.button = new Momentary({ icon: "3", name: "Button", ...button });
45
61
  this.x = new Axis({
46
62
  icon: "↔",
47
63
  name: "X",
48
- threshold: threshold || 0.01,
64
+ ...params,
49
65
  ...x,
50
66
  });
51
67
  this.y = new Axis({
52
68
  icon: "↕",
53
69
  name: "Y",
54
- threshold: threshold || 0.01,
70
+ ...params,
55
71
  ...y,
56
72
  });
57
73
  }
@@ -60,7 +76,7 @@ export class Analog extends Input<Analog> {
60
76
  * Returns true if the stick is away from the idle position, or the button is pressed.
61
77
  */
62
78
  public get active(): boolean {
63
- return this.x.active || this.y.active || this.button.active;
79
+ return this.magnitude > 0 || this.button.active;
64
80
  }
65
81
 
66
82
  /**
@@ -71,19 +87,20 @@ export class Analog extends Input<Analog> {
71
87
  }
72
88
 
73
89
  /**
74
- * Returns an force from the stick's position.
90
+ * Returns a force from the stick's position.
91
+ * This ignores the deadzone value.
75
92
  */
76
93
  public get force(): Force {
77
- return this.active
78
- ? Math.max(Math.min(Math.hypot(this.x.state, this.y.state), 1), -1)
79
- : 0;
94
+ return Math.max(Math.min(Math.hypot(this.x.state, this.y.state), 1), -1);
80
95
  }
81
96
 
82
97
  /**
83
98
  * Returns a magnitude from the stick's position.
84
99
  */
85
100
  public get magnitude(): Magnitude {
86
- return Math.abs(this.force);
101
+ const magnitude = Math.abs(this.force);
102
+ if (magnitude < this.deadzone) return 0;
103
+ return (magnitude - this.deadzone) / (1 - this.deadzone);
87
104
  }
88
105
 
89
106
  /**
@@ -9,6 +9,7 @@ export class Touch extends Analog {
9
9
  public readonly state: this = this;
10
10
  public readonly contact = this.button;
11
11
  public readonly tracker: Increment = new Increment();
12
+ public deadzone = 0;
12
13
 
13
14
  public get active(): boolean {
14
15
  return this.contact.active;