]> git.sesse.net Git - ultimatescore/blobdiff - score.js
Use common name and not team code for ranking lists.
[ultimatescore] / score.js
index 1d28e4cf2308015377b98626ea629003bb7e3b4c..f8bb712e58f491b74bafc39eb63d5a378c69b3a9 100644 (file)
--- a/score.js
+++ b/score.js
@@ -1,14 +1,18 @@
 '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()
@@ -20,6 +24,12 @@ 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'];
@@ -33,6 +43,13 @@ function setscore()
        update_score();
 }
 
+function setscore2()
+{
+       scoreA = state['score1'];
+       scoreB = state['score2'];
+       document.getElementById('score2_score').innerHTML = scoreA + " – " + scoreB;
+}
+
 function startclock()
 {
        if (!clock_running) {
@@ -42,6 +59,15 @@ function startclock()
        showclock();
 }
 
+function startclock2()
+{
+       if (!clock2_running) {
+               clock2_origin = Date.now();
+               clock2_running = true;
+       }
+       // No showclock.
+}
+
 function stopclock()
 {
        if (!clock_running) return;
@@ -50,6 +76,14 @@ function stopclock()
        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;
@@ -57,12 +91,39 @@ function setclock(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']);
@@ -145,26 +206,79 @@ function hidelowerthird()
        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_elapsed = clock_limit;
                clock_origin = Date.now();
                clock_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 clock_elapsed + elapsed;
 }
 
-function update_clock()
+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_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()
+{
+       update_given_clock(time_elapsed(), 'clock');
+}
+
+function update_clock2()
+{
+       update_given_clock(time_elapsed2(), 'clock2');
 }
 
 function goalA()
@@ -202,7 +316,7 @@ function update_score()
        document.getElementById('score').innerHTML = scoreA + "&nbsp;–&nbsp;" + scoreB;
 }
 
-/* called by caspar only */
+/* called by the Nageru theme only */
 function play()
 {
        document.getElementById('manualcontrols').style.display = 'none';
@@ -220,6 +334,9 @@ setInterval(function() {
        if (clock_running) {
                update_clock();
        }
+       if (clock2_running) {
+               update_clock2();
+       }
 }, 100);
 update_score();