'use strict';
-let clock_running = false;
+let num_clocks = 3;
+let clocks = [
+ { 'running': false, 'elapsed': 0, 'origin': undefined, 'id': 'clock' },
+ { 'running': false, 'elapsed': 0, 'origin': undefined, 'id': 'clock2' },
+ { 'running': false, 'elapsed': 0, 'origin': undefined, 'id': 'clock3' }
+];
+
let clock_visible = false;
let comment_visible = false;
let lowerthird_visible = false;
-let clock_elapsed = 0;
-let clock_limit = 30 * 60;
+let clock_limit = 25 * 60;
let scoreA = 0;
let scoreB = 0;
-let clock_origin;
let state = {};
function setteams()
loadquickl3s(sheets);
}
+function setteams2()
+{
+ document.getElementById('score2_team1').innerHTML = state['team1'];
+ document.getElementById('score2_team2').innerHTML = state['team2'];
+}
+
+function setteams3()
+{
+ document.getElementById('score3_team1').innerHTML = state['team1'];
+ document.getElementById('score3_team2').innerHTML = state['team2'];
+}
+
function setcolors()
{
document.getElementById('team1color').style.backgroundColor = state['team1color'];
update_score();
}
-function startclock()
+function setscore2()
+{
+ scoreA = state['score1'];
+ scoreB = state['score2'];
+ document.getElementById('score2_score').innerHTML = scoreA + " – " + scoreB;
+}
+
+function setscore3()
{
- if (!clock_running) {
- clock_origin = Date.now();
- clock_running = true;
+ scoreA = state['score1'];
+ scoreB = state['score2'];
+ document.getElementById('score3_score').innerHTML = scoreA + " – " + scoreB;
+}
+
+function startclock(num)
+{
+ if (!clocks[num].running) {
+ clocks[num].origin = Date.now();
+ clocks[num].running = true;
+ }
+ if (num == 0) {
+ showclock();
}
- showclock();
}
-function stopclock()
+function stopclock(num)
{
- if (!clock_running) return;
- clock_elapsed = time_elapsed();
- clock_origin = Date.now();
- clock_running = false;
+ if (!clocks[num].running) return;
+ clocks[num].elapsed = time_elapsed(num);
+ clocks[num].origin = Date.now();
+ clocks[num].running = false;
}
-function setclock(amount)
+function setclock(num, amount)
{
- clock_elapsed = amount;
- clock_origin = Date.now();
- update_clock();
+ clocks[num].elapsed = amount;
+ clocks[num].origin = Date.now();
+ update_clock(num);
+
+ // The BT-6000 likes to reset to 0:00 a while after the match is over,
+ // so go hide it then.
+ if (num == 0 && !clocks[num].running) {
+ hideclock();
+ }
}
function setclockfromstate()
{
let amount = parseInt(state['clock_min']) * 60 + parseInt(state['clock_sec']);
- setclock(amount);
+ setclock(0, amount);
+}
+
+// No setclock2fromstate.
+
+function adjustclockfromstate(num)
+{
+ let amount = parseInt(state['clock_min']) * 60 + parseInt(state['clock_sec']);
+ let elapsed = time_elapsed_raw(num);
+ if (Math.abs(amount - elapsed) >= 2.0) {
+ setclock(num, amount);
+ }
}
function setclocklimitfromstate()
if (state['image'] === undefined) {
img.style.display = 'none';
} else {
- img.src = state['image'];
+ img.src = state['image'];
img.style.display = 'inline';
}
showlowerthird();
lowerthird_visible = false;
}
-function time_elapsed()
+function set_sound_shark_volume_db(volume_db)
+{
+ let img = document.getElementById('lowerthird-img');
+ let should_enable = (volume_db > -40.0);
+ let currently_enabled = (img.style.display === 'inline' && img.src.match(/microphone\.png$/));
+
+ if (should_enable === currently_enabled) {
+ return;
+ }
+
+ if (should_enable) {
+ img.style.display = 'inline';
+ img.src = 'generic/microphone.png';
+ document.getElementById('lowerthird-picture').className = 'lowerthird-picture lowerthird-picture-animate-in';
+ document.getElementById('lowerthird-picture-content').className = 'lowerthird-picture-content lowerthird-picture-content-animate-in';
+ } else {
+ 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';
+ }
+}
+
+function time_elapsed_raw(num)
{
- let elapsed = (Date.now() - clock_origin) * 1e-3;
- if (clock_elapsed + elapsed >= clock_limit) {
- clock_elapsed = clock_limit;
- clock_origin = Date.now();
- clock_running = false;
+ let elapsed = (Date.now() - clocks[num].origin) * 1e-3;
+ if (clocks[num].elapsed + elapsed >= clock_limit) {
+ console.log("limit for", num);
+ if (num == 0) {
+ clocks[num].elapsed = clock_limit;
+ clocks[num].origin = Date.now();
+ clocks[num].running = false;
+
+ if (state['autocomment_on_clock_limit'] == '1' && !comment_visible) {
+ state['comment'] = state['autocomment'];
+ setcomment();
+ showcomment();
+ }
+ }
+
return clock_limit;
}
- return Math.floor(clock_elapsed + elapsed);
+ return clocks[num].elapsed + elapsed;
+}
+
+function time_elapsed(num)
+{
+ return Math.floor(time_elapsed_raw(num));
}
-function update_clock()
+function update_given_clock(elapsed, id)
{
- let elapsed = time_elapsed();
let min = Math.floor(elapsed / 60);
let sec = elapsed % 60;
if (sec < 10) sec = "0" + sec;
- document.getElementById('clock').innerHTML = min + ":" + sec;
+ let text = min + ":" + sec;
+
+ if (ultimateconfig['exohack']) {
+ // 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(id).innerHTML = html;
+ } else {
+ document.getElementById(id).innerHTML = text;
+ }
+}
+
+function update_clock(num)
+{
+ update_given_clock(time_elapsed(num), clocks[num].id);
}
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';
}
setInterval(function() {
- if (clock_running) {
- update_clock();
+ for (let i = 0; i < num_clocks; ++i) {
+ if (clocks[i].running) {
+ update_clock(i);
+ }
}
}, 100);
update_score();