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.
- package/README.md +1 -1
- package/dist/elements/analog.d.ts +46 -3
- package/dist/elements/analog.d.ts.map +1 -1
- package/dist/elements/analog.js +41 -14
- package/dist/elements/analog.js.map +1 -1
- package/dist/elements/axis.js +3 -3
- package/dist/elements/axis.js.map +1 -1
- package/dist/elements/unisense.js +1 -1
- package/dist/elements/unisense.js.map +1 -1
- package/dist/input.d.ts +27 -0
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js +9 -3
- package/dist/input.js.map +1 -1
- package/docs/Analog.md +81 -90
- package/docs/AnalogParams.md +7 -7
- package/docs/Axis.md +72 -79
- package/docs/Brightness.md +8 -8
- package/docs/CommandScopeA.md +16 -16
- package/docs/CommandScopeB.md +14 -14
- package/docs/Dpad.md +74 -81
- package/docs/DpadParams.md +8 -8
- package/docs/DualSenseCommand.md +45 -45
- package/docs/Dualsense.md +83 -90
- package/docs/DualsenseHID.md +47 -42
- package/docs/DualsenseHIDState.md +41 -41
- package/docs/DualsenseParams.md +17 -17
- package/docs/Exports.md +18 -21
- package/docs/Haptic.md +1 -1
- package/docs/Home.md +29 -31
- package/docs/Indicator.md +2 -2
- package/docs/Input.md +70 -79
- package/docs/InputId.md +84 -84
- package/docs/InputParams.md +4 -4
- package/docs/LedOptions.md +10 -10
- package/docs/Momentary.md +70 -77
- package/docs/Motion.md +2 -2
- package/docs/Mute.md +71 -89
- package/docs/PlayerID.md +12 -12
- package/docs/PulseOptions.md +8 -8
- package/docs/Touchpad.md +120 -94
- package/docs/Trigger.md +75 -82
- package/docs/TriggerMode.md +22 -22
- package/docs/Unisense.md +74 -81
- package/docs/UnisenseParams.md +7 -7
- package/package.json +2 -2
- package/src/elements/analog.spec.ts +17 -0
- package/src/elements/analog.ts +56 -18
- package/src/elements/axis.spec.ts +31 -0
- package/src/elements/axis.ts +3 -3
- package/src/elements/unisense.ts +1 -1
- package/src/input.ts +27 -9
- package/docs/Increment.md +0 -1554
- package/docs/Touch.md +0 -1781
package/src/elements/analog.ts
CHANGED
|
@@ -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
|
-
|
|
46
|
+
x || { icon: "↔", name: "X", threshold: threshold || 0.07 }
|
|
36
47
|
);
|
|
37
48
|
this.y = new Axis(
|
|
38
|
-
|
|
49
|
+
y || { icon: "↕", name: "Y", threshold: threshold || 0.07 }
|
|
39
50
|
);
|
|
40
51
|
}
|
|
41
52
|
|
|
42
|
-
|
|
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.
|
|
57
|
+
return this.x.active || this.y.active || this.button.active;
|
|
45
58
|
}
|
|
46
59
|
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
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.
|
|
80
|
+
return Math.abs(this.force);
|
|
55
81
|
}
|
|
56
82
|
|
|
57
|
-
|
|
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
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Alias for `.direction`
|
|
92
|
+
*/
|
|
63
93
|
public get radians(): Radians {
|
|
64
94
|
return this.direction;
|
|
65
95
|
}
|
|
66
96
|
|
|
67
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Alias for `.direction`
|
|
99
|
+
*/
|
|
68
100
|
public get angle(): Radians {
|
|
69
101
|
return this.direction;
|
|
70
102
|
}
|
|
71
103
|
|
|
72
|
-
|
|
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
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Alias for `.directionDegrees`.
|
|
113
|
+
*/
|
|
78
114
|
public get degrees(): Degrees {
|
|
79
115
|
return this.directionDegrees;
|
|
80
116
|
}
|
|
81
117
|
|
|
82
|
-
|
|
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
|
});
|
package/src/elements/axis.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
16
|
+
return Math.abs(this.force);
|
|
17
17
|
}
|
|
18
18
|
}
|
package/src/elements/unisense.ts
CHANGED
|
@@ -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:
|
|
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
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Timestamp of the last received input that changed the state.
|
|
62
|
+
*/
|
|
61
63
|
public lastChange: number = Date.now();
|
|
62
64
|
|
|
63
|
-
|
|
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
|
-
|
|
70
|
+
/**
|
|
71
|
+
* For numeric inputs, ignore state changes smaller than this threshold.
|
|
72
|
+
*/
|
|
67
73
|
public threshold: number = 0;
|
|
68
74
|
|
|
69
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Provide the type and default value for the input.
|
|
77
|
+
*/
|
|
70
78
|
public abstract state: Type;
|
|
71
79
|
|
|
72
|
-
|
|
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
|
-
|
|
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
|
-
|
|
165
|
+
/**
|
|
166
|
+
* The name of this input.
|
|
167
|
+
*/
|
|
154
168
|
readonly [InputName]: string;
|
|
155
169
|
|
|
156
|
-
|
|
170
|
+
/**
|
|
171
|
+
* A short name for this input
|
|
172
|
+
*/
|
|
157
173
|
readonly [InputIcon]: string;
|
|
158
174
|
|
|
159
|
-
|
|
175
|
+
/**
|
|
176
|
+
* The Input's parent, if any
|
|
177
|
+
*/
|
|
160
178
|
[InputParent]?: Input<unknown>;
|
|
161
179
|
|
|
162
180
|
[InputChildless]: boolean = true;
|