From: b Date: Sat, 14 Mar 2026 14:12:31 +0000 (+0000) Subject: limit timer to 6 digits, with saturation up to Z X-Git-Tag: v1.2.13 X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=HEAD;p=ott%2Fbsta limit timer to 6 digits, with saturation up to Z --- diff --git a/bsta_lib.1.pm b/bsta_lib.1.pm index 10d70a4..8fdb861 100644 --- a/bsta_lib.1.pm +++ b/bsta_lib.1.pm @@ -2,7 +2,7 @@ # # Library of functions # -# Copyright (C) 2016, 2017, 2019, 2020, 2022, 2023, 2024, 2025 Balthasar Szczepański +# Copyright (C) 2016, 2017, 2019, 2020, 2022, 2023, 2024, 2025, 2026 Balthasar Szczepański # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -667,6 +667,84 @@ sub debug { return $text; } +sub make_timer_digit { + (my $i) = @_; + + if ($i < 0) { + return '-'; + } + elsif ($i < 10) { + return chr($i + ord('0')); + } + elsif ($i < 36) { + return chr($i - 10 + ord('A')); + } + else { + return '-'; + } +} + +sub make_timer { + (my $timer, my $full_timer, my $frame, my $ong_state) = @_; + + if ( + ($timer > 0) || + (($timer >= 0) && ($frame == 0)) + ) {} + elsif (($timer >= -15) && ($ong_state >= STATE->{'ready'})) { + return '00','00','NG'; + } + else { + return 'EE','EE','EE'; + } + + my $tc = 40271; # 11:11:11 + my $max_digit; + + if ($full_timer <= $tc * 9) { #99:99:99 + $max_digit = 9; + } + elsif ($full_timer <= $tc * 15) { # FF:FF:FF + $max_digit = 15; # F + } + elsif ($full_timer > $tc * 34) { # YY:YY:YY + $max_digit = 35; # Z + } + else { + $max_digit = int(($full_timer - 1) / $tc + 1); # A-Y + } + + my $saturation = $tc * $max_digit; + + if ($timer > $saturation) { + return '--', '--', '--'; + } + + my @base = (10, 6, 10, 6, 10, 10); + my @digit; + + for my $i (0..5) { + $saturation -= $max_digit; + if ($timer >= $saturation) { + $digit[$i] = $timer - $saturation; + if ($digit[$i] > $max_digit) { + $digit[$i] = $max_digit; + } + } + else { + $digit[$i] = $timer % $base[$i]; + $timer = int($timer / $base[$i]); + $saturation = int($saturation / $base[$i]); + } + } + + return ( + make_timer_digit($digit[5]).make_timer_digit($digit[4]), + make_timer_digit($digit[3]).make_timer_digit($digit[2]), + make_timer_digit($digit[1]).make_timer_digit($digit[0]) + ); +} + sub print_html_start { (my $fh) = @_; @@ -907,6 +985,8 @@ sub print_viewer_page { my $timer = int($context->{'timer'}); # my $words_page = int($context->{'words_page'}); + my $full_timer = int($state->{'ongtime'}) * 3600; + my $prev_frame = $frame - 1; my $next_frame = $frame + 1; @@ -927,28 +1007,9 @@ sub print_viewer_page { my $timer_color_m = (($timer_unlocked >= 2) || ($ong_state >= STATE->{'ready'})) ? 'br' : 'ni'; my $timer_color_s = (($timer_unlocked >= 3) || ($ong_state >= STATE->{'ready'})) ? 'br' : 'ni'; - my $timer_h; - my $timer_m; - my $timer_s; - if ( - ($timer > 0) || - (($timer >= 0) && ($frame == 0)) - ) { - $timer_s = sprintf('%02d', $timer % 60); - $timer_h = int($timer / 60); - $timer_m = sprintf('%02d', $timer_h % 60); - $timer_h = sprintf('%02d', $timer_h / 60); - } - elsif (($timer >= -15) && ($ong_state >= STATE->{'ready'})) { - $timer_h = '00'; - $timer_m = '00'; - $timer_s = 'NG'; - } - else { - $timer_h = 'EE'; - $timer_m = 'EE'; - $timer_s = 'EE'; - } + (my $timer_h, my $timer_m, my $timer_s) = make_timer( + $timer, $full_timer, $frame, $ong_state + ); my $show_ongtime = (($frame_data->{'ongtime'} ne '') && (!$launch)); my $ongtime = ''; diff --git a/settings.txt b/settings.txt index 25181e1..a61dc98 100644 --- a/settings.txt +++ b/settings.txt @@ -1,6 +1,6 @@ # settings.txt # -# Copyright (C) 2023, 2024, 2025 Balthasar Szczepański +# Copyright (C) 2023, 2024, 2025, 2026 Balthasar Szczepański # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -15,7 +15,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -_version: 1.2.12 +_version: 1.2.13 _SHEBANG: #!$0 diff --git a/timer.js b/timer.js index 964763f..11b2ca0 100644 --- a/timer.js +++ b/timer.js @@ -3,7 +3,7 @@ // The countdown script. // // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0 -// Copyright (C) 2017, 2024 Balthasar Szczepański +// Copyright (C) 2017, 2024, 2026 Balthasar Szczepański // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -20,6 +20,25 @@ // @license-end var enabled = false; +var valid = false; + +function d2i (d) { + if (d >= '0' && d <= '9') + return d.charCodeAt(0) - '0'.charCodeAt(0); + if (d >= 'A' && d <= 'Z') + return d.charCodeAt(0) - 'A'.charCodeAt(0) + 10; + return NaN; +} + +function i2d (i) { + if (i < 0) + return '-'; + if (i < 10) + return String.fromCharCode(i + '0'.charCodeAt(0)); + if (i < 36) + return String.fromCharCode(i - 10 + 'A'.charCodeAt(0)); + return '-'; +} window.onload = function () { var e_h; @@ -28,68 +47,100 @@ window.onload = function () { var h; var m; var s; + var hms; + var digits; var countdown; var timer; + var base = [10, 6, 10, 6, 10, 10]; e_h = document.getElementById("ongh"); e_m = document.getElementById("ongm"); e_s = document.getElementById("ongs"); - h = +(e_h.innerHTML); - m = +(e_m.innerHTML); - s = +(e_s.innerHTML); + if (e_h == null || e_m == null || e_s == null) { + // window.alert("NUL"); + return; + } + + h = e_h.innerHTML; + m = e_m.innerHTML; + s = e_s.innerHTML; + + if (h.length != 2 || m.length != 2 || s.length != 2) { + // window.alert("LENGTH"); + return; + } + + hms = h + ":" + m + ":" + s; + + if ( + hms == "00:00:NG" || + hms == "EE:EE:EE" || + hms == "--:--:--" + ) { + // window.alert("INACTIVE"); + return; + } + + digits = []; + digits[0] = d2i(s[1]); + digits[1] = d2i(s[0]); + digits[2] = d2i(m[1]); + digits[3] = d2i(m[0]); + digits[4] = d2i(h[1]); + digits[5] = d2i(h[0]); timer = document.getElementById("timer"); timer.onclick = function () { enabled = !enabled; + if (enabled && valid) { + e_h.innerHTML = h; + e_m.innerHTML = m; + e_s.innerHTML = s; + } } - if (e_h == null || e_m == null || e_s == null) { - // window.alert("NUL"); - } - else { - countdown = setInterval (function() { - if(isNaN(h) || isNaN(m) || isNaN(s)) { + countdown = setInterval (function() { + var stop = true; + for (var i=0; i<6; ++i) { + if (isNaN(digits[i])) { // window.alert("NAN"); clearInterval(countdown); return; } - - if (s > 0) { - s -= 1; - } - else { - s = 59; - if (m > 0) { - m -= 1; - } - else { - m == 59; - if (h > 0) { - h -= 1; - } - else { - m = 0; - s = 0; - } - } + if (digits[i] > 0) { + --digits[i]; + stop = false; + break; } - - if (enabled) { - if (h == 0 && m == 0 && s == 0) { - e_h.innerHTML = "00"; - e_m.innerHTML = "00"; - e_s.innerHTML = "NG"; - // window.alert("ONG"); - clearInterval(countdown); - return; - } - else { - e_h.innerHTML = ((h < 10) ? "0" : "") + h; - e_m.innerHTML = ((m < 10) ? "0" : "") + m; - e_s.innerHTML = ((s < 10) ? "0" : "") + s; - } - } - }, 1000); - } + digits[i] = base[i] - 1; + } + if (stop) { + // window.alert("STOP"); + clearInterval(countdown); + return; + } + if ( + digits[0] == 0 && digits[1] == 0 && + digits[2] == 0 && digits[3] == 0 && + digits[4] == 0 && digits[5] == 0 + ) { + h = "00"; + m = "00"; + s = "NG"; + // window.alert("ONG"); + clearInterval(countdown); + } + else { + h = i2d(digits[5]) + i2d(digits[4]); + m = i2d(digits[3]) + i2d(digits[2]); + s = i2d(digits[1]) + i2d(digits[0]); + } + if (enabled) { + e_h.innerHTML = h; + e_m.innerHTML = m; + e_s.innerHTML = s; + } + valid = true; + }, 1000); };