This repository was archived by the owner on Dec 2, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEncoder.ts
More file actions
122 lines (107 loc) · 3.22 KB
/
Encoder.ts
File metadata and controls
122 lines (107 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* The encoder is used to configure the dial and display segment on an SD+.
* It is completely optional.
*/
export class Encoder {
/**
* Default background for the touch display slot
* @type {string}
*/
public background?: string;
/**
* Default icon for the Property Inspector, dial stack and layout. Falls back
* to the Action List Icon
*
* @type {string}
*/
public icon?: string;
/**
* Either a built-in layout (string) or a path to a JSON file that describes
* a custom layout. Can be changed with `setFeedbackLayout` event.
* @see Layout
* @type {string}
*/
public layout?: string;
/**
* The color used as the background of the Dial Stack
* @type {string}
*/
public stackColor?: string;
/**
* Part of TriggerDescription. Describes the action performed on rotation of
* the dial
* @type {string}
*/
public onRotateDescription?: string;
/**
* Part of TriggerDescription. Describes the action performed on pressing of
* the dial
* @type {string}
*/
public onPushDescription?: string;
/**
* Part of TriggerDescription. Describes the action performed on touching the
* display pad
* @type {string}
*/
public onTouchDescription?: string;
/**
* Part of TriggerDescription. Describes the action performed on long pressing
* the display pad
* @type {string}
*/
public onLongTouchDescription?: string;
public toManifest(): Record<string, unknown> {
const snippet: Record<string, unknown> = {
background: this.background,
Icon: this.icon,
layout: this.layout,
StackColor: this.stackColor,
TriggerDescription: {
Rotate: this.onRotateDescription,
Push: this.onPushDescription,
Touch: this.onTouchDescription,
LongTouch: this.onLongTouchDescription,
},
};
const optionals: [string, unknown, unknown][] = [
["background", this.background, this.background],
["Icon", this.icon, this.icon],
["layout", this.layout, this.layout],
["StackColor", this.stackColor, this.stackColor],
["StackColor", this.stackColor, this.stackColor],
[
"TriggerDescription",
this.onRotateDescription ||
this.onPushDescription ||
this.onTouchDescription ||
this.onLongTouchDescription,
this.buildTriggerDescription(),
],
];
this.evaluateOptionalValues(optionals, snippet);
return snippet;
}
private buildTriggerDescription() {
const snippet: Record<string, unknown> = {};
const optionals: [string, unknown, unknown][] = [
["Rotate", this.onRotateDescription, this.onRotateDescription],
["Push", this.onPushDescription, this.onPushDescription],
["Touch", this.onTouchDescription, this.onTouchDescription],
["LongTouch", this.onLongTouchDescription, this.onLongTouchDescription],
];
this.evaluateOptionalValues(optionals, snippet);
return snippet;
}
private evaluateOptionalValues(
optionals: [string, unknown, unknown][],
object: Record<string, unknown>,
): Record<string, unknown> {
optionals.forEach(([prop, condition, value]) => {
if (condition) {
object[prop] = value;
}
});
return object;
}
}