-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeckSettings.js
86 lines (76 loc) · 1.92 KB
/
DeckSettings.js
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
"use strict";
module.exports = class DeckSettings {
constructor(config, streamDeck) {
this.streamDeck = streamDeck;
this.brightness = true;
this.folders = {};
this.currentFolder = "root";
this.config = config;
this.buildFolder("root", config);
}
buildFolder(folderName, config) {
if (
!config.folders[folderName] ||
this.folders[folderName]
) {
// folder does not exist in config OR folder is already built
return;
}
this.folders[folderName] = new Array(15)
.fill({})
.map((item, index) => {
const newBtn = { id: index };
const configBtn = config.folders[folderName].find(
x => x.id === index
);
if (!configBtn) {
return newBtn;
}
Object.entries(configBtn).forEach(
([key, value]) => {
newBtn[key] = value;
}
);
return newBtn;
});
}
findButton(i) {
return this.folders[this.currentFolder][i];
}
getButtonArray() {
return this.folders[this.currentFolder];
}
toggleBrightness() {
this.brightness
? this.streamDeck.setBrightness(0)
: this.streamDeck.setBrightness(100);
this.brightness = !this.brightness;
}
paintButtons() {
const buttons = this.getButtonArray();
if (buttons) {
buttons.forEach(button => {
if (button.image) {
return this.streamDeck.fillImageFromFile(
button.id,
button.image
);
}
if (button.color) {
return this.streamDeck.fillColor(
button.id,
...button.color
);
}
this.streamDeck.fillColor(button.id, 0, 0, 0);
});
console.log("keys painted");
}
}
switchFolder(folderName) {
console.log("switching folder");
this.currentFolder = folderName;
this.buildFolder(folderName, this.config);
this.paintButtons();
}
};