about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-10-29 21:04:43 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-10-29 21:04:43 -0400
commit03f44c53e35fc1643a39a1e31141ead8c275a3a0 (patch)
tree74e9e1e5086c9739a13500793378012838b8a3dd
parent862cb4e3f9b9864bc1b5a20cd7ebd7c4d6cccb77 (diff)
downloadwittle-03f44c53e35fc1643a39a1e31141ead8c275a3a0.tar.gz
wittle-03f44c53e35fc1643a39a1e31141ead8c275a3a0.tar.bz2
wittle-03f44c53e35fc1643a39a1e31141ead8c275a3a0.zip
disable sending a time if you refresh the page
-rw-r--r--app/controllers/wittle/puzzles_controller.rb8
-rw-r--r--app/views/wittle/puzzles/_handle_puzzle.html.erb75
-rw-r--r--app/views/wittle/puzzles/show.html.haml13
-rw-r--r--config/routes.rb1
4 files changed, 59 insertions, 38 deletions
diff --git a/app/controllers/wittle/puzzles_controller.rb b/app/controllers/wittle/puzzles_controller.rb index ed7087a..2949f94 100644 --- a/app/controllers/wittle/puzzles_controller.rb +++ b/app/controllers/wittle/puzzles_controller.rb
@@ -12,6 +12,14 @@ module Wittle
12 def show 12 def show
13 @puzzle = Puzzle.find(params[:id]) 13 @puzzle = Puzzle.find(params[:id])
14 @playable = @puzzle.latest? && !((session[:played_puzzles] || []).include? @puzzle.id) 14 @playable = @puzzle.latest? && !((session[:played_puzzles] || []).include? @puzzle.id)
15 @already_started = ((session[:started_puzzles] || []).include? @puzzle.id)
16 end
17
18 def start
19 @puzzle = Puzzle.find(params[:id])
20
21 session[:started_puzzles] ||= []
22 session[:started_puzzles] << @puzzle.id
15 end 23 end
16 24
17 def solve 25 def solve
diff --git a/app/views/wittle/puzzles/_handle_puzzle.html.erb b/app/views/wittle/puzzles/_handle_puzzle.html.erb index 3d593a4..be9166a 100644 --- a/app/views/wittle/puzzles/_handle_puzzle.html.erb +++ b/app/views/wittle/puzzles/_handle_puzzle.html.erb
@@ -4,41 +4,52 @@ var timerInterval
4 4
5window.onload = function() { 5window.onload = function() {
6 <% if @playable %> 6 <% if @playable %>
7 function pad(val) { 7 function pad(val) {
8 var valString = val + "" 8 var valString = val + ""
9 if (valString.length < 2) 9 if (valString.length < 2)
10 { 10 {
11 return "0" + valString 11 return "0" + valString
12 } else { 12 } else {
13 return valString 13 return valString
14 }
14 } 15 }
15 } 16 function setTime() {
16 function setTime() { 17 ++totalSeconds
17 ++totalSeconds 18 $("#seconds").text(pad(totalSeconds%60))
18 $("#seconds").text(pad(totalSeconds%60)) 19 $("#minutes").text(pad(parseInt(totalSeconds/60)))
19 $("#minutes").text(pad(parseInt(totalSeconds/60))) 20 }
20 } 21 $("#sens").val(window.settings.sensitivity)
21 $("#sens").val(window.settings.sensitivity) 22 $("#sens").on("change", function() {
22 $("#sens").on("change", function() { 23 window.settings.sensitivity = this.value
23 window.settings.sensitivity = this.value 24 })
24 }) 25 $("#volume").val(parseFloat(window.settings.volume))
25 $("#volume").val(parseFloat(window.settings.volume)) 26 $("#volume").on("change", function() {
26 $("#volume").on("change", function() { 27 window.settings.volume = this.value
27 window.settings.volume = this.value 28 })
28 })
29 $("#activation-button button").on("click", function() {
30 var puzzle = window.deserializePuzzle("<%= @puzzle.data %>")
31 draw(puzzle)
32 29
33 $("#activation-button").hide() 30 <% if @already_started %>
31 var puzzle = window.deserializePuzzle("<%= @puzzle.data %>")
32 draw(puzzle)
33 <% else %>
34 $("#activation-button button").on("click", function() {
35 var puzzle = window.deserializePuzzle("<%= @puzzle.data %>")
36 draw(puzzle)
34 37
35 timerInterval = setInterval(setTime, 1000); 38 $("#activation-button").hide()
36 }) 39
40 timerInterval = setInterval(setTime, 1000);
41
42 $.ajax({
43 type: "POST",
44 url: "<%= start_puzzle_path(@puzzle, format: :js) %>"
45 })
46 })
47 <% end %>
37 <% else %> 48 <% else %>
38 var puzzle = window.deserializePuzzle("<%= @puzzle.data %>") 49 var puzzle = window.deserializePuzzle("<%= @puzzle.data %>")
39 draw(puzzle) 50 draw(puzzle)
40 drawPath(puzzle, JSON.parse("<%= escape_javascript(sanitize @puzzle.solved_data) %>")) 51 drawPath(puzzle, JSON.parse("<%= escape_javascript(sanitize @puzzle.solved_data) %>"))
41 window.trace = function() {} 52 window.trace = function() {}
42 <% end %> 53 <% end %>
43} 54}
44 55
@@ -49,7 +60,7 @@ window.TRACE_COMPLETION_FUNC = function(puzzle, rawPath) {
49 $.ajax({ 60 $.ajax({
50 type: "POST", 61 type: "POST",
51 url: "<%= solve_puzzle_path(@puzzle, format: :js) %>", 62 url: "<%= solve_puzzle_path(@puzzle, format: :js) %>",
52 data: { solved: JSON.stringify(rawPath), time: totalSeconds } 63 data: { solved: JSON.stringify(rawPath) <% unless @already_started %> , time: totalSeconds <% end %> }
53 }) 64 })
54} 65}
55 66
diff --git a/app/views/wittle/puzzles/show.html.haml b/app/views/wittle/puzzles/show.html.haml index deda344..c46e5ce 100644 --- a/app/views/wittle/puzzles/show.html.haml +++ b/app/views/wittle/puzzles/show.html.haml
@@ -3,12 +3,13 @@
3 %svg#puzzle{ style: "pointer-events: auto"} 3 %svg#puzzle{ style: "pointer-events: auto"}
4#submission-form 4#submission-form
5- if @playable 5- if @playable
6 #activation-button 6 - unless @already_started
7 %button{ type: "button" } Reveal Puzzle 7 #activation-button
8 #timer 8 %button{ type: "button" } Reveal Puzzle
9 %label#minutes 00 9 #timer
10 %label#colon : 10 %label#minutes 00
11 %label#seconds 00 11 %label#colon :
12 %label#seconds 00
12 %details#trace-settings 13 %details#trace-settings
13 %summary Settings 14 %summary Settings
14 .things 15 .things
diff --git a/config/routes.rb b/config/routes.rb index 8cae7ec..346315e 100644 --- a/config/routes.rb +++ b/config/routes.rb
@@ -2,6 +2,7 @@ Wittle::Engine.routes.draw do
2 root to: 'puzzles#about' 2 root to: 'puzzles#about'
3 get 'archive' => 'puzzles#index' 3 get 'archive' => 'puzzles#index'
4 get ':id' => 'puzzles#show', as: 'puzzle' 4 get ':id' => 'puzzles#show', as: 'puzzle'
5 post ':id/start' => 'puzzles#start', as: 'start_puzzle'
5 post ':id/solve' => 'puzzles#solve', as: 'solve_puzzle' 6 post ':id/solve' => 'puzzles#solve', as: 'solve_puzzle'
6 post ':id/submit' => 'puzzles#submit', as: 'submit_puzzle' 7 post ':id/submit' => 'puzzles#submit', as: 'submit_puzzle'
7end 8end