dualsense-ts 3.1.0 → 3.1.3
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/dist/elements/analog.d.ts +5 -6
- package/dist/elements/analog.d.ts.map +1 -1
- package/dist/elements/analog.js +3 -5
- package/dist/elements/analog.js.map +1 -1
- package/dist/elements/axis.d.ts +22 -1
- package/dist/elements/axis.d.ts.map +1 -1
- package/dist/elements/axis.js +24 -4
- package/dist/elements/axis.js.map +1 -1
- package/dist/elements/unisense.d.ts +2 -2
- package/dist/elements/unisense.d.ts.map +1 -1
- package/dist/elements/unisense.js +1 -0
- package/dist/elements/unisense.js.map +1 -1
- package/package.json +1 -1
- package/src/elements/analog.ts +9 -13
- package/src/elements/axis.ts +35 -3
- package/src/elements/unisense.ts +3 -2
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { Axis } from "./axis";
|
|
1
|
+
import { Axis, AxisParams } from "./axis";
|
|
2
2
|
import { Momentary } from "./momentary";
|
|
3
3
|
import { Input, InputParams } from "../input";
|
|
4
4
|
import { Radians, Degrees, Magnitude, Force } from "../math";
|
|
5
5
|
/**
|
|
6
|
-
* Configuration for an analog joystick and its
|
|
6
|
+
* Configuration for an analog joystick and its component inputs.
|
|
7
7
|
*/
|
|
8
8
|
export interface AnalogParams extends InputParams {
|
|
9
9
|
button?: InputParams;
|
|
10
|
-
x?:
|
|
11
|
-
y?:
|
|
12
|
-
threshold?: Magnitude;
|
|
10
|
+
x?: AxisParams;
|
|
11
|
+
y?: AxisParams;
|
|
13
12
|
deadzone?: Magnitude;
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
@@ -37,7 +36,7 @@ export declare class Analog extends Input<Analog> {
|
|
|
37
36
|
/**
|
|
38
37
|
* Ignores stick movement below this value (0 to 1).
|
|
39
38
|
*/
|
|
40
|
-
deadzone:
|
|
39
|
+
deadzone: Magnitude;
|
|
41
40
|
constructor(params?: AnalogParams);
|
|
42
41
|
/**
|
|
43
42
|
* Returns true if the stick is away from the idle position, or the button is pressed.
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"analog.d.ts","sourceRoot":"","sources":["../../src/elements/analog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC1C,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;IAE/C,MAAM,CAAC,EAAE,WAAW,CAAC;IAGrB,CAAC,CAAC,EAAE,UAAU,CAAC;IAGf,CAAC,CAAC,EAAE,UAAU,CAAC;IAGf,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,SAAS,CAAQ;gBAEtB,MAAM,CAAC,EAAE,YAAY;IAoBjC;;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"}
|
package/dist/elements/analog.js
CHANGED
|
@@ -20,9 +20,7 @@ class Analog extends input_1.Input {
|
|
|
20
20
|
* Ignores stick movement below this value (0 to 1).
|
|
21
21
|
*/
|
|
22
22
|
this.deadzone = 0.05;
|
|
23
|
-
const { button, x, y, deadzone
|
|
24
|
-
if (threshold)
|
|
25
|
-
this.threshold = threshold;
|
|
23
|
+
const { button, x, y, deadzone } = params || {};
|
|
26
24
|
if (deadzone)
|
|
27
25
|
this.deadzone = deadzone;
|
|
28
26
|
this.button = new momentary_1.Momentary({ icon: "3", name: "Button", ...button });
|
|
@@ -56,7 +54,7 @@ class Analog extends input_1.Input {
|
|
|
56
54
|
* This ignores the deadzone value.
|
|
57
55
|
*/
|
|
58
56
|
get force() {
|
|
59
|
-
return Math.max(Math.min(Math.hypot(this.x.
|
|
57
|
+
return Math.max(Math.min(Math.hypot(this.x.force, this.y.force), 1), -1);
|
|
60
58
|
}
|
|
61
59
|
/**
|
|
62
60
|
* Returns a magnitude from the stick's position.
|
|
@@ -71,7 +69,7 @@ class Analog extends input_1.Input {
|
|
|
71
69
|
* Returns the stick's angle in radians.
|
|
72
70
|
*/
|
|
73
71
|
get direction() {
|
|
74
|
-
return Math.atan2(this.y.
|
|
72
|
+
return Math.atan2(this.y.force, this.x.force);
|
|
75
73
|
}
|
|
76
74
|
/**
|
|
77
75
|
* Alias for `.direction`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analog.js","sourceRoot":"","sources":["../../src/elements/analog.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"analog.js","sourceRoot":"","sources":["../../src/elements/analog.ts"],"names":[],"mappings":";;;AAAA,iCAA0C;AAC1C,2CAAwC;AACxC,oCAA8C;AAoB9C;;;;;;;GAOG;AACH,MAAa,MAAO,SAAQ,aAAa;IAoBvC,YAAY,MAAqB;QAC/B,KAAK,CAAC,MAAM,CAAC,CAAC;QApBA,UAAK,GAAS,IAAI,CAAC;QAcnC;;WAEG;QACI,aAAQ,GAAc,IAAI,CAAC;QAIhC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;QAEhD,IAAI,QAAQ;YAAE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,IAAI,qBAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,CAAC,GAAG,IAAI,WAAI,CAAC;YAChB,IAAI,EAAE,GAAG;YACT,IAAI,EAAE,GAAG;YACT,GAAG,MAAM;YACT,GAAG,CAAC;SACL,CAAC,CAAC;QACH,IAAI,CAAC,CAAC,GAAG,IAAI,WAAI,CAAC;YAChB,IAAI,EAAE,GAAG;YACT,IAAI,EAAE,GAAG;YACT,GAAG,MAAM;YACT,GAAG,CAAC;SACL,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,SAAS,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,IAAW,MAAM;QACf,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;IAClE,CAAC;IAED;;;OAGG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAClB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvC,IAAI,SAAS,GAAG,IAAI,CAAC,QAAQ;YAAE,OAAO,CAAC,CAAC;QACxC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,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;AAhHD,wBAgHC"}
|
package/dist/elements/axis.d.ts
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
|
-
import { Input } from "../input";
|
|
1
|
+
import { Input, InputParams } from "../input";
|
|
2
2
|
import { Force, Magnitude } from "../math";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for an Axis input.
|
|
5
|
+
*/
|
|
6
|
+
export interface AxisParams extends InputParams {
|
|
7
|
+
deadzone?: Magnitude;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Represents a simple ranged input. For example, one axis of an analog
|
|
11
|
+
* joystick or touchpad, the pull of a trigger, or the movement of a gyroscope.
|
|
12
|
+
*/
|
|
3
13
|
export declare class Axis extends Input<Force> {
|
|
4
14
|
state: Force;
|
|
15
|
+
/**
|
|
16
|
+
* Ignores inputs of magnitude less than this value (0 to 1).
|
|
17
|
+
*/
|
|
18
|
+
deadzone: Magnitude;
|
|
19
|
+
constructor(params?: AxisParams);
|
|
5
20
|
get active(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the axis position, ignoring the deadzone value.
|
|
23
|
+
*/
|
|
6
24
|
get force(): Force;
|
|
25
|
+
/**
|
|
26
|
+
* Returns an absolute axis position.
|
|
27
|
+
*/
|
|
7
28
|
get magnitude(): Magnitude;
|
|
8
29
|
}
|
|
9
30
|
//# sourceMappingURL=axis.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axis.d.ts","sourceRoot":"","sources":["../../src/elements/axis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"axis.d.ts","sourceRoot":"","sources":["../../src/elements/axis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,UAAW,SAAQ,WAAW;IAE7C,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED;;;GAGG;AACH,qBAAa,IAAK,SAAQ,KAAK,CAAC,KAAK,CAAC;IAC7B,KAAK,EAAE,KAAK,CAAK;IAExB;;OAEG;IACI,QAAQ,EAAE,SAAS,CAAQ;gBAEtB,MAAM,CAAC,EAAE,UAAU;IAO/B,IAAW,MAAM,IAAI,OAAO,CAE3B;IAED;;OAEG;IACH,IAAW,KAAK,IAAI,KAAK,CAExB;IAED;;OAEG;IACH,IAAW,SAAS,IAAI,SAAS,CAIhC;CACF"}
|
package/dist/elements/axis.js
CHANGED
|
@@ -2,19 +2,39 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Axis = void 0;
|
|
4
4
|
const input_1 = require("../input");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a simple ranged input. For example, one axis of an analog
|
|
7
|
+
* joystick or touchpad, the pull of a trigger, or the movement of a gyroscope.
|
|
8
|
+
*/
|
|
5
9
|
class Axis extends input_1.Input {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(
|
|
10
|
+
constructor(params) {
|
|
11
|
+
super(params);
|
|
8
12
|
this.state = 0;
|
|
13
|
+
/**
|
|
14
|
+
* Ignores inputs of magnitude less than this value (0 to 1).
|
|
15
|
+
*/
|
|
16
|
+
this.deadzone = 0.05;
|
|
17
|
+
const { deadzone } = params || {};
|
|
18
|
+
if (deadzone)
|
|
19
|
+
this.deadzone = deadzone;
|
|
9
20
|
}
|
|
10
21
|
get active() {
|
|
11
|
-
return Math.abs(this.state) > this.
|
|
22
|
+
return Math.abs(this.state) > this.deadzone;
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns the axis position, ignoring the deadzone value.
|
|
26
|
+
*/
|
|
13
27
|
get force() {
|
|
14
28
|
return this.active ? this.state : 0;
|
|
15
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns an absolute axis position.
|
|
32
|
+
*/
|
|
16
33
|
get magnitude() {
|
|
17
|
-
|
|
34
|
+
const magnitude = Math.abs(this.force);
|
|
35
|
+
if (magnitude < this.deadzone)
|
|
36
|
+
return 0;
|
|
37
|
+
return (magnitude - this.deadzone) / (1 - this.deadzone);
|
|
18
38
|
}
|
|
19
39
|
}
|
|
20
40
|
exports.Axis = Axis;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axis.js","sourceRoot":"","sources":["../../src/elements/axis.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"axis.js","sourceRoot":"","sources":["../../src/elements/axis.ts"],"names":[],"mappings":";;;AAAA,oCAA8C;AAW9C;;;GAGG;AACH,MAAa,IAAK,SAAQ,aAAY;IAQpC,YAAY,MAAmB;QAC7B,KAAK,CAAC,MAAM,CAAC,CAAC;QART,UAAK,GAAU,CAAC,CAAC;QAExB;;WAEG;QACI,aAAQ,GAAc,IAAI,CAAC;QAIhC,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;QAElC,IAAI,QAAQ;YAAE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACzC,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAClB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvC,IAAI,SAAS,GAAG,IAAI,CAAC,QAAQ;YAAE,OAAO,CAAC,CAAC;QACxC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3D,CAAC;CACF;AAlCD,oBAkCC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Trigger } from "./trigger";
|
|
2
2
|
import { Momentary } from "./momentary";
|
|
3
|
-
import { Analog } from "./analog";
|
|
3
|
+
import { Analog, AnalogParams } from "./analog";
|
|
4
4
|
import { Haptic } from "../haptics";
|
|
5
5
|
import { Input, InputParams } from "../input";
|
|
6
6
|
export interface UnisenseParams extends InputParams {
|
|
7
7
|
trigger?: InputParams;
|
|
8
8
|
bumper?: InputParams;
|
|
9
|
-
analog?:
|
|
9
|
+
analog?: AnalogParams;
|
|
10
10
|
}
|
|
11
11
|
export declare class Unisense extends Input<Unisense> {
|
|
12
12
|
readonly state: this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unisense.d.ts","sourceRoot":"","sources":["../../src/elements/unisense.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"unisense.d.ts","sourceRoot":"","sources":["../../src/elements/unisense.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE9C,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAGD,qBAAa,QAAS,SAAQ,KAAK,CAAC,QAAQ,CAAC;IAC3C,SAAgB,KAAK,EAAE,IAAI,CAAQ;IAEnC,SAAgB,OAAO,EAAE,OAAO,CAAC;IACjC,SAAgB,MAAM,EAAE,SAAS,CAAC;IAClC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,MAAM,EAAE,MAAM,CAAC;gBAEnB,MAAM,GAAE,cAAmB;IAqBvC,IAAW,MAAM,IAAI,OAAO,CAE3B;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unisense.js","sourceRoot":"","sources":["../../src/elements/unisense.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,2CAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"unisense.js","sourceRoot":"","sources":["../../src/elements/unisense.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,2CAAwC;AACxC,qCAAgD;AAChD,wCAAoC;AACpC,oCAA8C;AAQ9C,iFAAiF;AACjF,MAAa,QAAS,SAAQ,aAAe;IAQ3C,YAAY,SAAyB,EAAE;QACrC,KAAK,CAAC,MAAM,CAAC,CAAC;QARA,UAAK,GAAS,IAAI,CAAC;QASjC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;QAE3C,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAO,CAAC;YACzB,IAAI,EAAE,GAAG;YACT,IAAI,EAAE,SAAS;YACf,SAAS,EAAE,CAAC,GAAG,GAAG;YAClB,GAAG,OAAO;SACX,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,IAAI,qBAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC;YACvB,IAAI,EAAE,GAAG;YACT,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,CAAC,GAAG,GAAG;YAClB,QAAQ,EAAE,CAAC,GAAG,GAAG;YACjB,GAAG,MAAM;SACV,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAM,EAAE,CAAC;IAC7B,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IACzE,CAAC;CACF;AAhCD,4BAgCC"}
|
package/package.json
CHANGED
package/src/elements/analog.ts
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
import { Axis } from "./axis";
|
|
1
|
+
import { Axis, AxisParams } from "./axis";
|
|
2
2
|
import { Momentary } from "./momentary";
|
|
3
3
|
import { Input, InputParams } from "../input";
|
|
4
4
|
import { Radians, Degrees, Magnitude, Force } from "../math";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Configuration for an analog joystick and its
|
|
7
|
+
* Configuration for an analog joystick and its component inputs.
|
|
8
8
|
*/
|
|
9
9
|
export interface AnalogParams extends InputParams {
|
|
10
10
|
// Configuration for the input's button
|
|
11
11
|
button?: InputParams;
|
|
12
12
|
|
|
13
13
|
// Configuration for the input's x axis
|
|
14
|
-
x?:
|
|
14
|
+
x?: AxisParams;
|
|
15
15
|
|
|
16
16
|
// Configuration for the input's y axis
|
|
17
|
-
y?:
|
|
17
|
+
y?: AxisParams;
|
|
18
18
|
|
|
19
|
-
//
|
|
20
|
-
threshold?: Magnitude;
|
|
21
|
-
|
|
22
|
-
// Ignore input while magnitude is less than or equal to this value
|
|
19
|
+
// Ignore input of magnitude less than or equal to this value
|
|
23
20
|
deadzone?: Magnitude;
|
|
24
21
|
}
|
|
25
22
|
|
|
@@ -49,13 +46,12 @@ export class Analog extends Input<Analog> {
|
|
|
49
46
|
/**
|
|
50
47
|
* Ignores stick movement below this value (0 to 1).
|
|
51
48
|
*/
|
|
52
|
-
public deadzone:
|
|
49
|
+
public deadzone: Magnitude = 0.05;
|
|
53
50
|
|
|
54
51
|
constructor(params?: AnalogParams) {
|
|
55
52
|
super(params);
|
|
56
|
-
const { button, x, y, deadzone
|
|
53
|
+
const { button, x, y, deadzone } = params || {};
|
|
57
54
|
|
|
58
|
-
if (threshold) this.threshold = threshold;
|
|
59
55
|
if (deadzone) this.deadzone = deadzone;
|
|
60
56
|
this.button = new Momentary({ icon: "3", name: "Button", ...button });
|
|
61
57
|
this.x = new Axis({
|
|
@@ -91,7 +87,7 @@ export class Analog extends Input<Analog> {
|
|
|
91
87
|
* This ignores the deadzone value.
|
|
92
88
|
*/
|
|
93
89
|
public get force(): Force {
|
|
94
|
-
return Math.max(Math.min(Math.hypot(this.x.
|
|
90
|
+
return Math.max(Math.min(Math.hypot(this.x.force, this.y.force), 1), -1);
|
|
95
91
|
}
|
|
96
92
|
|
|
97
93
|
/**
|
|
@@ -107,7 +103,7 @@ export class Analog extends Input<Analog> {
|
|
|
107
103
|
* Returns the stick's angle in radians.
|
|
108
104
|
*/
|
|
109
105
|
public get direction(): Radians {
|
|
110
|
-
return Math.atan2(this.y.
|
|
106
|
+
return Math.atan2(this.y.force, this.x.force);
|
|
111
107
|
}
|
|
112
108
|
|
|
113
109
|
/**
|
package/src/elements/axis.ts
CHANGED
|
@@ -1,18 +1,50 @@
|
|
|
1
|
-
import { Input } from "../input";
|
|
1
|
+
import { Input, InputParams } from "../input";
|
|
2
2
|
import { Force, Magnitude } from "../math";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for an Axis input.
|
|
6
|
+
*/
|
|
7
|
+
export interface AxisParams extends InputParams {
|
|
8
|
+
// Ignore input of magnitude less than or equal to this value
|
|
9
|
+
deadzone?: Magnitude;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Represents a simple ranged input. For example, one axis of an analog
|
|
14
|
+
* joystick or touchpad, the pull of a trigger, or the movement of a gyroscope.
|
|
15
|
+
*/
|
|
4
16
|
export class Axis extends Input<Force> {
|
|
5
17
|
public state: Force = 0;
|
|
6
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Ignores inputs of magnitude less than this value (0 to 1).
|
|
21
|
+
*/
|
|
22
|
+
public deadzone: Magnitude = 0.05;
|
|
23
|
+
|
|
24
|
+
constructor(params?: AxisParams) {
|
|
25
|
+
super(params);
|
|
26
|
+
const { deadzone } = params || {};
|
|
27
|
+
|
|
28
|
+
if (deadzone) this.deadzone = deadzone;
|
|
29
|
+
}
|
|
30
|
+
|
|
7
31
|
public get active(): boolean {
|
|
8
|
-
return Math.abs(this.state) > this.
|
|
32
|
+
return Math.abs(this.state) > this.deadzone;
|
|
9
33
|
}
|
|
10
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Returns the axis position, ignoring the deadzone value.
|
|
37
|
+
*/
|
|
11
38
|
public get force(): Force {
|
|
12
39
|
return this.active ? this.state : 0;
|
|
13
40
|
}
|
|
14
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Returns an absolute axis position.
|
|
44
|
+
*/
|
|
15
45
|
public get magnitude(): Magnitude {
|
|
16
|
-
|
|
46
|
+
const magnitude = Math.abs(this.force);
|
|
47
|
+
if (magnitude < this.deadzone) return 0;
|
|
48
|
+
return (magnitude - this.deadzone) / (1 - this.deadzone);
|
|
17
49
|
}
|
|
18
50
|
}
|
package/src/elements/unisense.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Trigger } from "./trigger";
|
|
2
2
|
import { Momentary } from "./momentary";
|
|
3
|
-
import { Analog } from "./analog";
|
|
3
|
+
import { Analog, AnalogParams } from "./analog";
|
|
4
4
|
import { Haptic } from "../haptics";
|
|
5
5
|
import { Input, InputParams } from "../input";
|
|
6
6
|
|
|
7
7
|
export interface UnisenseParams extends InputParams {
|
|
8
8
|
trigger?: InputParams;
|
|
9
9
|
bumper?: InputParams;
|
|
10
|
-
analog?:
|
|
10
|
+
analog?: AnalogParams;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
// The name "Dualsense" clearly implies a composition of two Unisense elements 🤔
|
|
@@ -34,6 +34,7 @@ export class Unisense extends Input<Unisense> {
|
|
|
34
34
|
icon: "⨁",
|
|
35
35
|
name: "Analog",
|
|
36
36
|
threshold: 1 / 128,
|
|
37
|
+
deadzone: 8 / 128,
|
|
37
38
|
...analog,
|
|
38
39
|
});
|
|
39
40
|
this.haptic = new Haptic();
|