]> git.sesse.net Git - ultimatescore/commitdiff
A small clock refactoring.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 12 Oct 2019 11:46:32 +0000 (13:46 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 12 Oct 2019 11:46:32 +0000 (13:46 +0200)
score.js

index ab07189d53b872513e2b9ccf3f3184ba572b3cae..f8bb712e58f491b74bafc39eb63d5a378c69b3a9 100644 (file)
--- a/score.js
+++ b/score.js
@@ -245,9 +245,8 @@ function time_elapsed2()
        return Math.floor(time_elapsed2_raw());
 }
 
-function update_clock()
+function update_given_clock(elapsed, id)
 {
-       let elapsed = time_elapsed();
        let min = Math.floor(elapsed / 60);
        let sec = elapsed % 60;
 
@@ -266,37 +265,20 @@ function update_clock()
                                html += "<div style='display: inline-block; width: 15px'>" + text.charAt(i) + "</div>";
                        }
                }
-               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()
 {
-       let elapsed = time_elapsed2();
-       let min = Math.floor(elapsed / 60);
-       let sec = elapsed % 60;
-
-       if (sec < 10) sec = "0" + sec;
-       let text = min + ":" + sec;
+       update_given_clock(time_elapsed(), 'clock');
+}
 
-       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('clock2').innerHTML = html;
-       } else {
-               document.getElementById('clock2').innerHTML = text;
-       }
+function update_clock2()
+{
+       update_given_clock(time_elapsed2(), 'clock2');
 }
 
 function goalA()