-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
7831 lines (7060 loc) · 242 KB
/
index.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
// define express webserver
const express = require('express');
// define webserver app
const app = express();
// define http server
const server = require('http').Server(app);
const port = process.env.PORT || '4000'; // port
// define socket.io with cors for Cross-Origin Resource Sharing
const io = require('socket.io')(server, {
cors: {
origin: '*'
}
});
// define cors for cross origin
const cors = require('cors');
// define websocket ws
const WebSocket = require('ws');
// define body parser for url encode
const bodyParser = require("body-parser");
// define read files
const fs = require('fs');
// define multer for file upload
const multer = require('multer');
// winston logger
const winston = require('winston');
const path = require('path');
// create logger itself
const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp({
format: 'MMM-DD-YYYY HH:mm:ss'
}),
winston.format.printf(info => `${[info.timestamp]}: ${info.level}: ${info.message}`),
),
transports: [
// write all logs error (and below) to `error.log`
new winston.transports.File({ filename: 'logs/error.log', level: 'error' }),
// write to all logs with level `info` and below to `combined.log`
new winston.transports.File({ filename: 'logs/combined.log' }),
// write all logs to console
new winston.transports.Console()
]
});
// use url encode
app.use(bodyParser.urlencoded({
extended:true
}));
// define static files
app.use(express.static("logos"));
app.use(express.static("images"));
app.use(express.static("css"));
app.use(express.static("script"));
app.use(express.static("logs"));
app.use(express.static("teams"));
app.use(express.static("games"));
// use cors
app.use(cors());
// http server port
server.listen(port, function(){
logger.info("HTTP server is running on port "+port);
});
// file upload storage
var storage = multer.diskStorage({
destination: function(req, file, cb){
cb(null, 'teams');
},
filename: function (req, file, cb){
cb(null, file.originalname);
}
});
// file upload instance
var upload = multer({storage: storage}).single('file');
// post / upload file
app.post('/upload',function(req, res){
upload(req, res, function(err){
if(err instanceof multer.MulterError){
return res.status(500).json(err);
}else if(err){
return res.status(500).json(err);
}
// display uploaded image
res.status(200).send(req.file);
})
})
// --- initial data setup ---
var gameData;
var playerData;
var teamData;
// define base initial game data
// team 1
var team1= 'Razorbacks';
var logo1= 'fursty-razorbacks.png';
var color1= '#ee1818';
// team 2
var team2= 'Guest';
var logo2= 'no-logo.png';
var color2= '#ffffff';
// ball
var ballbesitz= 'team1';
// points
var points1= 0;
var points2= 0;
// timeouts
var team1timeouts= 3;
var team2timeouts= 3;
// visible parts
// quarter
var quartershow= 'yes';
var quarter= 'PRE';
// gameclock
var clockshow= 'yes';
var clockmin= 12;
var clocksec= 0;
var clockseconds= 720;
// gameclock quarter in seconds
var clocksetup= 720;
// clock as string
var clock= '12:00';
// playclock
var playclockshow= 'yes';
var playclock= 30;
// down
var downshow= 'yes';
var down= '1st';
// distance
var distanceshow= 'yes';
var distance= '10';
var distanceyard= 10;
// score display
var score= 'no';
var scorelogo= 'no';
// flag
var flag= 'no';
// teamlist
var teams;
// player lists
var team1players;
var team2players;
// field side
var team1fieldside = 'left';
var team2fieldside = 'right';
// commentator
var kommentator1 = '';
var kommentator2 = '';
var kommentator1logo= 'fursty-razorbacks.png';
var kommentator2logo= 'fursty-razorbacks.png';
var showkommentator = 'no';
// name overlay
var showtimer = 'no';
var bauchbinde1 = '';
var bauchbinde2 = '';
var bauchbindelogo = '';
var showbauchbinde = 'no';
// playclock run
var playclockrun = 'stop';
// other variables
// obs connection
var obsconnection= '';
var obsscene= '';
// logos for streamdeck
var logo1base64;
var logo1streamdeck;
var logo2base64;
var logo2streamdeck;
// --- websocket server ws for StreamDeck connection and communication ---
// websocket ws server
const wsServer = new WebSocket.Server({ port: 3001 });
// check ws socket connection
wsServer.on('connection', function(socket){
logger.info('StreamDeck connection received');
// check received message
socket.on('message', function (data) {
logger.info('message from StreamDeck:', data);
// save json data from StreamDeck
var streamdeckdata = JSON.parse(data);
logger.verbose('StreamDeck JSON data:', streamdeckdata);
// define empty button data
var contextid = '';
var event = '';
var id = '';
// loop StreamDeck data
for(var key in streamdeckdata){
// find context
if(key.match('context')){
// save context
contextid = streamdeckdata[key];
}
// find event
if(key.match('event')){
// save context
event = streamdeckdata[key];
}
// find payload
if(key.match('payload')){
// save payload as json data
var payload = streamdeckdata[key];
// loop through payload
for(var pkey in payload){
// find settings
if(pkey.match('settings')){
// save settings as json data
var settings = payload[pkey];
// loop through settings
for(var skey in settings){
// find id
if(skey.match('id')){
// save id
id = settings[skey];
}
}
}
}
}
}
// read logos and create base64 images
streamDeckLogos();
// check the StreamDeck data based on event and id with context identifier
// main actions from StreamDeck buttons
// check id with keyUp
if(event === 'keyUp'){
// button id
if(id === 'countquarter'){
var newdata = JSON.stringify({event:"setTitle",context:contextid, payload:{title:quarter, target: 0}});
logger.info('Streamdeck event data:', JSON.parse(newdata));
socket.send(newdata);
}else if(id === 'countdowns'){
var newdata = JSON.stringify({event:"setTitle",context:contextid, payload:{title:down, target: 0}});
logger.info('Streamdeck event data:', JSON.parse(newdata));
socket.send(newdata);
}else if(id === 'counttimeoutteam1'){
var newdata = JSON.stringify({event:"setTitle",context:contextid, payload:{title:team1timeouts.toString(), target: 0}});
logger.info('Streamdeck event data:', JSON.parse(newdata));
socket.send(newdata);
var newdata = JSON.stringify({event:"setImage",context:contextid, payload:{image:logo1streamdeck, target: 0}});
logger.info('Streamdeck event data:', JSON.parse(newdata));
socket.send(newdata);
}else if(id === 'counttimeoutteam2'){
var newdata = JSON.stringify({event:"setTitle",context:contextid, payload:{title:team2timeouts.toString(), target: 0}});
logger.info('Streamdeck event data:', JSON.parse(newdata));
socket.send(newdata);
var newdata = JSON.stringify({event:"setImage",context:contextid, payload:{image:logo2streamdeck, target: 0}});
logger.info('Streamdeck event data:', JSON.parse(newdata));
socket.send(newdata);
}
}
});
});
// create images for stream deck from team logos
function streamDeckLogos(){
// read logos from team1 and team2 and create base64 images
logo1base64 = fs.readFileSync('logos/'+logo1, 'base64');
logo1streamdeck = "data:image/png;base64,"+logo1base64+"\"";
logo2base64 = fs.readFileSync('logos/'+logo2, 'base64');
logo2streamdeck = "data:image/png;base64,"+logo2base64+"\"";
}
/*
// `server` is a vanilla Node.js HTTP server, so use
// the same ws upgrade process described here:
// https://www.npmjs.com/package/ws#multiple-servers-sharing-a-single-https-server
const server2 = app.listen(3001);
server2.on('upgrade', (request, socket, head) => {
wsServer.handleUpgrade(request, socket, head, socket => {
wsServer.emit('connection', socket, request);
});
});
*/
// --- functions ---
// sleep function
function sleep(millis) {
return new Promise(resolve => setTimeout(resolve, millis));
}
// create JSON data from game data
function gameDataToJSON(){
// create json data for gamedata
gameData = {
team1: team1,
logo1: logo1,
color1: color1,
team2: team2,
logo2: logo2,
color2: color2,
ballbesitz: ballbesitz,
points1: points1,
team1timeouts: team1timeouts,
points2: points2,
team2timeouts: team2timeouts,
quartershow: quartershow,
quarter: quarter,
clockshow: clockshow,
clocksetup: clocksetup,
clockseconds: clockseconds,
clock: clock,
playclockshow: playclockshow,
playclock: playclock,
downshow: downshow,
down: down,
distanceshow: distanceshow,
distance: distance,
distanceyard: distanceyard,
score: score,
scorelogo: scorelogo,
flag: flag,
obsconnection: obsconnection,
obsscene: obsscene,
teams: teams,
team1fieldside: team1fieldside,
team2fieldside: team2fieldside,
// bauchbinde
kommentator1: kommentator1,
kommentator2: kommentator2,
kommentator1logo: kommentator1logo,
kommentator2logo: kommentator2logo,
showkommentator: showkommentator,
bauchbinde1: bauchbinde1,
bauchbinde2: bauchbinde2,
bauchbindelogo: bauchbindelogo,
showbauchbinde: showbauchbinde,
showtimer: showtimer
};
}
// send json object from game data
// perform some checks on data before sending
function sendGameData() {
// check distance
distanceYards();
// check distance smaller than 1 yard
if(distanceyard<1){
// show inches
distance = 'inches';
}else{
// show distance
distance = distanceyard.toString();
}
// check points smaller than 0
checkPoints();
// create json data
gameDataToJSON();
// send data
//io.emit('loadedscoreboard', gameData);
io.emit('sendgamedata', gameData);
}
// load game data from file
function loadGameDataFromFile(){
// read file
fs.readFile('logs/gamedata.log', 'utf8' , (err, data) => {
// error
if (err) {
logger.error(err);
}
// parse as json
var jsongamedata = JSON.parse(data);
// gamedata = Object.assign(gamedata, JSON.parse(data));
// get json data
team1 = jsongamedata.team1;
logo1 = jsongamedata.logo1;
color1 = jsongamedata.color1;
team2 = jsongamedata.team2;
logo2 = jsongamedata.logo2;
color2 = jsongamedata.color2;
ballbesitz = jsongamedata.ballbesitz;
points1 = jsongamedata.points1;
team1timeouts = jsongamedata.team1timeouts;
points2 = jsongamedata.points2;
team2timeouts = jsongamedata.team2timeouts;
quartershow = jsongamedata.quartershow;
quarter = jsongamedata.quarter;
clockshow = jsongamedata.clockshow;
clocksetup = jsongamedata.clocksetup;
clockseconds = jsongamedata.clockseconds;
clock = jsongamedata.clock;
playclockshow = jsongamedata.playclockshow;
playclock = jsongamedata.playclock;
downshow = jsongamedata.downshow;
down = jsongamedata.down;
distanceshow = jsongamedata.distanceshow;
distance = jsongamedata.distance;
distanceyard = jsongamedata.distanceyard;
score = jsongamedata.score;
scorelogo = jsongamedata.scorelogo;
flag = jsongamedata.flag;
obsconnection = jsongamedata.obsconnection;
obsscene = jsongamedata.obsscene;
teams = jsongamedata.teams;
team1fieldside = jsongamedata.team1fieldside;
team2fieldside = jsongamedata.team2fieldside;
// bauchbinde
kommentator1 = jsongamedata.kommentator1;
kommentator2 = jsongamedata.kommentator2;
kommentator1logo = jsongamedata.kommentator1logo;
kommentator2logo = jsongamedata.kommentator2logo;
showkommentator = jsongamedata.showkommentator;
bauchbinde1 = jsongamedata.bauchbinde1;
bauchbinde2 = jsongamedata.bauchbinde2;
bauchbindelogo = jsongamedata.bauchbindelogo;
showbauchbinde = jsongamedata.showbauchbinde;
showtimer = jsongamedata.showtimer;
})
}
// write game data to file
function writeGameDataToFile(){
fs.writeFile('logs/gamedata.log', JSON.stringify(gameData), err => {
if (err) {
logger.error(err);
return
}
//file written successfully
})
}
// read team list from file
function readTeams(){
// read file
fs.readFile('logos/teams.json', 'utf8' , (err, data) => {
// error
if (err) {
logger.error(err);
}
// parse as json
try {
// parse as json
teams = JSON.parse(data);
} catch (err) {
logger.error(err);
}
})
}
// read team1 player file and return as json
function readTeam1players(){
// read file
fs.readFile('logos/team1.json', 'utf8' , (err, data) => {
// error
if (err) {
logger.error(err);
}
// parse as json
try {
// parse as json
team1players = JSON.parse(data);
} catch (err) {
logger.error(err);
}
})
}
// read team2 player file and return as json
function readTeam2players(){
// read file
fs.readFile('logos/team2.json', 'utf8' , (err, data) => {
// error
if (err) {
logger.error(err);
}
// parse as json
try {
// parse as json
team2players = JSON.parse(data);
} catch (err) {
logger.error(err);
}
})
}
// setup teams as team1 and team2
function setupTeams(teamnumber, teamname){
// loop through teams
for(var i = 0; i < teams.length; i++){
// check team name
if(teamname.match(teams[i].team_name)){
// setup team
if(teamnumber === 1){
// team1
team1= teams[i].name;
logo1= teams[i].logo;
color1= teams[i].color;
}else if(teamnumber === 2){
// team1
team2= teams[i].name;
logo2= teams[i].logo;
color2= teams[i].color;
}
}
}
}
// create ans send json object from teams list data
function sendAllTeamsData() {
// create json data
teamData = {
teamlist: teams,
};
// send data
//io.emit('loadedteams', teamData);
io.emit('sendteamlist', teamData);
}
// create ans send json object from team player data
function sendTeamData() {
// create json data
playerData = {
team1players: team1players,
team2players: team2players,
};
// send data
//io.emit('loadedplayers', playerData);
io.emit('sendplayerlist', playerData);
}
// start playclock
function playclockRun(){
// set interval
var myInt = setInterval(() => {
if(playclockrun === 'start'){
// count clock
if(clockseconds > 0){
// reduce one second, count seconds
setClock('minus1Second');
}else{
logger.info("Clock finished ");
clearInterval(myInt);
}
// set game data
sendGameData();
}else{
// stop clock
clearInterval(myInt);
}
}, 1000);
}
// create time string from min and sec
function setClock(action) {
// get action
if(action === 'reset12Clock'){
// set seconds
clocksetup = 720;
} else if(action === 'reset15Clock'){
// set seconds
clocksetup = 900;
} else if(action === 'reset30Clock'){
// set seconds
clocksetup = 1800;
} else if(action === 'plusMinute'){
// set clock
clockseconds = clockseconds+60;
} else if(action === 'minusMinute'){
// set clock
clockseconds = clockseconds-60;
} else if(action === 'plus10Second'){
// set clock
clockseconds = clockseconds+10;
} else if(action === 'minus10Second'){
// set clock
clockseconds = clockseconds-10;
} else if(action === 'plus1Second'){
// set clock
clockseconds = clockseconds+1;
} else if(action === 'minus1Second'){
// set clock
clockseconds = clockseconds-1;
} else if(action === 'resetClock'){
// set clock
clockseconds = clocksetup;
}
// calculate seconds in min and sec
var mins = ~~(clockseconds/60);
var secs = ~~clockseconds % 60;
var stringsec = (secs<10 ? "0" : "")+secs;
clock = mins + ":" + (secs<10 ? "0" : "") + secs;
}
// game field functions
// flip sides
function flipSides() {
// check and change sides
if(team1fieldside === 'left'){
team1fieldside = 'right';
team2fieldside = 'left';
}else{
team1fieldside = 'left';
team2fieldside = 'right';
}
}
// points functions
// touchdownTeam
function touchdownTeam(team){
// set score
score= 'TOUCHDOWN';
showtimer = 'TOUCHDOWN'+team;
var points;
// check team
// count points
if(team === 'team1'){
scorelogo= logo1;
points1 = points1 + 6;
points = points1;
}else{
scorelogo= logo2;
points2 = points2 + 6;
points = points2;
}
logger.info(team+' points: '+points);
// send GameData
sendGameData();
// wait 6 seconds
sleep(6000).then(() => {
// check if score is visible
if(showtimer === 'TOUCHDOWN'+team){
// remove score
score= 'no';
scorelogo= 'no';
showtimer = 'no';
}
// send GameData
sendGameData();
});
}
// twopointTeam
function twopointTeam(team){
// set score
score= '2PT CONVERSION';
showtimer = '2PT CONVERSION'+team;
var points;
// check team
// count points
if(team === 'team1'){
scorelogo= logo1;
points1 = points1 + 2;
points = points1;
}else{
scorelogo= logo2;
points2 = points2 + 2;
points = points2;
}
logger.info(team+' points: '+points);
// send GameData
sendGameData();
// wait 6 seconds
sleep(6000).then(() => {
// check if score is visible
if(showtimer === '2PT CONVERSION'+team){
// remove score
score= 'no';
scorelogo= 'no';
showtimer = 'no';
}
// send GameData
sendGameData();
});
}
// fieldgoalTeam
function fieldgoalTeam(team){
// set score
score= 'FIELDGOAL';
showtimer = 'FIELDGOAL'+team;
var points;
// check team
// count points
if(team === 'team1'){
scorelogo= logo1;
points1 = points1 + 3;
points = points1;
}else{
scorelogo= logo2;
points2 = points2 + 3;
points = points2;
}
logger.info(team+' points: '+points);
// send GameData
sendGameData();
// wait 6 seconds
sleep(6000).then(() => {
// check if score is visible
if(showtimer === 'FIELDGOAL'+team){
// remove score
score= 'no';
scorelogo= 'no';
showtimer = 'no';
}
// send GameData
sendGameData();
});
}
// safetyTeam
function safetyTeam(team){
// set score
score= 'SAFETY';
showtimer = 'SAFETY'+team;
var points;
// check team
// count points
if(team === 'team1'){
scorelogo= logo1;
points1 = points1 + 2;
points = points1;
}else{
scorelogo= logo2;
points2 = points2 + 2;
points = points2;
}
logger.info(team+' points: '+points);
// send GameData
sendGameData();
// wait 6 seconds
sleep(6000).then(() => {
// check if score is visible
if(showtimer === 'SAFETY'+team){
// remove score
score= 'no';
scorelogo= 'no';
showtimer = 'no';
}
// send GameData
sendGameData();
});
}
// points
function points(action){
// check action
if(action === 'plusTeam1' || action === 'extrapointTeam1'){
points1 = points1+1;
}else if (action === 'minusTeam1'){
points1 = points1-1;
}else if(action === 'plusTeam2' || action === 'extrapointTeam2'){
points2 = points2+1;
}else if (action === 'minusTeam2'){
points2 = points2-1;
}
}
// timeoutTeam
function timeoutTeam(action,team){
// check action
if(action === 'plus'){
// increase timeouts
countTimeout('plus',team);
}else if(action === 'minus'){
// decrease timeouts
countTimeout('minus',team);
}else if(action === 'count'){
// set score
score= 'TIMEOUT';
showtimer = 'TIMEOUT'+team;
// check team
if(team === 'team1'){
scorelogo= logo1;
}else{
scorelogo= logo2;
}
// count timeouts
countTimeout('minus',team);
logger.info(team+' timeout');
// send GameData
sendGameData();
// wait 6 seconds
sleep(6000).then(() => {
// check if score is visible
if(showtimer === 'TIMEOUT'+team){
// remove score
score= 'no';
scorelogo= 'no';
showtimer = 'no';
}
// send GameData
sendGameData();
});
}
}
// bauchbinde functions
// kommentatorenShow
function kommentatorenShow(data){
// set kommentator
kommentator1 = data.kommentator1;
kommentator2 = data.kommentator2;
kommentator1logo = logo1;
kommentator2logo = logo1;
showkommentator = 'yes';
// send GameData
sendGameData();
}
// kommentatorenHide
function kommentatorenHide(){
showkommentator = 'no';
// send GameData
sendGameData();
}
// bauchbindeShow
function bauchbindeShow(team,data){
// check team
if(team === 'team1'){
bauchbindelogo = logo1;
}else if(team === 'team2'){
bauchbindelogo = logo2;
}else{
bauchbindelogo = '';
}
// set bauchbinde
bauchbinde1 = data.bauchbinde1;
bauchbinde2 = data.bauchbinde2;
showbauchbinde = 'yes';
showtimer = bauchbinde1+bauchbinde2;
// send GameData
sendGameData();
// wait 6 seconds
sleep(6000).then(() => {
// check if score is visible
if(showtimer === bauchbinde1+bauchbinde2){
// remove score
score= 'no';
scorelogo= 'no';
showtimer = 'no';
}
bauchbindeHide();
});
}
// bauchbindeHide
function bauchbindeHide(){
showbauchbinde= 'no';
// send GameData
sendGameData();
}
// bauchbindeShowTeamPlayer
function bauchbindeShowTeamPlayer(team,data){
// get player number
var num = data.player;
// setup variables
var number = '';
var name = '';
var position = '';
// loop player data
// check team
if(team === 'team1'){
bauchbindelogo = logo1;
for (var i = 0; i < team1players.length; i++){
// get array object
var obj = team1players[i];
// check player number
if(num === obj['number']){
// player data
name = obj['name'];
position = obj['position'];
}
}
}else{
bauchbindelogo = logo2;
for (var i = 0; i < team2players.length; i++){
// get array object
var obj = team2players[i];
// check player number
if(num === obj['number']){
// player data
name = obj['name'];
position = obj['position'];
}
}
}
// set bauchbinde
// check player number is a number
if(isNaN(num)){
// NAN (Not A Number) dont' add the number to the name
}else{
// add the number to the name
number = "#"+num+" ";
}
bauchbinde1 = number+name;
bauchbinde2 = position;
showbauchbinde = 'yes';
showtimer = bauchbinde1+bauchbinde2;
// send GameData
sendGameData();
// wait 6 seconds
sleep(6000).then(() => {
// check if score is visible
if(showtimer === bauchbinde1+bauchbinde2){
// remove score
score= 'no';
scorelogo= 'no';
showtimer = 'no';
}
bauchbindeHide();
});
}
// update team playerlist
function updateTeamPlayer(team,data){
var teamlist;
var filename;
// check team
if(team === 'team1'){
// file
filename = 'logos/team1.json';
// set team data
team1players = data;
// parse list
teamlist = JSON.parse(team1players);
}else{
// file
filename = 'logos/team2.json';
// set team data
team2players = data;
// parse list
teamlist = JSON.parse(team2players);
}
// set JSON string, human readable
var teamlistjson = JSON.stringify(teamlist, null, 2);
// write file
fs.writeFile(filename, teamlistjson, err => {
if (err) {
logger.error(err);
}
});
}
// update AllTeams List
function updateAllTeamsList(data){
// parse list
var teamslist = JSON.parse(data);
// file
var filename = 'logos/teams.json';
// set JSON string, human readable
var teamslistjson = JSON.stringify(teamslist, null, 2);
// write file
fs.writeFile(filename, teamslistjson, err => {
if (err) {
logger.error(err);
}
});
}
// control show functions
// quarter Show
function quarterShow(){
// change quarter show
if(quartershow === 'yes'){
quartershow = 'no';
} else if(quartershow === 'no'){
quartershow = 'yes';
}
}
// gameclock Show
function gameclockShow(){
// change gameclock show
if(clockshow === 'yes'){
clockshow = 'no';
} else if(clockshow === 'no'){
clockshow = 'yes';
}
}
// playclock Show
function playclockShow(){
// change playclock show
if(playclockshow === 'yes'){
playclockshow = 'no';
} else if(playclockshow === 'no'){
playclockshow = 'yes';
}
}
// down Show
function downShow(){
// change down show
if(downshow === 'yes'){
downshow = 'no';
} else if(downshow === 'no'){
downshow = 'yes';
}
}
// distance Show
function distanceShow(){
// change distance show
if(distanceshow === 'yes'){
distanceshow = 'no';
} else if(distanceshow === 'no'){
distanceshow = 'yes';
}
}
// count quarter up