dualsense-ts 3.0.0 → 3.1.4
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/comparators.d.ts +1 -1
- package/dist/comparators.d.ts.map +1 -1
- package/dist/comparators.js +3 -2
- package/dist/comparators.js.map +1 -1
- package/dist/elements/analog.d.ts +11 -6
- package/dist/elements/analog.d.ts.map +1 -1
- package/dist/elements/analog.js +18 -10
- 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/touch.d.ts +1 -0
- package/dist/elements/touch.d.ts.map +1 -1
- package/dist/elements/touch.js +1 -0
- package/dist/elements/touch.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/dist/input.d.ts +5 -0
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js +25 -13
- package/dist/input.js.map +1 -1
- package/package.json +1 -1
- package/src/comparators.ts +5 -1
- package/src/elements/analog.spec.ts +2 -15
- package/src/elements/analog.ts +28 -15
- package/src/elements/axis.ts +35 -3
- package/src/elements/touch.ts +1 -0
- package/src/elements/unisense.ts +3 -2
- package/src/input.ts +14 -12
package/dist/comparators.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare function VirtualComparator(): boolean;
|
|
|
5
5
|
/**
|
|
6
6
|
* Input state change checker that considers a numeric threshold.
|
|
7
7
|
*/
|
|
8
|
-
export declare function ThresholdComparator(threshold: number, state: unknown, newState: unknown): boolean;
|
|
8
|
+
export declare function ThresholdComparator(threshold: number, deadzone: number, state: unknown, newState: unknown): boolean;
|
|
9
9
|
/**
|
|
10
10
|
* Input state change checker for most values.
|
|
11
11
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comparators.d.ts","sourceRoot":"","sources":["../src/comparators.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,OAAO,GAChB,OAAO,
|
|
1
|
+
{"version":3,"file":"comparators.d.ts","sourceRoot":"","sources":["../src/comparators.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,OAAO,GAChB,OAAO,CAOT;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAE1E"}
|
package/dist/comparators.js
CHANGED
|
@@ -11,10 +11,11 @@ exports.VirtualComparator = VirtualComparator;
|
|
|
11
11
|
/**
|
|
12
12
|
* Input state change checker that considers a numeric threshold.
|
|
13
13
|
*/
|
|
14
|
-
function ThresholdComparator(threshold, state, newState) {
|
|
14
|
+
function ThresholdComparator(threshold, deadzone, state, newState) {
|
|
15
15
|
if (typeof state !== "number" || typeof newState !== "number")
|
|
16
16
|
throw new Error("Bad threshold comparison");
|
|
17
|
-
return Math.abs(state - newState) > threshold
|
|
17
|
+
return (Math.abs(state - newState) > threshold &&
|
|
18
|
+
(Math.abs(newState) > deadzone || Math.abs(state) > deadzone));
|
|
18
19
|
}
|
|
19
20
|
exports.ThresholdComparator = ThresholdComparator;
|
|
20
21
|
/**
|
package/dist/comparators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comparators.js","sourceRoot":"","sources":["../src/comparators.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,IAAI,CAAC;AACd,CAAC;AAFD,8CAEC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CACjC,SAAiB,EACjB,KAAc,EACd,QAAiB;IAEjB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAC3D,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAC9C,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,QAAQ,CAAC,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"comparators.js","sourceRoot":"","sources":["../src/comparators.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,IAAI,CAAC;AACd,CAAC;AAFD,8CAEC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CACjC,SAAiB,EACjB,QAAgB,EAChB,KAAc,EACd,QAAiB;IAEjB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAC3D,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAC9C,OAAO,CACL,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,QAAQ,CAAC,GAAG,SAAS;QACtC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,QAAQ,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,CAC9D,CAAC;AACJ,CAAC;AAZD,kDAYC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,KAAc,EAAE,QAAiB;IAC/D,OAAO,KAAK,KAAK,QAAQ,CAAC;AAC5B,CAAC;AAFD,0CAEC"}
|
|
@@ -1,15 +1,15 @@
|
|
|
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
|
-
|
|
10
|
+
x?: AxisParams;
|
|
11
|
+
y?: AxisParams;
|
|
12
|
+
deadzone?: Magnitude;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Represents an analog joystick.
|
|
@@ -33,6 +33,10 @@ export declare class Analog extends Input<Analog> {
|
|
|
33
33
|
* Button triggered by pressing the stick.
|
|
34
34
|
*/
|
|
35
35
|
readonly button: Momentary;
|
|
36
|
+
/**
|
|
37
|
+
* Ignores stick movement below this value (0 to 1).
|
|
38
|
+
*/
|
|
39
|
+
deadzone: Magnitude;
|
|
36
40
|
constructor(params?: AnalogParams);
|
|
37
41
|
/**
|
|
38
42
|
* Returns true if the stick is away from the idle position, or the button is pressed.
|
|
@@ -46,7 +50,8 @@ export declare class Analog extends Input<Analog> {
|
|
|
46
50
|
magnitude: Magnitude;
|
|
47
51
|
};
|
|
48
52
|
/**
|
|
49
|
-
* Returns
|
|
53
|
+
* Returns a force from the stick's position.
|
|
54
|
+
* This ignores the deadzone value.
|
|
50
55
|
*/
|
|
51
56
|
get force(): Force;
|
|
52
57
|
/**
|
|
@@ -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,CA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CACF"}
|
package/dist/elements/analog.js
CHANGED
|
@@ -16,18 +16,24 @@ class Analog extends input_1.Input {
|
|
|
16
16
|
constructor(params) {
|
|
17
17
|
super(params);
|
|
18
18
|
this.state = this;
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Ignores stick movement below this value (0 to 1).
|
|
21
|
+
*/
|
|
22
|
+
this.deadzone = 0.05;
|
|
23
|
+
const { button, x, y, deadzone } = params || {};
|
|
24
|
+
if (deadzone)
|
|
25
|
+
this.deadzone = deadzone;
|
|
20
26
|
this.button = new momentary_1.Momentary({ icon: "3", name: "Button", ...button });
|
|
21
27
|
this.x = new axis_1.Axis({
|
|
22
28
|
icon: "↔",
|
|
23
29
|
name: "X",
|
|
24
|
-
|
|
30
|
+
...params,
|
|
25
31
|
...x,
|
|
26
32
|
});
|
|
27
33
|
this.y = new axis_1.Axis({
|
|
28
34
|
icon: "↕",
|
|
29
35
|
name: "Y",
|
|
30
|
-
|
|
36
|
+
...params,
|
|
31
37
|
...y,
|
|
32
38
|
});
|
|
33
39
|
}
|
|
@@ -35,7 +41,7 @@ class Analog extends input_1.Input {
|
|
|
35
41
|
* Returns true if the stick is away from the idle position, or the button is pressed.
|
|
36
42
|
*/
|
|
37
43
|
get active() {
|
|
38
|
-
return this.
|
|
44
|
+
return this.magnitude > 0 || this.button.active;
|
|
39
45
|
}
|
|
40
46
|
/**
|
|
41
47
|
* Returns a direction and magnitude representing the stick's position.
|
|
@@ -44,24 +50,26 @@ class Analog extends input_1.Input {
|
|
|
44
50
|
return { direction: this.direction, magnitude: this.magnitude };
|
|
45
51
|
}
|
|
46
52
|
/**
|
|
47
|
-
* Returns
|
|
53
|
+
* Returns a force from the stick's position.
|
|
54
|
+
* This ignores the deadzone value.
|
|
48
55
|
*/
|
|
49
56
|
get force() {
|
|
50
|
-
return this.
|
|
51
|
-
? Math.max(Math.min(Math.hypot(this.x.state, this.y.state), 1), -1)
|
|
52
|
-
: 0;
|
|
57
|
+
return Math.max(Math.min(Math.hypot(this.x.force, this.y.force), 1), -1);
|
|
53
58
|
}
|
|
54
59
|
/**
|
|
55
60
|
* Returns a magnitude from the stick's position.
|
|
56
61
|
*/
|
|
57
62
|
get magnitude() {
|
|
58
|
-
|
|
63
|
+
const magnitude = Math.abs(this.force);
|
|
64
|
+
if (magnitude < this.deadzone)
|
|
65
|
+
return 0;
|
|
66
|
+
return (magnitude - this.deadzone) / (1 - this.deadzone);
|
|
59
67
|
}
|
|
60
68
|
/**
|
|
61
69
|
* Returns the stick's angle in radians.
|
|
62
70
|
*/
|
|
63
71
|
get direction() {
|
|
64
|
-
return Math.atan2(this.y.
|
|
72
|
+
return Math.atan2(this.y.force, this.x.force);
|
|
65
73
|
}
|
|
66
74
|
/**
|
|
67
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,IAA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;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"}
|
package/dist/elements/touch.d.ts
CHANGED
|
@@ -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;
|
|
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"}
|
package/dist/elements/touch.js
CHANGED
|
@@ -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;
|
|
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"}
|
|
@@ -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/dist/input.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface InputParams {
|
|
|
4
4
|
name?: string;
|
|
5
5
|
icon?: string;
|
|
6
6
|
threshold?: number;
|
|
7
|
+
deadzone?: number;
|
|
7
8
|
}
|
|
8
9
|
export declare type InputChangeType = "change" | "press" | "release";
|
|
9
10
|
export declare type InputEventType = InputChangeType | "input";
|
|
@@ -34,6 +35,10 @@ export declare abstract class Input<Type> implements AsyncIterator<Input<Type>>
|
|
|
34
35
|
* For numeric inputs, ignore state changes smaller than this threshold.
|
|
35
36
|
*/
|
|
36
37
|
threshold: number;
|
|
38
|
+
/**
|
|
39
|
+
* For numeric inputs, ignore states smaller than this deadzone.
|
|
40
|
+
*/
|
|
41
|
+
deadzone: number;
|
|
37
42
|
/**
|
|
38
43
|
* Provide the type and default value for the input.
|
|
39
44
|
*/
|
package/dist/input.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAO/B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAO/B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,oBAAY,eAAe,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;AAC7D,oBAAY,cAAc,GAAG,eAAe,GAAG,OAAO,CAAC;AAEvD,oBAAY,aAAa,CAAC,QAAQ,IAAI,CACpC,KAAK,EAAE,QAAQ,E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package/dist/input.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a, _b, _c, _d;
|
|
2
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Input = exports.InputIcon = exports.InputName = exports.InputSet = exports.InputChanged = exports.InputSetComparator = void 0;
|
|
5
5
|
const comparators_1 = require("./comparators");
|
|
@@ -30,6 +30,10 @@ class Input {
|
|
|
30
30
|
* For numeric inputs, ignore state changes smaller than this threshold.
|
|
31
31
|
*/
|
|
32
32
|
this.threshold = 0;
|
|
33
|
+
/**
|
|
34
|
+
* For numeric inputs, ignore states smaller than this deadzone.
|
|
35
|
+
*/
|
|
36
|
+
this.deadzone = 0;
|
|
33
37
|
/**
|
|
34
38
|
* Stores event listeners.
|
|
35
39
|
*/
|
|
@@ -42,19 +46,27 @@ class Input {
|
|
|
42
46
|
* Returns true if the provided state is worth an event
|
|
43
47
|
*/
|
|
44
48
|
this[_c] = comparators_1.BasicComparator;
|
|
49
|
+
/**
|
|
50
|
+
* The name of this input.
|
|
51
|
+
*/
|
|
52
|
+
this[_d] = 'Unknown Input';
|
|
53
|
+
/**
|
|
54
|
+
* A short name for this input.
|
|
55
|
+
*/
|
|
56
|
+
this[_e] = '???';
|
|
45
57
|
/**
|
|
46
58
|
* Other Inputs that contain this one.
|
|
47
59
|
*/
|
|
48
|
-
this[
|
|
49
|
-
const { name, icon, threshold } = {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
this[_f] = new Set();
|
|
61
|
+
const { name, icon, threshold, deadzone } = params || {};
|
|
62
|
+
if (name)
|
|
63
|
+
this[exports.InputName] = name;
|
|
64
|
+
if (icon)
|
|
65
|
+
this[exports.InputIcon] = icon;
|
|
66
|
+
if (threshold)
|
|
67
|
+
this.threshold = threshold;
|
|
68
|
+
if (deadzone)
|
|
69
|
+
this.deadzone = deadzone;
|
|
58
70
|
setTimeout(() => {
|
|
59
71
|
this[exports.InputSetComparator]();
|
|
60
72
|
Object.values(this).forEach((value) => {
|
|
@@ -166,7 +178,7 @@ class Input {
|
|
|
166
178
|
/**
|
|
167
179
|
* Links Inputs to bubble up events.
|
|
168
180
|
*/
|
|
169
|
-
[(_d = InputParents, InputAdopt)](parent) {
|
|
181
|
+
[(_d = exports.InputName, _e = exports.InputIcon, _f = InputParents, InputAdopt)](parent) {
|
|
170
182
|
this[InputParents].add(parent);
|
|
171
183
|
}
|
|
172
184
|
/**
|
|
@@ -174,7 +186,7 @@ class Input {
|
|
|
174
186
|
*/
|
|
175
187
|
[exports.InputSetComparator]() {
|
|
176
188
|
if (typeof this.state === "number") {
|
|
177
|
-
this[InputComparator] = comparators_1.ThresholdComparator.bind(this, this.threshold);
|
|
189
|
+
this[InputComparator] = comparators_1.ThresholdComparator.bind(this, this.threshold, this.deadzone);
|
|
178
190
|
}
|
|
179
191
|
else if (this.state instanceof Input) {
|
|
180
192
|
this[InputComparator] = comparators_1.VirtualComparator;
|
package/dist/input.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.js","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":";;;;AACA,+CAIuB;
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":";;;;AACA,+CAIuB;AAmBvB;;GAEG;AAEU,QAAA,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAClD,QAAA,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AACtC,QAAA,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC9B,QAAA,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAChC,QAAA,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAE7C;;GAEG;AAEH,MAA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,CAAC,0BAAkB,CAAC;QAClB,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE;YAClC,IAAI,CAAC,eAAe,CAAC,GAAG,iCAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;SACvF;aAAM,IAAI,IAAI,CAAC,KAAK,YAAY,KAAK,EAAE;YACtC,IAAI,CAAC,eAAe,CAAC,GAAG,+BAAiB,CAAC;SAC3C;aAAM;YACL,IAAI,CAAC,eAAe,CAAC,GAAG,6BAAe,CAAC;SACzC;IACH,CAAC;IAED;;OAEG;IACH,CAAC,gBAAQ,CAAC,CAAC,KAAW;QACpB,IAAI,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE;YAC5C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;YACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAC1B,IAAI,OAAO,KAAK,KAAK,SAAS;gBAC5B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;SAChD;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC3B,CAAC;CACF;AA3ND,sBA2NC"}
|
package/package.json
CHANGED
package/src/comparators.ts
CHANGED
|
@@ -10,12 +10,16 @@ export function VirtualComparator(): boolean {
|
|
|
10
10
|
*/
|
|
11
11
|
export function ThresholdComparator(
|
|
12
12
|
threshold: number,
|
|
13
|
+
deadzone: number,
|
|
13
14
|
state: unknown,
|
|
14
15
|
newState: unknown
|
|
15
16
|
): boolean {
|
|
16
17
|
if (typeof state !== "number" || typeof newState !== "number")
|
|
17
18
|
throw new Error("Bad threshold comparison");
|
|
18
|
-
return
|
|
19
|
+
return (
|
|
20
|
+
Math.abs(state - newState) > threshold &&
|
|
21
|
+
(Math.abs(newState) > deadzone || Math.abs(state) > deadzone)
|
|
22
|
+
);
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
/**
|
|
@@ -25,8 +25,8 @@ describe("Analog", () => {
|
|
|
25
25
|
expect(analog.active).toEqual(false);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
it("should utilize `
|
|
29
|
-
const analog = new Analog({
|
|
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);
|
package/src/elements/analog.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
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
|
+
// Configuration for the input's button
|
|
10
11
|
button?: InputParams;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
// Configuration for the input's x axis
|
|
14
|
+
x?: AxisParams;
|
|
15
|
+
|
|
16
|
+
// Configuration for the input's y axis
|
|
17
|
+
y?: AxisParams;
|
|
18
|
+
|
|
19
|
+
// Ignore input of magnitude less than or equal to this value
|
|
20
|
+
deadzone?: Magnitude;
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
/**
|
|
@@ -36,22 +43,27 @@ export class Analog extends Input<Analog> {
|
|
|
36
43
|
* Button triggered by pressing the stick.
|
|
37
44
|
*/
|
|
38
45
|
public readonly button: Momentary;
|
|
46
|
+
/**
|
|
47
|
+
* Ignores stick movement below this value (0 to 1).
|
|
48
|
+
*/
|
|
49
|
+
public deadzone: Magnitude = 0.05;
|
|
39
50
|
|
|
40
51
|
constructor(params?: AnalogParams) {
|
|
41
52
|
super(params);
|
|
42
|
-
const { button, x, y,
|
|
53
|
+
const { button, x, y, deadzone } = params || {};
|
|
43
54
|
|
|
55
|
+
if (deadzone) this.deadzone = deadzone;
|
|
44
56
|
this.button = new Momentary({ icon: "3", name: "Button", ...button });
|
|
45
57
|
this.x = new Axis({
|
|
46
58
|
icon: "↔",
|
|
47
59
|
name: "X",
|
|
48
|
-
|
|
60
|
+
...params,
|
|
49
61
|
...x,
|
|
50
62
|
});
|
|
51
63
|
this.y = new Axis({
|
|
52
64
|
icon: "↕",
|
|
53
65
|
name: "Y",
|
|
54
|
-
|
|
66
|
+
...params,
|
|
55
67
|
...y,
|
|
56
68
|
});
|
|
57
69
|
}
|
|
@@ -60,7 +72,7 @@ export class Analog extends Input<Analog> {
|
|
|
60
72
|
* Returns true if the stick is away from the idle position, or the button is pressed.
|
|
61
73
|
*/
|
|
62
74
|
public get active(): boolean {
|
|
63
|
-
return this.
|
|
75
|
+
return this.magnitude > 0 || this.button.active;
|
|
64
76
|
}
|
|
65
77
|
|
|
66
78
|
/**
|
|
@@ -71,26 +83,27 @@ export class Analog extends Input<Analog> {
|
|
|
71
83
|
}
|
|
72
84
|
|
|
73
85
|
/**
|
|
74
|
-
* Returns
|
|
86
|
+
* Returns a force from the stick's position.
|
|
87
|
+
* This ignores the deadzone value.
|
|
75
88
|
*/
|
|
76
89
|
public get force(): Force {
|
|
77
|
-
return this.
|
|
78
|
-
? Math.max(Math.min(Math.hypot(this.x.state, this.y.state), 1), -1)
|
|
79
|
-
: 0;
|
|
90
|
+
return Math.max(Math.min(Math.hypot(this.x.force, this.y.force), 1), -1);
|
|
80
91
|
}
|
|
81
92
|
|
|
82
93
|
/**
|
|
83
94
|
* Returns a magnitude from the stick's position.
|
|
84
95
|
*/
|
|
85
96
|
public get magnitude(): Magnitude {
|
|
86
|
-
|
|
97
|
+
const magnitude = Math.abs(this.force);
|
|
98
|
+
if (magnitude < this.deadzone) return 0;
|
|
99
|
+
return (magnitude - this.deadzone) / (1 - this.deadzone);
|
|
87
100
|
}
|
|
88
101
|
|
|
89
102
|
/**
|
|
90
103
|
* Returns the stick's angle in radians.
|
|
91
104
|
*/
|
|
92
105
|
public get direction(): Radians {
|
|
93
|
-
return Math.atan2(this.y.
|
|
106
|
+
return Math.atan2(this.y.force, this.x.force);
|
|
94
107
|
}
|
|
95
108
|
|
|
96
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/touch.ts
CHANGED
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();
|
package/src/input.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface InputParams {
|
|
|
11
11
|
name?: string;
|
|
12
12
|
icon?: string;
|
|
13
13
|
threshold?: number;
|
|
14
|
+
deadzone?: number;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export type InputChangeType = "change" | "press" | "release";
|
|
@@ -53,6 +54,11 @@ export abstract class Input<Type> implements AsyncIterator<Input<Type>> {
|
|
|
53
54
|
*/
|
|
54
55
|
public threshold: number = 0;
|
|
55
56
|
|
|
57
|
+
/**
|
|
58
|
+
* For numeric inputs, ignore states smaller than this deadzone.
|
|
59
|
+
*/
|
|
60
|
+
public deadzone: number = 0;
|
|
61
|
+
|
|
56
62
|
/**
|
|
57
63
|
* Provide the type and default value for the input.
|
|
58
64
|
*/
|
|
@@ -69,16 +75,12 @@ export abstract class Input<Type> implements AsyncIterator<Input<Type>> {
|
|
|
69
75
|
private [InputOnces] = new Map<InputChangeType, InputCallback<this>[]>();
|
|
70
76
|
|
|
71
77
|
constructor(params: InputParams = {}) {
|
|
72
|
-
const { name, icon, threshold } = {
|
|
73
|
-
icon: "???",
|
|
74
|
-
name: "Nameless Input",
|
|
75
|
-
threshold: 0,
|
|
76
|
-
...params,
|
|
77
|
-
};
|
|
78
|
+
const { name, icon, threshold, deadzone } = params || {}
|
|
78
79
|
|
|
79
|
-
this[InputName] = name;
|
|
80
|
-
this[InputIcon] = icon;
|
|
81
|
-
this.threshold = threshold;
|
|
80
|
+
if (name) this[InputName] = name;
|
|
81
|
+
if (icon) this[InputIcon] = icon;
|
|
82
|
+
if (threshold) this.threshold = threshold;
|
|
83
|
+
if (deadzone) this.deadzone = deadzone;
|
|
82
84
|
|
|
83
85
|
setTimeout(() => {
|
|
84
86
|
this[InputSetComparator]();
|
|
@@ -219,12 +221,12 @@ export abstract class Input<Type> implements AsyncIterator<Input<Type>> {
|
|
|
219
221
|
/**
|
|
220
222
|
* The name of this input.
|
|
221
223
|
*/
|
|
222
|
-
readonly [InputName]: string;
|
|
224
|
+
readonly [InputName]: string = 'Unknown Input';
|
|
223
225
|
|
|
224
226
|
/**
|
|
225
227
|
* A short name for this input.
|
|
226
228
|
*/
|
|
227
|
-
readonly [InputIcon]: string;
|
|
229
|
+
readonly [InputIcon]: string = '???';
|
|
228
230
|
|
|
229
231
|
/**
|
|
230
232
|
* Other Inputs that contain this one.
|
|
@@ -243,7 +245,7 @@ export abstract class Input<Type> implements AsyncIterator<Input<Type>> {
|
|
|
243
245
|
*/
|
|
244
246
|
[InputSetComparator](): void {
|
|
245
247
|
if (typeof this.state === "number") {
|
|
246
|
-
this[InputComparator] = ThresholdComparator.bind(this, this.threshold);
|
|
248
|
+
this[InputComparator] = ThresholdComparator.bind(this, this.threshold, this.deadzone);
|
|
247
249
|
} else if (this.state instanceof Input) {
|
|
248
250
|
this[InputComparator] = VirtualComparator;
|
|
249
251
|
} else {
|