From 1bc945a9874722d1e0d236265f607f6fa78f609d Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 4 Nov 2023 10:02:01 -0400 Subject: show player's own solution on show page --- app/controllers/wittle/puzzles_controller.rb | 11 +++++++++++ app/views/wittle/puzzles/_handle_puzzle.html.erb | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/wittle/puzzles_controller.rb b/app/controllers/wittle/puzzles_controller.rb index b481460..8dc2ac8 100644 --- a/app/controllers/wittle/puzzles_controller.rb +++ b/app/controllers/wittle/puzzles_controller.rb @@ -22,6 +22,14 @@ module Wittle @puzzle = Puzzle.find(params[:id]) @playable = @puzzle.latest? && !((session[:played_puzzles] || []).include? @puzzle.id) @already_started = ((session[:started_puzzles] || []).include? @puzzle.id) + + unless @playable + if (session[:puzzle_solutions] || {}).has_key? @puzzle.id.to_s + @solution = session[:puzzle_solutions][@puzzle.id.to_s] + else + @solution = @puzzle.solved_data + end + end end def start @@ -45,6 +53,9 @@ module Wittle session[:played_puzzles] ||= [] session[:played_puzzles] << @puzzle.id + + session[:puzzle_solutions] ||= {} + session[:puzzle_solutions][@puzzle.id] = params[:solved] end def submit diff --git a/app/views/wittle/puzzles/_handle_puzzle.html.erb b/app/views/wittle/puzzles/_handle_puzzle.html.erb index 81bca29..e451745 100644 --- a/app/views/wittle/puzzles/_handle_puzzle.html.erb +++ b/app/views/wittle/puzzles/_handle_puzzle.html.erb @@ -51,7 +51,7 @@ window.onload = function() { <% else %> var puzzle = window.deserializePuzzle("<%= @puzzle.data %>") draw(puzzle) - drawPath(puzzle, JSON.parse("<%= escape_javascript(sanitize @puzzle.solved_data) %>")) + drawPath(puzzle, JSON.parse("<%= escape_javascript(sanitize @solution) %>")) window.trace = function() {} <% end %> } -- cgit 1.4.1