'use strict';
let clock_running = false;
+let clock2_running = false;
let clock_visible = false;
+let scorebug2_visible = false;
let comment_visible = false;
let lowerthird_visible = false;
let clock_elapsed = 0;
+let clock2_elapsed = 0;
let clock_limit = 30 * 60;
let scoreA = 0;
let scoreB = 0;
let clock_origin;
+let clock2_origin;
let state = {};
function setteams()
loadquickl3s(sheets);
}
+function setteams2()
+{
+ document.getElementById('score2_team1').innerHTML = state['team1'];
+ document.getElementById('score2_team2').innerHTML = state['team2'];
+}
+
function setcolors()
{
document.getElementById('team1color').style.backgroundColor = state['team1color'];
update_score();
}
+function setscore2()
+{
+ scoreA = state['score1'];
+ scoreB = state['score2'];
+ document.getElementById('score2_score').innerHTML = scoreA + " – " + scoreB;
+}
+
function startclock()
{
if (!clock_running) {
showclock();
}
+function startclock2()
+{
+ if (!clock2_running) {
+ clock2_origin = Date.now();
+ clock2_running = true;
+ }
+ // No showclock.
+}
+
function stopclock()
{
if (!clock_running) return;
clock_running = false;
}
+function stopclock2()
+{
+ if (!clock2_running) return;
+ clock2_elapsed = time2_elapsed();
+ clock2_origin = Date.now();
+ clock2_running = false;
+}
+
function setclock(amount)
{
clock_elapsed = amount;
update_clock();
}
+function setclock2(amount)
+{
+ clock2_elapsed = amount;
+ clock2_origin = Date.now();
+ update_clock2();
+}
+
function setclockfromstate()
{
let amount = parseInt(state['clock_min']) * 60 + parseInt(state['clock_sec']);
setclock(amount);
}
+// No setclock2fromstate.
+
+function adjustclockfromstate()
+{
+ let amount = parseInt(state['clock_min']) * 60 + parseInt(state['clock_sec']);
+ let elapsed = time_elapsed_raw();
+ if (Math.abs(amount - elapsed) >= 2.0) {
+ setclock(amount);
+ }
+}
+
+function adjustclock2fromstate()
+{
+ let amount = parseInt(state['clock_min']) * 60 + parseInt(state['clock_sec']);
+ let elapsed = time_elapsed2_raw();
+ if (Math.abs(amount - elapsed) >= 2.0) {
+ setclock2(amount);
+ }
+}
+
function setclocklimitfromstate()
{
let amount = parseInt(state['clock_limit_min']) * 60 + parseInt(state['clock_limit_sec']);
{
if (lowerthird_visible) return;
- // With no flexbox, this is how it has to be...
- let f = document.getElementById('lowerthird-headline');
- let g = document.getElementById('lowerthird-headline-content');
- f.style.paddingTop = Math.round((f.clientHeight - g.clientHeight) / 2) + 'px';
-
- f = document.getElementById('lowerthird-subheading');
- g = document.getElementById('lowerthird-subheading-content');
- f.style.paddingTop = Math.round((f.clientHeight - g.clientHeight) / 2) + 'px';
-
- f = document.getElementById('lowerthird-picture');
- g = document.getElementById('lowerthird-picture-content');
- f.style.paddingTop = Math.round((f.clientHeight - g.clientHeight) / 2) + 'px';
-
document.getElementById('lowerthird-headline').className = 'lowerthird-headline lowerthird-headline-animate-in';
document.getElementById('lowerthird-headline-content').className = 'lowerthird-headline-content lowerthird-headline-content-animate-in';
document.getElementById('lowerthird-subheading').className = 'lowerthird-subheading lowerthird-subheading-animate-in';
document.getElementById('lowerthird-headline-content').className = 'lowerthird-headline-content lowerthird-headline-content-animate-out';
document.getElementById('lowerthird-subheading').className = 'lowerthird-subheading lowerthird-subheading-animate-out';
document.getElementById('lowerthird-subheading-content').className = 'lowerthird-subheading-content lowerthird-subheading-content-animate-out';
- document.getElementById('lowerthird-picture').className = 'lowerthird-picture lowerthird-picture-hidden lowerthird-picture-animate-out';
+ document.getElementById('lowerthird-picture').className = 'lowerthird-picture lowerthird-picture-animate-out';
document.getElementById('lowerthird-picture-content').className = 'lowerthird-picture-content lowerthird-picture-content-animate-out';
lowerthird_visible = false;
}
-function time_elapsed()
+function time_elapsed_raw()
{
let elapsed = (Date.now() - clock_origin) * 1e-3;
if (clock_elapsed + elapsed >= clock_limit) {
clock_running = false;
return clock_limit;
}
- return Math.floor(clock_elapsed + elapsed);
+ return clock_elapsed + elapsed;
+}
+
+function time_elapsed2_raw()
+{
+ let elapsed = (Date.now() - clock2_origin) * 1e-3;
+ if (clock2_elapsed + elapsed >= clock_limit) {
+ // No separate clock 2 limit.
+ return clock_limit;
+ }
+ return clock2_elapsed + elapsed;
+}
+
+function time_elapsed()
+{
+ return Math.floor(time_elapsed_raw());
+}
+
+function time_elapsed2()
+{
+ return Math.floor(time_elapsed2_raw());
}
function update_clock()
let sec = elapsed % 60;
if (sec < 10) sec = "0" + sec;
- document.getElementById('clock').innerHTML = min + ":" + sec;
+ let text = min + ":" + sec;
+
+ if (false) {
+ // This is a hack around the fact that Exo has variable-width numerals.
+ // It doesn't look fantastic, but for the clock, it's better not to have
+ // the text jumping around.
+ let html = "";
+ for (let i = 0; i < text.length; ++i) {
+ if (text.charAt(i) === ':') {
+ html += ':';
+ } else {
+ html += "<div style='display: inline-block; width: 15px'>" + text.charAt(i) + "</div>";
+ }
+ }
+ document.getElementById('clock').innerHTML = html;
+ } else {
+ document.getElementById('clock').innerHTML = text;
+ }
+}
+
+function update_clock2()
+{
+ let elapsed = time_elapsed2();
+ let min = Math.floor(elapsed / 60);
+ let sec = elapsed % 60;
+
+ if (sec < 10) sec = "0" + sec;
+ let text = min + ":" + sec;
+
+ document.getElementById('clock2').innerHTML = text;
}
function goalA()
document.getElementById('score').innerHTML = scoreA + " – " + scoreB;
}
-/* called by caspar only */
+/* called by the Nageru theme only */
function play()
{
document.getElementById('manualcontrols').style.display = 'none';
document.getElementById('area').style.display = 'none';
-
- // Old CEF workaround
- document.getElementById('lowerthird-subheading').style.top = '638px';
}
function update(v)
if (clock_running) {
update_clock();
}
+ if (clock2_running) {
+ update_clock2();
+ }
}, 100);
update_score();
//play();
//startclock();
+
+let websocket = null;
+
+function open_ws()
+{
+ console.log("Connecting...");
+ try {
+ if (websocket)
+ websocket.close();
+ websocket = new WebSocket("ws://127.0.0.1:5250/");
+ websocket.onopen = function(evt) {
+ console.log("Connected to client.");
+ };
+ websocket.onclose = function(evt) {
+ console.log("Disconnected from client.");
+ setTimeout(open_ws, 100);
+ };
+ websocket.onmessage = function(evt) {
+ let msg = evt.data;
+ let m = msg.match(/^update (.*)/);
+ if (m !== null) {
+ update(m[1]);
+ }
+ m = msg.match(/^eval (.*)/);
+ if (m !== null) {
+ eval(m[1]);
+ }
+ };
+ websocket.onerror = function(evt) {
+ console.log('Error: ' + evt.data);
+ };
+ } catch (exception) {
+ console.log('Error: ' + exception);
+ setTimeout(open_ws, 100);
+ }
+};
+open_ws();