X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=score.js;h=67099a8cb4b6620471d4072288b5bcacd6063139;hb=ec9e61b284e06fa90db188909bb94c62474b2627;hp=17ac07c4f8a679b7ec2466b59a1c6a43135be7ce;hpb=7acfe5e3d4efcbc670e7acd5c7ea7d61f6ba24d5;p=ultimatescore diff --git a/score.js b/score.js index 17ac07c..67099a8 100644 --- a/score.js +++ b/score.js @@ -63,6 +63,15 @@ function setclockfromstate() setclock(amount); } +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 setclocklimitfromstate() { let amount = parseInt(state['clock_limit_min']) * 60 + parseInt(state['clock_limit_sec']); @@ -145,7 +154,7 @@ 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) { @@ -154,7 +163,12 @@ function time_elapsed() clock_running = false; return clock_limit; } - return Math.floor(clock_elapsed + elapsed); + return clock_elapsed + elapsed; +} + +function time_elapsed() +{ + return Math.floor(time_elapsed_raw()); } function update_clock() @@ -164,7 +178,24 @@ 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 += "
" + text.charAt(i) + "
"; + } + } + document.getElementById('clock').innerHTML = html; + } else { + document.getElementById('clock').innerHTML = text; + } } function goalA()