X-Git-Url: https://git.sesse.net/?p=ultimatescore;a=blobdiff_plain;f=score.js;h=22b909903fb3f5c58975cf74c8751f662c1d5697;hp=ab07189d53b872513e2b9ccf3f3184ba572b3cae;hb=HEAD;hpb=d62c9b9a3b3b221778baaae54c22156acd8d403d diff --git a/score.js b/score.js index ab07189..ab3e465 100644 --- a/score.js +++ b/score.js @@ -1,18 +1,18 @@ 'use strict'; -let clock_running = false; -let clock2_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 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() @@ -30,6 +30,12 @@ function setteams2() 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']; @@ -50,77 +56,59 @@ function setscore2() document.getElementById('score2_score').innerHTML = scoreA + " â€“ " + scoreB; } -function startclock() +function setscore3() { - if (!clock_running) { - clock_origin = Date.now(); - clock_running = true; - } - showclock(); + scoreA = state['score1']; + scoreB = state['score2']; + document.getElementById('score3_score').innerHTML = scoreA + " â€“ " + scoreB; } -function startclock2() +function startclock(num) { - if (!clock2_running) { - clock2_origin = Date.now(); - clock2_running = true; + if (!clocks[num].running) { + clocks[num].origin = Date.now(); + clocks[num].running = true; + } + if (num == 0) { + showclock(); } - // No 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 stopclock2() +function setclock(num, amount) { - if (!clock2_running) return; - clock2_elapsed = time2_elapsed(); - clock2_origin = Date.now(); - clock2_running = false; -} + clocks[num].elapsed = amount; + clocks[num].origin = Date.now(); + update_clock(num); -function setclock(amount) -{ - clock_elapsed = amount; - clock_origin = Date.now(); - update_clock(); -} - -function setclock2(amount) -{ - clock2_elapsed = amount; - clock2_origin = Date.now(); - update_clock2(); + // 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() +function adjustclockfromstate(num) { let amount = parseInt(state['clock_min']) * 60 + parseInt(state['clock_sec']); - let elapsed = time_elapsed_raw(); + let elapsed = time_elapsed_raw(num); 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); + setclock(num, amount); } } @@ -188,7 +176,7 @@ function setandshowlowerthird() if (state['image'] === undefined) { img.style.display = 'none'; } else { - img.src = state['image']; + img.src = state['image']; img.style.display = 'inline'; } showlowerthird(); @@ -206,48 +194,56 @@ function hidelowerthird() lowerthird_visible = false; } -function time_elapsed_raw() +function set_sound_shark_volume_db(volume_db) { - 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 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 (state['autocomment_on_clock_limit'] == '1' && !comment_visible) { - state['comment'] = state['autocomment']; - setcomment(); - showcomment(); - } + if (should_enable === currently_enabled) { + return; + } - return clock_limit; + 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'; } - return clock_elapsed + elapsed; } -function time_elapsed2_raw() +function time_elapsed_raw(num) { - let elapsed = (Date.now() - clock2_origin) * 1e-3; - if (clock2_elapsed + elapsed >= clock_limit) { - // No separate clock 2 limit. + 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 clock2_elapsed + elapsed; + return clocks[num].elapsed + elapsed; } -function time_elapsed() +function time_elapsed(num) { - return Math.floor(time_elapsed_raw()); + return Math.floor(time_elapsed_raw(num)); } -function time_elapsed2() +function update_given_clock(elapsed, id) { - return Math.floor(time_elapsed2_raw()); -} - -function update_clock() -{ - let elapsed = time_elapsed(); let min = Math.floor(elapsed / 60); let sec = elapsed % 60; @@ -266,37 +262,15 @@ function update_clock() html += "
" + text.charAt(i) + "
"; } } - document.getElementById('clock').innerHTML = html; + document.getElementById(id).innerHTML = html; } else { - document.getElementById('clock').innerHTML = text; + document.getElementById(id).innerHTML = text; } } -function update_clock2() +function update_clock(num) { - let elapsed = time_elapsed2(); - let min = Math.floor(elapsed / 60); - let sec = elapsed % 60; - - if (sec < 10) sec = "0" + 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 += "
" + text.charAt(i) + "
"; - } - } - document.getElementById('clock2').innerHTML = html; - } else { - document.getElementById('clock2').innerHTML = text; - } + update_given_clock(time_elapsed(num), clocks[num].id); } function goalA() @@ -349,11 +323,10 @@ function update(v) } setInterval(function() { - if (clock_running) { - update_clock(); - } - if (clock2_running) { - update_clock2(); + for (let i = 0; i < num_clocks; ++i) { + if (clocks[i].running) { + update_clock(i); + } } }, 100); update_score();