-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.js
1322 lines (1222 loc) · 59.4 KB
/
classes.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const dictionary = require('./dictionary.js');
const {
app,
BrowserWindow,
remote,
ipcRenderer,
ipcMain,
webContents
} = require('electron');
var fs = require('fs');
//var SerialPort = require('serialport');
var notification = require('./notification.js');
const url = require('url');
const path = require('path');
const {
callbackify
} = require('util');
/////////////////////////////////////////////////////////////////// BASE CLASSES
class Mode {
constructor(Name, Value) {
this.Name = Name;
this.Value = Value;
}
}
class Color {
constructor(Name, Value) {
this.Name = Name;
this.Value = Value;
this.returnColor = () => {
if (this.Value != "") {
var result = this.Value.substring(4, this.Value.length - 1).replace(/\s/g, '');
return result.split(',');
} else {
return ["0", "0", "0"];
}
};
this.fullColorHex = () => {
var colorArray;
var returnString = "#";
if (this.Value != "") {
var result = this.Value.substring(4, this.Value.length - 1).replace(/\s/g, '');
colorArray = result.split(',');
} else {
colorArray = ["0", "0", "0"];
}
for (var i = 0; i < colorArray.length; i++) {
var hex = Number(colorArray[i]).toString(16);
if (hex.length < 2) {
hex = "0" + hex;
}
returnString += hex;
}
return returnString;
};
}
}
/////////////////////////////////////////////////////////////////// GLOBAL VARIABLES
var _GroupList = new dictionary.Dictionary;
var _AssetList = new dictionary.Dictionary;
var _PortList = new dictionary.Dictionary;
var _SocketList = [];
var _CommandList = new dictionary.Dictionary;
var ColorsCustom = new Array(
new Color("Dark Blue", 'rgb(8,44,102)'),
new Color("Red", 'rgb(217,30,24)'),
new Color("Purple", 'rgb(142,63,102)'),
new Color("Yellow", 'rgb(255,239,73)'),
new Color("Green", 'rgb(36,198,91)'),
new Color("Mint Green", 'rgb(51,202,157)'),
new Color("Pink", 'rgb(155,40,123)'),
new Color("Orange", 'rgb(255,84,0)'),
new Color("Light Blue", 'rgb(126,189,195)'),
new Color("Army Green", 'rgb(42,197,98)'),
new Color("Turquoise", 'rgb(3,247,235)')
);
var _ModeList = new Array(
new Mode("Off", 0),
new Mode("Solid", 1),
new Mode("Random Cloudy", 2),
new Mode("Flash", 3),
new Mode("Rainbow Waterfall", 4),
new Mode("Twinkle", 5),
new Mode("Random Twinkle", 6),
new Mode("Random Flash", 7),
new Mode("Theater Chase", 8),
new Mode("Chroma", 9),
new Mode("Fade In", 10),
new Mode("Fade Out", 11),
new Mode("Sudden Flash", 12),
new Mode("Random Breath", 13),
new Mode("Breath", 14),
new Mode("Falling Stars", 15),
new Mode("Xmas Chase", 16),
new Mode("Pong", 17),
new Mode("Waterfall", 18),
new Mode("Lightning", 19),
new Mode("Waves", 20),
new Mode("Levels", 21),
new Mode("Rain", 22),
new Mode("Pause", 23),
new Mode("Sound Sync", 24),
new Mode("Portal", 25),
new Mode("Tree", 26)
);
global.ip = "";
global.objectList = {
_AssetList,
_GroupList,
_PortList,
_SocketList,
_CommandList,
_ModeList,
};
global.colorCustom = {
ColorsCustom
};
/////////////////////////////////////////////////////////////////// PROJECT CLASS
class Project {
constructor() {
//the two only unique vars of the project
this.name = "";
this.folderPath = "";
this.ip = "";
//the filepath arrays (load in this order)
this.commandArray = new Array();
this.groupArray = new Array();
this.assetArray = new Array();
}
importAllOpenObjects() {
//commands first
var commandArray = global.objectList._CommandList.data();
commandArray.forEach(element => {
element.Value.filePath = this.folderPath + "\\" + element.Value.name + ".json";
if (!this.commandArray.some(e => e.Name === element.Value.name)) {
this.commandArray.push({
Name: element.Value.name,
Path: element.Value.filePath
});
}
});
//then groups
var groupArray = global.objectList._GroupList.data();
groupArray.forEach(element => {
element.Value.filePath = this.folderPath + "\\" + element.Value.name + ".json";
if (!this.groupArray.some(e => e.Name === element.Value.name)) {
this.groupArray.push({
Name: element.Key,
Path: element.Value.filePath
});
}
});
//then assets
var assetArray = global.objectList._AssetList.data();
assetArray.forEach(element => {
element.Value.filePath = this.folderPath + "\\" + element.Value.name + ".json";
if (!this.assetArray.some(e => e.Name === element.Value.name)) {
this.assetArray.push({
Name: element.Value.name,
Path: element.Value.filePath
});
}
});
notification.send("NOTICE, ALL OBJECTS IMPORTED", this.name);
}
saveAllProjectObjects(isSync = false) {
//save each object to the folder
this.commandArray.forEach(element => {
var obj = global.objectList._CommandList.findKeyValuePair(element.Name)
if (obj.filePath != undefined) {
if (isSync) {
fs.writeFileSync(obj.filePath, JSON.stringify(obj, null, 1), (err) => {
if (err) throw err;
});
} else {
fs.writeFile(obj.filePath, JSON.stringify(obj, null, 1), (err) => {
if (err) throw err;
});
}
}
});
this.groupArray.forEach(element => {
var obj = global.objectList._GroupList.findKeyValuePair(element.Name)
if (obj.filePath != undefined) {
if (isSync) {
fs.writeFileSync(obj.filePath, JSON.stringify(obj, null, 1), (err) => {
if (err) throw err;
});
} else {
fs.writeFile(obj.filePath, JSON.stringify(obj, null, 1), (err) => {
if (err) throw err;
});
}
}
});
this.assetArray.forEach(element => {
var obj = global.objectList._AssetList.findKeyValuePair(element.Name)
if (obj.filePath != undefined) {
if (isSync) {
fs.writeFileSync(obj.filePath, JSON.stringify(obj, null, 1), (err) => {
if (err) throw err;
});
} else {
fs.writeFile(obj.filePath, JSON.stringify(obj, null, 1), (err) => {
if (err) throw err;
});
}
}
});
//write to the project file
if (isSync) {
fs.writeFileSync(this.folderPath + '\\' + this.name + ".json", JSON.stringify(this, null, 1), (err) => {
if (err) throw err;
});
} else {
fs.writeFile(this.folderPath + '\\' + this.name + ".json", JSON.stringify(this, null, 1), (err) => {
if (err) throw err;
});
}
notification.send("NOTICE, PROJECT SAVED", this.name);
}
openAllProjectObjects() {
//open commands and create them
this.commandArray.forEach(element => {
openedObject = JSON.parse(fs.readFileSync(element.Path));
var openedCommand = Object.assign(new Command, openedObject);
//chuck the asset into the asset list and lode it on the screen
if (global.objectList._CommandList.findKeyValuePair(openedCommand.name) == 0) {
global.objectList._CommandList.addKeyValuePair(openedCommand.name, openedCommand);
openedCommand.createPaneForCommand();
} else {
//say there was an error or the asset was opened
}
});
//then groups
this.groupArray.forEach(element => {
openedObject = JSON.parse(fs.readFileSync(element.Path));
var openedGroup = Object.assign(new Group, openedObject);
//chuck the asset into the asset list and lode it on the screen
if (global.objectList._GroupList.findKeyValuePair(openedGroup.name) == 0) {
global.objectList._GroupList.addKeyValuePair(openedGroup.name, openedGroup);
openedGroup.createPaneForGroup();
} else {
//say there was an error or the asset was opened
}
});
//then assets
this.assetArray.forEach(element => {
openedObject = JSON.parse(fs.readFileSync(element.Path));
var openedAsset = Object.assign(new Asset, openedObject);
openedAsset.protocol = Object.assign(new classes.protocol, openedAsset.protocol);
//chuck the asset into the asset list and lode it on the screen
if (global.objectList._AssetList.findKeyValuePair(openedAsset.name) == 0) {
global.objectList._AssetList.addKeyValuePair(openedAsset.name, openedAsset);
openedAsset.createPaneForAsset();
} else {
//say there was an error or the asset was opened
}
});
//set the title to the projectname
document.title = "Liquid Pixel Hub - " + this.name + " Loaded";
global.ip = this.ip;
notification.send("NOTICE, PROJECT OPENED", this.name);
}
}
/////////////////////////////////////////////////////////////////// PROTOCOL CLASS
class Protocol {
constructor() {
this.type = 2;
this.isConnected = false;
//SERIAL
this.comport = "COM#";
this.baudrate = 9600;
//BLUETOOTH
this.id = null;
//WIFI
this.ip = null;
}
openConnection(callback) {
for (let i = 0; i < global.objectList._SocketList.length; i++) {
if (global.objectList._SocketList[i].ip == this.ip) {
this.isConnected = true;
break;
} else if (i == global.objectList._SocketList.length - 1) {
this.isConnected = false;
break;
}
}
if (global.objectList._SocketList.length == 0) {
this.isConnected = false;
}
callback(this.isConnected);
}
closeConnection() {
}
transmitString(str) {
for (let i = 0; i < global.objectList._SocketList.length; i++) {
if (global.objectList._SocketList[i].ip == this.ip) {
global.objectList._SocketList[i].socket.write(Buffer.from(str));
}
}
}
}
/////////////////////////////////////////////////////////////////// COMMAND CLASS
class Command {
constructor() {
//for the command module not the command message
this.name = "";
this.startDelay = 0;
this.repeatTimes = 0;
this.position = 0;
this.filePath = "";
this.targetArray = new Array();
this.commandArray = new Array();
//this.assetArray = new Array();
//this.groupArray = new Array();
//outdated
//this.cubePosition = 0;
//used in command
// this.type = 0;
// this.color = new Color("Null", 'rgb(0,0,0)');
// this.mode = new Mode("Off", 0);
// this.delay = 0;
// this.debug = 0;
// this.sound = 0;
//actual command message
//this.command = "";
}
//All COMMAND METHODS
setState(status = 0) {
var colorArray = [
'#e35656', //off
'#24c65b', //running
'#f9a12f' //next
];
//get all of the changable objects
var displays = [
document.getElementById(this.name + "CommandPanel").getElementsByClassName("viewableCommandNumber")[0],
document.getElementById(this.name + "CommandButton").getElementsByClassName("rightPanelCommandButtonThumbnail")[0],
document.getElementById(this.name + "CommandHighlightButton").getElementsByClassName("leftPanelCommandButtonThumbnail")[0],
document.getElementById(this.name + "homePanelCommandPanel").getElementsByClassName("HomePanelCommandSummaryState")[0]
];
//change the of all of the static ones
for (var i = 0; i < displays.length; i++) {
//change the color
displays[i].style.backgroundColor = colorArray[status];
}
if (status == 1) {
//then change the master displays
}
}
callEvent(name) {
// a custom event handler that will be called locally from within the assets themselves
switch (name) {
case 'command-previous':
//set state
this.setState(0);
break;
case 'command-sent':
//set state
this.setState(1);
//then set the next in line to up next
for (var i = 0; i < document.getElementsByClassName("viewableCommandNumber").length; i++) {
if (parseInt(document.getElementsByClassName("viewableCommandNumber")[i].innerHTML.substr(1, document.getElementsByClassName("viewableCommandNumber")[i].innerHTML.length), 10) == (this.position + 1)) {
//get the parent and call the set state
global.objectList._CommandList.findKeyValuePair(document.getElementsByClassName("viewableCommandNumber")[i].parentElement.id.replace("CommandPanel", "")).callEvent('command-next')
}
if (parseInt(document.getElementsByClassName("viewableCommandNumber")[i].innerHTML.substr(1, document.getElementsByClassName("viewableCommandNumber")[i].innerHTML.length), 10) == (this.position - 1)) {
global.objectList._CommandList.findKeyValuePair(document.getElementsByClassName("viewableCommandNumber")[i].parentElement.id.replace("CommandPanel", "")).callEvent('command-previous')
}
}
//then send a notification
notification.send("COMMAND " + this.command + " SENT", this.name)
break;
case 'command-next':
//set state
this.setState(2);
break;
default:
// do nothing if it defaults
}
}
sendCommand() {
//update the command itself
this.updateCommand();
//scroll it into view on the command highlight
var elmnt = document.getElementById(this.name + "CommandHighlightButton");
elmnt.scrollIntoView();
if (this.targetArray.length > 0) {
for (var i = 0; i < this.targetArray.length; i++)
{
//figure out if its a group or asset.
if(global.objectList._AssetList.findKeyValuePair(this.targetArray[i]) != 0)
{
//what to do if an asset
//check to see if a command exists for this index
if(this.commandArray[i] != null){
global.objectList._AssetList.findKeyValuePair(this.targetArray[i]).sendCommand(this.commandArray[i]);
}
else{
notification.send(this.targetArray[i].toUpperCase() + " DOES NOT HAVE AN ASSOCIATED COMMAND", this.name)
}
}
else if(global.objectList._GroupList.findKeyValuePair(this.targetArray[i]) != 0)
{
//what to do if a group
//check to see if a command exists for this index
if(this.commandArray[i] != null){
global.objectList._GroupList.findKeyValuePair(this.targetArray[i]).sendCommand(this.commandArray[i]);
}
else{
notification.send(this.targetArray[i].toUpperCase() + " DOES NOT HAVE AN ASSOCIATED COMMAND", this.name)
}
}
else
{
notification.send(this.targetArray[i].toUpperCase() + " ASSET OR GROUP DOES NOT EXIST", this.name)
}
//global.objectList._AssetList.findKeyValuePair(this.assetArray[i]).sendCommand(this.command);
}
}
}
updateCommand() {
//uptade the arrays
var tempCommands = document.getElementById(this.name + "CommandPanel").querySelector('textarea[name="commands"]').value;
if (tempCommands.length != 0) {
//purge spaces
//tempCommands = tempCommands.replace(/\s+/g, '');
//string.split(",")
this.commandArray = tempCommands.split(" ");
}
var tempTargets = document.getElementById(this.name + "CommandPanel").querySelector('textarea[name="targets"]').value;
if (tempTargets.length != 0) {
//purge spaces
//tempCommands = tempCommands.replace(/\s+/g, '');
//string.split(",")
this.targetArray = tempTargets.split(" ");
}
//update the module specific variables
if (!isNaN(document.getElementById(this.name + "CommandPanel").querySelector('input[name="command_delay"]').value)) {
this.startDelay = document.getElementById(this.name + "CommandPanel").querySelector('input[name="command_delay"]').value;
}
if (!isNaN(document.getElementById(this.name + "CommandPanel").querySelector('input[name="command_repeat"]').value)) {
this.repeatTimes = document.getElementById(this.name + "CommandPanel").querySelector('input[name="command_repeat"]').value;
}
}
commandSetup() {
if (this.commandArray.length != 0) {
document.getElementById(this.name + "CommandPanel").querySelector('textarea[name="commands"]').value = this.commandArray.join(" ");
}
if (this.targetArray.length != 0) {
document.getElementById(this.name + "CommandPanel").querySelector('textarea[name="targets"]').value = this.targetArray.join(" ");
}
if (this.startDelay != 0) {
document.getElementById(this.name + "CommandPanel").querySelector('input[name="command_delay"]').value = this.startDelay;
}
if (this.repeatTimes != 0) {
document.getElementById(this.name + "CommandPanel").querySelector('input[name="command_repeat"]').value = this.repeatTimes;
}
}
generateCommand() {
//I0T0{43,218,82}M25D0~
this.command = 'I' + this.cubePosition + 'T' + this.type + '{' + this.color.returnColor()[0] + ',' + this.color.returnColor()[1] + ',' + this.color.returnColor()[2] + '}M' + this.mode.Value + 'D' + this.delay + '~';
//this.command = 'T' + this.type + 'C' + this.cubePosition + 'R' + this.color.returnColor()[0] + 'G' + this.color.returnColor()[1] + 'B' + this.color.returnColor()[2] + 'M' + this.mode.Value + 'D' + this.delay + 'X' + this.debug + 'S' + this.sound + '~';
document.getElementById(this.name + "CommandPanel").querySelector('input[name="generated_string"]').value = this.command;
}
saveCommand() {
this.updateCommand();
fs.writeFileSync(this.filePath, JSON.stringify(this, null, 1), (err) => {
if (err) throw err;
});
}
closePaneForCommand() {
//removes all HTML
document.getElementById(this.name + "CommandPanel").remove();
document.getElementById(this.name + "CommandButton").remove();
document.getElementById(this.name + "homePanelCommandPanel").remove();
//then removes this asset from the global list
global.objectList._CommandList.removeKeyValuePair(this.name);
}
generateSearchResult(containerId) {
var fooName = this.name + "CommandPanel"
var commandPanelForSearch = document.createElement('div');
commandPanelForSearch.className = "stageSearchPaneResult"; //gives it the proper styling
commandPanelForSearch.id = this.name + "CommandSearchButton"; //name of this specific asset
commandPanelForSearch.onclick = function () {
onTabChanged('CommandContentPanel');
var elmnt = document.getElementById(fooName);
elmnt.scrollIntoView();
};
commandPanelForSearch.innerHTML =
`
<div class="stageSearchPaneResultState" style="background-color: #e35656;">#` + (this.position).toLocaleString('en-US', {
minimumIntegerDigits: 3,
useGrouping: false
}) + `</div>
<div class="stageSearchPaneResultSpacer"></div>
<div class="stageSearchPaneResultCommandType" style="background-color: #0075ac; color: rgb(200,200,200);">` + "COMMAND" + `</div>
<div class="stageSearchPaneResultCommand">` + this.name + `</div>
<div class="stageSearchPaneResultCommandObjects">` + (this.assetArray.length + this.groupArray.length) + ` Objects</div>
`;
document.getElementById(containerId).appendChild(commandPanelForSearch);
}
createPaneForCommand() {
//this creates the group pane in the group tab
var commandPanelForCommandTab = document.createElement('div');
commandPanelForCommandTab.className = "viewableCommand hoverPanelContent"; //gives it the proper styling
commandPanelForCommandTab.id = this.name + "CommandPanel"; //name of this specific asset
commandPanelForCommandTab.innerHTML =
`
<!--The autonumber in the order of commands-->
<div class="viewableCommandNumber">#` + (this.position).toLocaleString('en-US', {
minimumIntegerDigits: 3,
useGrouping: false
}) + `</div>
<!--The command name-->
<input class="viewableCommandInput" type="text" name="commandName" value="` + this.name + `" readonly="readonly">
<!--The command messagepane-->
<textarea class="viewableCommandInputPane" type="text" name="commands" placeholder="put command strings here"></textarea>
<!--A list of all assets and groups here-->
<textarea class="viewableCommandInputPane" type="text" name="targets" placeholder="put assets/groups here"></textarea>
<div class="viewableCommandControlPane">
<!--The settings for a command to be ran with-->
<div class="viewableCommandControlPaneControls">
<input class="viewableCommandControlPaneControlsNumber" type="text" name="command_delay" value="Activation delay" onchange="global.objectList._CommandList.findKeyValuePair('` + this.name + `').updateCommand()">
<input class="viewableCommandControlPaneControlsNumber" type="text" name="command_repeat" value="Number of repeats" onchange="global.objectList._CommandList.findKeyValuePair('` + this.name + `').updateCommand()">
</div>
<!--A list of all assets and groups-->
</div>
<button type="button" class="viewableCommandControlPaneSend" onclick="global.objectList._CommandList.findKeyValuePair('` + this.name + `').sendCommand()">
<svg id="viewableCommandControlPaneSendIcon">
<use xlink:href="SvgIcons/play.svg#play"></use>
</svg>
</button>`; //this is the gerneral inner html for the command panel
document.getElementById('CommandContentPanel').appendChild(commandPanelForCommandTab);
//makes the sidebar for the commands
var commandPanelForRightSidebar = document.createElement('div');
commandPanelForRightSidebar.className = "rightPanelCommandButton"; //gives it the proper styling
commandPanelForRightSidebar.id = this.name + "CommandButton"; //name of this specific group
commandPanelForRightSidebar.onclick = function () {
onTabChanged('CommandContentPanel');
var elmnt = document.getElementById(commandPanelForCommandTab.id);
elmnt.scrollIntoView();
};
commandPanelForRightSidebar.innerHTML =
`
<div class="rightPanelCommandButtonThumbnail">#` + (this.position).toLocaleString('en-US', {
minimumIntegerDigits: 3,
useGrouping: false
}) + `</div>
<div class="rightPanelCommandButtonText">` + this.name + `</div>
`;
document.getElementById('RightPanelCommandHolder').appendChild(commandPanelForRightSidebar);
//make a microcommand in the command highlighter leftSidebarCommandViewerCollapsible
var commandPanelForCommandHighlighter = document.createElement('div');
commandPanelForCommandHighlighter.className = "leftPanelCommandButton"; //gives it the proper styling
commandPanelForCommandHighlighter.id = this.name + "CommandHighlightButton"; //name of this specific group
commandPanelForCommandHighlighter.onclick = function () {
onTabChanged('CommandContentPanel');
var elmnt = document.getElementById(commandPanelForCommandTab.id);
elmnt.scrollIntoView();
};
commandPanelForCommandHighlighter.innerHTML =
`
<div class="leftPanelCommandButtonThumbnail">#` + (this.position).toLocaleString('en-US', {
minimumIntegerDigits: 3,
useGrouping: false
}) + `</div>
<div class="leftPanelCommandButtonText">` + this.name + `</div>
`;
document.getElementById('leftSidebarCommandViewerCollapsible').appendChild(commandPanelForCommandHighlighter);
//make a microcommand on the home panel
var commandPanelForHomePanel = document.createElement('div');
commandPanelForHomePanel.className = "HomePanelCommandSummary"; //gives it the proper styling
commandPanelForHomePanel.id = this.name + "homePanelCommandPanel"; //name of this specific asset
commandPanelForHomePanel.onclick = function () {
onTabChanged('CommandContentPanel');
var elmnt = document.getElementById(commandPanelForCommandTab.id);
elmnt.scrollIntoView();
};
commandPanelForHomePanel.innerHTML =
`
<div class="HomePanelCommandSummaryState">#` + (this.position).toLocaleString('en-US', {
minimumIntegerDigits: 3,
useGrouping: false
}) + `</div>
<div class="HomePanelCommandSummaryColor">NULL</div>
<div class="HomePanelCommandSummaryName">` + this.name + `</div>
`;
document.getElementById('HomeCommandSummary').appendChild(commandPanelForHomePanel);
//update content
var test = this.name;
setTimeout(function () {
global.objectList._CommandList.findKeyValuePair(test).commandSetup();
}, 200);
}
}
/////////////////////////////////////////////////////////////////// GROUP CLASS
class Group {
constructor() {
this.name = "";
this.filePath = "";
this.isDisbanded = false;
this.state = 0; //STBY BIND DISS RUN
this.stateChanged = (newState) => this.state != newState;
this.assetArray = new Array(); //keys instead of objects
}
//All GROUPS METHODS
setState(status = 0) {
var stateArray = [
'STBY',
'BIND',
'DISB',
'RUN',
'PAUS',
'STOP'
];
var stateArrayColor = [
'#f9a12f',
'#24c65b',
'#e35656',
'#0075ac',
'#F75C03',
'#e35656'
];
//get all of the changable objects
var displays = [
document.getElementById(this.name + "GroupPanel").getElementsByClassName("viewableGroupTitlePaneStatus")[0],
document.getElementById(this.name + "GroupButton").getElementsByClassName("rightPanelGroupButtonThumbnail")[0],
document.getElementById(this.name + "homePanelGroupPanel").getElementsByClassName("HomePanelGroupSummaryState")[0],
];
if (this.stateChanged(status)) {
//set the global status
this.state = status;
//change the of all of the static ones
for (var i = 0; i < displays.length; i++) {
//change the text
displays[i].innerHTML = stateArray[status];
//change the color
displays[i].style.backgroundColor = stateArrayColor[status];
}
}
}
callEvent(name) {
// a custom event handler that will be called locally from within the assets themselves
switch (name) {
case 'group-standby':
//set state
this.setState(0);
//then send a notification
notification.send("NOTICE, THIS GROUP HAS BEEN REINSTATED AND IS ON STANDBY", this.name);
break;
case 'group-activated':
//set state
this.setState(1);
//then send a notification
notification.send("NOTICE, ASSETS SUCCESFULLY BINDED", this.name);
break;
case 'group-disbanded':
//set state
this.setState(2);
//then send a notification
notification.send("NOTICE, THIS GROUP IS DISBANDED", this.name);
break;
case 'command-sent':
//set state
this.setState(3);
break;
case 'command-pause':
//set state
this.setState(4);
break;
case 'command-stop':
//set state
this.setState(5);
break;
default:
// do nothing if it defaults
}
}
sendCommand(commandString) {
this.updateGroup();
for (var i = 0; i < this.assetArray.length; i++) {
global.objectList._AssetList.findKeyValuePair(this.assetArray[i]).sendCommand(commandString);
}
if (commandString.includes("M0")) {
this.callEvent('command-stop');
} else if (commandString.includes("M23")) {
this.callEvent('command-pause');
} else {
this.callEvent('command-sent');
}
}
generateAndSendLocalCommand() {
var delayClamped = 0;
var checkClamped = 0;
var colorClamped = new Color("Custom", document.getElementById(this.name + "GroupPanel").querySelector('label[name="colorPicker"]').style.backgroundColor);
var modeClamped = global.objectList._ModeList[document.getElementById(this.name + "GroupPanel").querySelector('select[name="modeDropdown"]').value];
//clamp the dlay value
if (!isNaN(document.getElementById(this.name + "GroupPanel").querySelector('input[name="delay"]').value)) {
delayClamped = document.getElementById(this.name + "GroupPanel").querySelector('input[name="delay"]').value;
}
//clamp the debug value
if (document.getElementById(this.name + "GroupPanel").querySelector('input[name="debug"]').checked) {
checkClamped = 1;
}
//generate a local command
var localCommand = 'I0T0{' + colorClamped.returnColor()[0] + ',' + colorClamped.returnColor()[1] + ',' + colorClamped.returnColor()[2] + '}M' + modeClamped.Value + 'D' + delayClamped + '~';
//var localCommand = 'T0C0R' + colorClamped.returnColor()[0] + 'G' + colorClamped.returnColor()[1] + 'B' + colorClamped.returnColor()[2] + 'M' + modeClamped.Value + 'D' + delayClamped + 'X' + checkClamped + 'S0~\n';
//change the html of the command input
document.getElementById(this.name + "GroupPanel").querySelector('input[name="generated_string"]').value = localCommand;
//send it
this.sendCommand(localCommand);
}
saveGroup() {
this.updateGroup();
fs.writeFileSync(this.filePath, JSON.stringify(this, null, 1), (err) => {
if (err) throw err;
});
}
groupSetup() {
for (var i = 0; i < this.assetArray.length; i++) {
if (!document.getElementById(this.name + "GroupPanel").querySelector('*[id="' + this.assetArray[i] + "groupPanelAssetCheckbox" + '"]').checked) {
document.getElementById(this.name + "GroupPanel").querySelector('*[id="' + this.assetArray[i] + "groupPanelAssetCheckbox" + '"]').checked = true;
}
}
}
updateGroup() {
var optionBox = document.getElementById(this.name + "GroupPanel").querySelector('select[name="modeDropdown"]');
if (document.getElementById(this.name + "GroupPanel").querySelector('select[name="modeDropdown"]').length == 1) {
global.objectList._ModeList.forEach(function (option) {
optionBox.innerHTML += "<option value=\"" + option.Value + "\">" + option.Name + "</option>";
});
}
//will update everything about the group data
this.assetArray = [];
var test = document.getElementById(this.name + "GroupPanel").querySelector('div[name="selectedAssets"]').childNodes;
for (var i = 1; i < test.length; i++) {
if (test[i].querySelector("input").checked) {
var alias = test[i].querySelector("input").id.replace('groupPanelAssetCheckbox', '');
//global.objectList._AssetList.findKeyValuePair(alias).name
this.assetArray.push(alias);
}
}
//update the amount of element shown on the home screen number
document.getElementById(this.name + "homePanelGroupPanel").getElementsByClassName("HomePanelGroupSummaryAssets")[0].innerHTML = this.assetArray.length + " Assets";
}
closePaneForGroup() {
//removes all HTML
document.getElementById(this.name + "GroupPanel").remove();
document.getElementById(this.name + "GroupButton").remove();
document.getElementById(this.name + "homePanelGroupPanel").remove();
if (document.getElementById(this.name + "commandPanelGroupPanel") != null) {
document.getElementById(this.name + "commandPanelGroupPanel").remove();
}
//then removes this asset from the global list
global.objectList._GroupList.removeKeyValuePair(this.name);
}
generateSearchResult(containerId) {
var fooName = this.name + "GroupPanel"
var groupPanelForSearch = document.createElement('div');
groupPanelForSearch.className = "stageSearchPaneResult"; //gives it the proper styling
groupPanelForSearch.id = this.name + "GroupSearchButton"; //name of this specific asset
groupPanelForSearch.onclick = function () {
onTabChanged('GroupContentPanel');
var elmnt = document.getElementById(fooName);
elmnt.scrollIntoView();
};
groupPanelForSearch.innerHTML =
`
<div class="stageSearchPaneResultState">` + "STBY" + `</div>
<div class="stageSearchPaneResultSpacer"></div>
<div class="stageSearchPaneResultType" style="background-color: #00c3dd; color: rgb(66, 70, 77);">` + "GROUP" + `</div>
<div class="stageSearchPaneResultGroup">` + this.name + `</div>
<div class="stageSearchPaneResultGroupAssets">` + this.assetArray.length + ` Assets</div>
`;
document.getElementById(containerId).appendChild(groupPanelForSearch);
}
createPaneForGroup() {
//this creates the group pane in the group tab
var groupPanelForGroupTab = document.createElement('div');
groupPanelForGroupTab.className = "viewableGroup hoverPanelContent"; //gives it the proper styling
groupPanelForGroupTab.id = this.name + "GroupPanel"; //name of this specific asset
groupPanelForGroupTab.innerHTML =
`
<!--This will house various bits of information for this group-->
<div class="viewableGroupTitlePane">
<div class="viewableGroupTitlePaneStatus">` + "STBY" + `</div>
<div class="viewableGroupTitlePaneName">` + this.name + `</div>
<button type="button" class="viewableGroupTitlePaneDisband"> DISBAND </button>
</div>
<!--This will hold all of the assets in this group-->
<div class="viewableGroupAssetPaneWrapper">
<div class="viewableGroupAssetPane" name="selectedAssets">
</div>
</div>
<!--This is a basic command panel in the asset panel so that test commands can be sent-->
<div class="viewableGroupCommandConstruction">
<!--The color for the command-->
<label name="colorPicker" class="viewableGroupCommandConstructionColor">
<input type="color" style="display: none;"
onchange="this.parentElement.style.backgroundColor = this.value; this.parentElement.style.color = this.value;" />
No Color
</label>
<!--The mode dropdown-->
<select class="viewableGroupCommandConstructionModeSelect" name="modeDropdown">
<option value="0">Select Mode</option>
</select>
<!--The debug boolean of the command-->
<label class="viewableGroupCommandConstructionDebug">
Debug
<input name="debug" class="viewableGroupCommandConstructionDebugCheckbox" type="checkbox" onclick="this.parentElement.childNodes[0].nodeValue = 'Debug ' + this.checked;">
</label>
<!--The delay of the command-->
<input class="viewableGroupCommandConstructionDelay" type="text" name="delay" value="Set Delay (ms)">
<!--The generated string-->
<input class="viewableGroupCommandConstructionGeneratedString" type="text" name="generated_string" value="Generated String" readonly="readonly">
<!--The send button-->
<button type="button" class="viewableGroupCommandConstructionSend" onclick="global.objectList._GroupList.findKeyValuePair('` + this.name + `').generateAndSendLocalCommand()">
<svg id="viewableSlimCommandPlayIcon">
<use xlink:href="SvgIcons/play.svg#play_small"></use>
</svg>
</button>
</div>`; //this is the gerneral inner html for the group panel
document.getElementById('groupPanelGroupHolder').appendChild(groupPanelForGroupTab);
//makes the sidebar for the groups
var groupPanelForRightSidebar = document.createElement('div');
groupPanelForRightSidebar.className = "rightPanelGroupButton"; //gives it the proper styling
groupPanelForRightSidebar.id = this.name + "GroupButton"; //name of this specific group
groupPanelForRightSidebar.onclick = function () {
onTabChanged('GroupContentPanel');
var elmnt = document.getElementById(groupPanelForGroupTab.id);
elmnt.scrollIntoView();
};
groupPanelForRightSidebar.innerHTML =
`
<div class="rightPanelGroupButtonThumbnail">` + "STBY" + `</div>
<div class="rightPanelGroupButtonText">` + this.name + `</div>
`;
document.getElementById('RightPanelGroupHolder').appendChild(groupPanelForRightSidebar);
//make a microasset on the home panel
var groupPanelForHomePanel = document.createElement('div');
groupPanelForHomePanel.className = "HomePanelGroupSummary"; //gives it the proper styling
groupPanelForHomePanel.id = this.name + "homePanelGroupPanel"; //name of this specific asset
groupPanelForHomePanel.onclick = function () {
onTabChanged('GroupContentPanel');
var elmnt = document.getElementById(groupPanelForGroupTab.id);
elmnt.scrollIntoView();
};
groupPanelForHomePanel.innerHTML =
`
<div class="HomePanelGroupSummaryName">` + this.name + `</div>
<div class="HomePanelGroupSummaryAssets">` + this.assetArray.length + ` Assets</div>
<div class="HomePanelGroupSummaryState">` + "STBY" + `</div>
`;
document.getElementById('HomeGroupSummary').appendChild(groupPanelForHomePanel);
//generate the panels in the command panes
var groupPanelForCommandPanel = document.createElement('label');
groupPanelForCommandPanel.id = this.name + "commandPanelGroupPanel";
groupPanelForCommandPanel.title = this.name;
groupPanelForCommandPanel.innerHTML =
`
<input type="checkbox" id="` + this.name + "commandPanelGroupCheckbox" + `" class="viewableCommandObjectButtonCheck">
<span class="viewableCommandObjectButton">
<span class="viewableCommandObjectButtonThumbnail" style="background-color: #00c3dd; color: rgb(66, 70, 77);">G</span>
<span class="viewableCommandObjectButtonText">` + this.name + `</span>
</span>
`;
var elements = document.getElementsByClassName("viewableCommandObjectHolderPanel");
for (var i = 0; i < elements.length; i++) {
elements[i].appendChild(groupPanelForCommandPanel.cloneNode(true));
}
//update the content of the group
var test = this.name;
setTimeout(function () {
global.objectList._GroupList.findKeyValuePair(test).groupSetup();
global.objectList._GroupList.findKeyValuePair(test).updateGroup();
}, 200);
this.setState(0);
//at this point run all update code so that the Group is fully up to date
if (this.assetArray.length == 0) {
this.setState(0);
} else if (this.isDisbanded) {
this.callEvent('group-disbanded');
} else {
this.callEvent('group-activated');
}
//this.updateGroup();
}
}
/////////////////////////////////////////////////////////////////// ASSET CLASS
class Asset {
constructor() {
this.type = ""; //this is the type of the box being run
this.name = ""; //the name
this.filePath = ""; //filepath that is used
this.state = 0; //the current state of the asset
this.stateChanged = (newState) => this.state != newState;
this.protocol = new Protocol();
}
//All ASSET METHODS
setState(status = 0) {
var stateArray = [
'STBY',
'CON',
'DISS',
'RUN',
'PAUS',
'STOP',
'SYNC'
];
var stateArrayColor = [
'#f9a12f',
'#24c65b',
'#e35656',
'#0075ac',
'#F75C03',