diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-11-04 09:49:24 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-11-04 09:49:24 -0400 |
commit | b0481b17cbb177d329c67cfe5abd5f76365ceefd (patch) | |
tree | 8e44927d1d1e778518d6d0c77fcaf0120dc3b2c6 /app | |
parent | 1dcb14df464d74d85bb90000f5936c76cbfd8a60 (diff) | |
download | wittle-b0481b17cbb177d329c67cfe5abd5f76365ceefd.tar.gz wittle-b0481b17cbb177d329c67cfe5abd5f76365ceefd.tar.bz2 wittle-b0481b17cbb177d329c67cfe5abd5f76365ceefd.zip |
more accurate puzzle timer
Diffstat (limited to 'app')
-rw-r--r-- | app/views/wittle/puzzles/_handle_puzzle.html.erb | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/app/views/wittle/puzzles/_handle_puzzle.html.erb b/app/views/wittle/puzzles/_handle_puzzle.html.erb index be9166a..81bca29 100644 --- a/app/views/wittle/puzzles/_handle_puzzle.html.erb +++ b/app/views/wittle/puzzles/_handle_puzzle.html.erb | |||
@@ -1,23 +1,25 @@ | |||
1 | <script type="text/javascript"> | 1 | <script type="text/javascript"> |
2 | var totalSeconds = 0 | 2 | var totalSeconds = 0 |
3 | var startTime = 0 | ||
3 | var timerInterval | 4 | var timerInterval |
4 | 5 | ||
6 | function pad(val) { | ||
7 | var valString = val + "" | ||
8 | if (valString.length < 2) | ||
9 | { | ||
10 | return "0" + valString | ||
11 | } else { | ||
12 | return valString | ||
13 | } | ||
14 | } | ||
15 | function setTime() { | ||
16 | totalSeconds = Math.floor((Date.now() - startTime) / 1000) | ||
17 | $("#seconds").text(pad(totalSeconds%60)) | ||
18 | $("#minutes").text(pad(parseInt(totalSeconds/60))) | ||
19 | } | ||
20 | |||
5 | window.onload = function() { | 21 | window.onload = function() { |
6 | <% if @playable %> | 22 | <% if @playable %> |
7 | function pad(val) { | ||
8 | var valString = val + "" | ||
9 | if (valString.length < 2) | ||
10 | { | ||
11 | return "0" + valString | ||
12 | } else { | ||
13 | return valString | ||
14 | } | ||
15 | } | ||
16 | function setTime() { | ||
17 | ++totalSeconds | ||
18 | $("#seconds").text(pad(totalSeconds%60)) | ||
19 | $("#minutes").text(pad(parseInt(totalSeconds/60))) | ||
20 | } | ||
21 | $("#sens").val(window.settings.sensitivity) | 23 | $("#sens").val(window.settings.sensitivity) |
22 | $("#sens").on("change", function() { | 24 | $("#sens").on("change", function() { |
23 | window.settings.sensitivity = this.value | 25 | window.settings.sensitivity = this.value |
@@ -37,6 +39,7 @@ window.onload = function() { | |||
37 | 39 | ||
38 | $("#activation-button").hide() | 40 | $("#activation-button").hide() |
39 | 41 | ||
42 | startTime = Date.now() | ||
40 | timerInterval = setInterval(setTime, 1000); | 43 | timerInterval = setInterval(setTime, 1000); |
41 | 44 | ||
42 | $.ajax({ | 45 | $.ajax({ |
@@ -56,6 +59,7 @@ window.onload = function() { | |||
56 | <% if @playable %> | 59 | <% if @playable %> |
57 | window.TRACE_COMPLETION_FUNC = function(puzzle, rawPath) { | 60 | window.TRACE_COMPLETION_FUNC = function(puzzle, rawPath) { |
58 | clearInterval(timerInterval) | 61 | clearInterval(timerInterval) |
62 | setTime() | ||
59 | 63 | ||
60 | $.ajax({ | 64 | $.ajax({ |
61 | type: "POST", | 65 | type: "POST", |