diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/audio/panel_abort_tracing.aac (renamed from app/assets/audio/wittle/panel_abort_tracing.aac) | bin | 5606 -> 5606 bytes | |||
-rw-r--r-- | app/assets/audio/panel_failure.aac (renamed from app/assets/audio/wittle/panel_failure.aac) | bin | 8543 -> 8543 bytes | |||
-rw-r--r-- | app/assets/audio/panel_start_tracing.aac (renamed from app/assets/audio/wittle/panel_start_tracing.aac) | bin | 12082 -> 12082 bytes | |||
-rw-r--r-- | app/assets/audio/panel_success.aac (renamed from app/assets/audio/wittle/panel_success.aac) | bin | 46061 -> 46061 bytes | |||
-rw-r--r-- | app/assets/config/manifest.js | 6 | ||||
-rw-r--r-- | app/assets/config/wittle_manifest.js | 4 | ||||
-rw-r--r-- | app/assets/images/.keep (renamed from app/assets/audio/wittle/.keep) | 0 | ||||
-rw-r--r-- | app/assets/images/slider.png (renamed from app/assets/images/wittle/slider.png) | bin | 20100 -> 20100 bytes | |||
-rw-r--r-- | app/assets/images/wittle_expert.png (renamed from app/assets/images/wittle/wittle_expert.png) | bin | 155050 -> 155050 bytes | |||
-rw-r--r-- | app/assets/images/wittle_hard.png (renamed from app/assets/images/wittle/wittle_hard.png) | bin | 92194 -> 92194 bytes | |||
-rw-r--r-- | app/assets/images/wittle_header.png (renamed from app/assets/images/wittle/wittle_header.png) | bin | 82868 -> 82868 bytes | |||
-rw-r--r-- | app/assets/images/wittle_normal.png (renamed from app/assets/images/wittle/wittle_normal.png) | bin | 81341 -> 81341 bytes | |||
-rw-r--r-- | app/assets/javascripts/application.js | 2 | ||||
-rw-r--r-- | app/assets/javascripts/custom_mechanics.js (renamed from app/assets/javascripts/wittle/custom_mechanics.js) | 0 | ||||
-rw-r--r-- | app/assets/javascripts/display2.js (renamed from app/assets/javascripts/wittle/display2.js) | 0 | ||||
-rw-r--r-- | app/assets/javascripts/polyominos.js (renamed from app/assets/javascripts/wittle/polyominos.js) | 0 | ||||
-rw-r--r-- | app/assets/javascripts/puzzle.js (renamed from app/assets/javascripts/wittle/puzzle.js) | 2 | ||||
-rw-r--r-- | app/assets/javascripts/serializer.js (renamed from app/assets/javascripts/wittle/serializer.js) | 0 | ||||
-rw-r--r-- | app/assets/javascripts/solve.js (renamed from app/assets/javascripts/wittle/solve.js) | 0 | ||||
-rw-r--r-- | app/assets/javascripts/svg.js (renamed from app/assets/javascripts/wittle/svg.js) | 0 | ||||
-rw-r--r-- | app/assets/javascripts/trace2.js (renamed from app/assets/javascripts/wittle/trace2.js) | 0 | ||||
-rw-r--r-- | app/assets/javascripts/utilities.js.erb (renamed from app/assets/javascripts/wittle/utilities.js.erb) | 8 | ||||
-rw-r--r-- | app/assets/javascripts/validate.js (renamed from app/assets/javascripts/wittle/validate.js) | 0 | ||||
-rw-r--r-- | app/assets/javascripts/wittle.js (renamed from app/assets/javascripts/wittle/wittle.js) | 0 | ||||
-rw-r--r-- | app/assets/javascripts/wittle/application.js | 14 | ||||
-rw-r--r-- | app/assets/stylesheets/application.css (renamed from app/assets/stylesheets/wittle/application.css) | 6 | ||||
-rw-r--r-- | app/assets/stylesheets/general.css.scss (renamed from app/assets/stylesheets/wittle/general.css.scss) | 14 | ||||
-rw-r--r-- | app/channels/application_cable/channel.rb | 4 | ||||
-rw-r--r-- | app/channels/application_cable/connection.rb | 4 | ||||
-rw-r--r-- | app/controllers/application_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/puzzles_controller.rb | 109 | ||||
-rw-r--r-- | app/controllers/wittle/application_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/wittle/puzzles_controller.rb | 120 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/puzzles_helper.rb | 7 | ||||
-rw-r--r-- | app/helpers/wittle/application_helper.rb | 4 | ||||
-rw-r--r-- | app/helpers/wittle/puzzles_helper.rb | 9 | ||||
-rw-r--r-- | app/jobs/application_job.rb | 7 | ||||
-rw-r--r-- | app/jobs/wittle/application_job.rb | 4 | ||||
-rw-r--r-- | app/mailers/application_mailer.rb | 4 | ||||
-rw-r--r-- | app/mailers/wittle/application_mailer.rb | 6 | ||||
-rw-r--r-- | app/models/application_record.rb | 3 | ||||
-rw-r--r-- | app/models/puzzle.rb | 14 | ||||
-rw-r--r-- | app/models/score.rb | 7 | ||||
-rw-r--r-- | app/models/wittle/application_record.rb | 5 | ||||
-rw-r--r-- | app/models/wittle/puzzle.rb | 16 | ||||
-rw-r--r-- | app/models/wittle/score.rb | 9 | ||||
-rw-r--r-- | app/views/layouts/application.html.haml (renamed from app/views/layouts/wittle/application.html.haml) | 4 | ||||
-rw-r--r-- | app/views/layouts/mailer.html.erb | 13 | ||||
-rw-r--r-- | app/views/layouts/mailer.text.erb | 1 | ||||
-rw-r--r-- | app/views/puzzles/_handle_puzzle.html.erb (renamed from app/views/wittle/puzzles/_handle_puzzle.html.erb) | 0 | ||||
-rw-r--r-- | app/views/puzzles/_submission.html.haml (renamed from app/views/wittle/puzzles/_submission.html.haml) | 0 | ||||
-rw-r--r-- | app/views/puzzles/about.html.haml (renamed from app/views/wittle/puzzles/about.html.haml) | 0 | ||||
-rw-r--r-- | app/views/puzzles/index.html.haml (renamed from app/views/wittle/puzzles/index.html.haml) | 0 | ||||
-rw-r--r-- | app/views/puzzles/show.html.haml (renamed from app/views/wittle/puzzles/show.html.haml) | 0 | ||||
-rw-r--r-- | app/views/puzzles/solve.js.erb (renamed from app/views/wittle/puzzles/solve.js.erb) | 0 |
56 files changed, 202 insertions, 212 deletions
diff --git a/app/assets/audio/wittle/panel_abort_tracing.aac b/app/assets/audio/panel_abort_tracing.aac index 1871586..1871586 100644 --- a/app/assets/audio/wittle/panel_abort_tracing.aac +++ b/app/assets/audio/panel_abort_tracing.aac | |||
Binary files differ | |||
diff --git a/app/assets/audio/wittle/panel_failure.aac b/app/assets/audio/panel_failure.aac index c61fe94..c61fe94 100644 --- a/app/assets/audio/wittle/panel_failure.aac +++ b/app/assets/audio/panel_failure.aac | |||
Binary files differ | |||
diff --git a/app/assets/audio/wittle/panel_start_tracing.aac b/app/assets/audio/panel_start_tracing.aac index 9b828f1..9b828f1 100644 --- a/app/assets/audio/wittle/panel_start_tracing.aac +++ b/app/assets/audio/panel_start_tracing.aac | |||
Binary files differ | |||
diff --git a/app/assets/audio/wittle/panel_success.aac b/app/assets/audio/panel_success.aac index d6e75fe..d6e75fe 100644 --- a/app/assets/audio/wittle/panel_success.aac +++ b/app/assets/audio/panel_success.aac | |||
Binary files differ | |||
diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000..70ff62e --- /dev/null +++ b/app/assets/config/manifest.js | |||
@@ -0,0 +1,6 @@ | |||
1 | //= link_tree ../images | ||
2 | //= link_directory ../stylesheets .css | ||
3 | //= link_directory ../javascripts .js | ||
4 | //= link_tree ../../../vendor/javascript .js | ||
5 | //= link_directory ../audio .aac | ||
6 | //= link jquery.min.js | ||
diff --git a/app/assets/config/wittle_manifest.js b/app/assets/config/wittle_manifest.js deleted file mode 100644 index 46aea2a..0000000 --- a/app/assets/config/wittle_manifest.js +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | //= link_directory ../stylesheets/wittle .css | ||
2 | //= link_directory ../javascripts/wittle .js | ||
3 | //= link_directory ../audio/wittle .aac | ||
4 | //= link_directory ../images/wittle .png | ||
diff --git a/app/assets/audio/wittle/.keep b/app/assets/images/.keep index e69de29..e69de29 100644 --- a/app/assets/audio/wittle/.keep +++ b/app/assets/images/.keep | |||
diff --git a/app/assets/images/wittle/slider.png b/app/assets/images/slider.png index f093f89..f093f89 100644 --- a/app/assets/images/wittle/slider.png +++ b/app/assets/images/slider.png | |||
Binary files differ | |||
diff --git a/app/assets/images/wittle/wittle_expert.png b/app/assets/images/wittle_expert.png index b806b57..b806b57 100644 --- a/app/assets/images/wittle/wittle_expert.png +++ b/app/assets/images/wittle_expert.png | |||
Binary files differ | |||
diff --git a/app/assets/images/wittle/wittle_hard.png b/app/assets/images/wittle_hard.png index e993e9b..e993e9b 100644 --- a/app/assets/images/wittle/wittle_hard.png +++ b/app/assets/images/wittle_hard.png | |||
Binary files differ | |||
diff --git a/app/assets/images/wittle/wittle_header.png b/app/assets/images/wittle_header.png index a082f8e..a082f8e 100644 --- a/app/assets/images/wittle/wittle_header.png +++ b/app/assets/images/wittle_header.png | |||
Binary files differ | |||
diff --git a/app/assets/images/wittle/wittle_normal.png b/app/assets/images/wittle_normal.png index adc0943..adc0943 100644 --- a/app/assets/images/wittle/wittle_normal.png +++ b/app/assets/images/wittle_normal.png | |||
Binary files differ | |||
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000..e614ed0 --- /dev/null +++ b/app/assets/javascripts/application.js | |||
@@ -0,0 +1,2 @@ | |||
1 | //= require jquery3 | ||
2 | //= require_tree . | ||
diff --git a/app/assets/javascripts/wittle/custom_mechanics.js b/app/assets/javascripts/custom_mechanics.js index d4733db..d4733db 100644 --- a/app/assets/javascripts/wittle/custom_mechanics.js +++ b/app/assets/javascripts/custom_mechanics.js | |||
diff --git a/app/assets/javascripts/wittle/display2.js b/app/assets/javascripts/display2.js index ddf3968..ddf3968 100644 --- a/app/assets/javascripts/wittle/display2.js +++ b/app/assets/javascripts/display2.js | |||
diff --git a/app/assets/javascripts/wittle/polyominos.js b/app/assets/javascripts/polyominos.js index 4d8be6e..4d8be6e 100644 --- a/app/assets/javascripts/wittle/polyominos.js +++ b/app/assets/javascripts/polyominos.js | |||
diff --git a/app/assets/javascripts/wittle/puzzle.js b/app/assets/javascripts/puzzle.js index cb0b20a..4889e96 100644 --- a/app/assets/javascripts/wittle/puzzle.js +++ b/app/assets/javascripts/puzzle.js | |||
@@ -148,7 +148,7 @@ window.Puzzle = class { | |||
148 | this.grid[x] = [] | 148 | this.grid[x] = [] |
149 | for (var y=0; y<height; y++) { | 149 | for (var y=0; y<height; y++) { |
150 | if (x%2 === 1 && y%2 === 1) this.grid[x][y] = null | 150 | if (x%2 === 1 && y%2 === 1) this.grid[x][y] = null |
151 | else this.grid[x][y] = {'type':'line', 'line':LINE_NONE} | 151 | else this.grid[x][y] = {'type':'line', 'line':window.LINE_NONE} |
152 | } | 152 | } |
153 | } | 153 | } |
154 | // Performance: A large value which is === 0 to be used for pillar wrapping. | 154 | // Performance: A large value which is === 0 to be used for pillar wrapping. |
diff --git a/app/assets/javascripts/wittle/serializer.js b/app/assets/javascripts/serializer.js index 70c7f0f..70c7f0f 100644 --- a/app/assets/javascripts/wittle/serializer.js +++ b/app/assets/javascripts/serializer.js | |||
diff --git a/app/assets/javascripts/wittle/solve.js b/app/assets/javascripts/solve.js index 8695291..8695291 100644 --- a/app/assets/javascripts/wittle/solve.js +++ b/app/assets/javascripts/solve.js | |||
diff --git a/app/assets/javascripts/wittle/svg.js b/app/assets/javascripts/svg.js index c103b94..c103b94 100644 --- a/app/assets/javascripts/wittle/svg.js +++ b/app/assets/javascripts/svg.js | |||
diff --git a/app/assets/javascripts/wittle/trace2.js b/app/assets/javascripts/trace2.js index 000e60b..000e60b 100644 --- a/app/assets/javascripts/wittle/trace2.js +++ b/app/assets/javascripts/trace2.js | |||
diff --git a/app/assets/javascripts/wittle/utilities.js.erb b/app/assets/javascripts/utilities.js.erb index b621003..0414ce8 100644 --- a/app/assets/javascripts/wittle/utilities.js.erb +++ b/app/assets/javascripts/utilities.js.erb | |||
@@ -75,10 +75,10 @@ var proxy = { | |||
75 | window.settings = new Proxy({}, proxy.init()) | 75 | window.settings = new Proxy({}, proxy.init()) |
76 | 76 | ||
77 | var tracks = { | 77 | var tracks = { |
78 | 'start': new Audio(src = '<%= asset_url("wittle/panel_start_tracing.aac") %>'), | 78 | 'start': new Audio(src = '<%= asset_url("panel_start_tracing.aac") %>'), |
79 | 'success': new Audio(src = '<%= asset_url("wittle/panel_success.aac") %>'), | 79 | 'success': new Audio(src = '<%= asset_url("panel_success.aac") %>'), |
80 | 'fail': new Audio(src = '<%= asset_url("wittle/panel_failure.aac") %>'), | 80 | 'fail': new Audio(src = '<%= asset_url("panel_failure.aac") %>'), |
81 | 'abort': new Audio(src = '<%= asset_url("wittle/panel_abort_tracing.aac") %>'), | 81 | 'abort': new Audio(src = '<%= asset_url("panel_abort_tracing.aac") %>'), |
82 | } | 82 | } |
83 | 83 | ||
84 | var currentAudio = null | 84 | var currentAudio = null |
diff --git a/app/assets/javascripts/wittle/validate.js b/app/assets/javascripts/validate.js index d6e6484..d6e6484 100644 --- a/app/assets/javascripts/wittle/validate.js +++ b/app/assets/javascripts/validate.js | |||
diff --git a/app/assets/javascripts/wittle/wittle.js b/app/assets/javascripts/wittle.js index 883a4b8..883a4b8 100644 --- a/app/assets/javascripts/wittle/wittle.js +++ b/app/assets/javascripts/wittle.js | |||
diff --git a/app/assets/javascripts/wittle/application.js b/app/assets/javascripts/wittle/application.js deleted file mode 100644 index 52d2214..0000000 --- a/app/assets/javascripts/wittle/application.js +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files | ||
2 | // listed below. | ||
3 | // | ||
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, | ||
5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. | ||
6 | // | ||
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the | ||
8 | // compiled file. JavaScript code in this file should be added after the last require_* statement. | ||
9 | // | ||
10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details | ||
11 | // about supported directives. | ||
12 | // | ||
13 | //= require jquery3 | ||
14 | //= require_tree . | ||
diff --git a/app/assets/stylesheets/wittle/application.css b/app/assets/stylesheets/application.css index 0ebd7fe..288b9ab 100644 --- a/app/assets/stylesheets/wittle/application.css +++ b/app/assets/stylesheets/application.css | |||
@@ -2,11 +2,11 @@ | |||
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files | 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files |
3 | * listed below. | 3 | * listed below. |
4 | * | 4 | * |
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, | 5 | * Any CSS (and SCSS, if configured) file within this directory, lib/assets/stylesheets, or any plugin's |
6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. | 6 | * vendor/assets/stylesheets directory can be referenced here using a relative path. |
7 | * | 7 | * |
8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the | 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the |
9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS | 9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS |
10 | * files in this directory. Styles in this file should be added after the last require_* statement. | 10 | * files in this directory. Styles in this file should be added after the last require_* statement. |
11 | * It is generally better to create a new file per style scope. | 11 | * It is generally better to create a new file per style scope. |
12 | * | 12 | * |
diff --git a/app/assets/stylesheets/wittle/general.css.scss b/app/assets/stylesheets/general.css.scss index 12e5486..7ee3169 100644 --- a/app/assets/stylesheets/wittle/general.css.scss +++ b/app/assets/stylesheets/general.css.scss | |||
@@ -3,7 +3,7 @@ | |||
3 | } | 3 | } |
4 | 4 | ||
5 | #banner { | 5 | #banner { |
6 | background-image: image-url("wittle/wittle_header.png"); | 6 | background-image: image-url("wittle_header.png"); |
7 | background-size: cover; | 7 | background-size: cover; |
8 | width: 600px; | 8 | width: 600px; |
9 | height: 245px; | 9 | height: 245px; |
@@ -65,7 +65,7 @@ input[type="range"]::-webkit-slider-thumb { | |||
65 | appearance: none; | 65 | appearance: none; |
66 | -moz-appearance: none; | 66 | -moz-appearance: none; |
67 | -webkit-appearance: none; | 67 | -webkit-appearance: none; |
68 | background: image-url('wittle/slider.png'); | 68 | background: image-url('slider.png'); |
69 | background-size: 17px 33px; | 69 | background-size: 17px 33px; |
70 | height: 33px; | 70 | height: 33px; |
71 | width: 17px; | 71 | width: 17px; |
@@ -74,7 +74,7 @@ input[type="range"]::-moz-range-thumb { | |||
74 | appearance: none; | 74 | appearance: none; |
75 | -moz-appearance: none; | 75 | -moz-appearance: none; |
76 | -webkit-appearance: none; | 76 | -webkit-appearance: none; |
77 | background: image-url('wittle/slider.png'); | 77 | background: image-url('slider.png'); |
78 | background-size: 17px 33px; | 78 | background-size: 17px 33px; |
79 | height: 33px; | 79 | height: 33px; |
80 | width: 17px; | 80 | width: 17px; |
@@ -83,7 +83,7 @@ input[type="range"]::-ms-thumb { | |||
83 | appearance: none; | 83 | appearance: none; |
84 | -moz-appearance: none; | 84 | -moz-appearance: none; |
85 | -webkit-appearance: none; | 85 | -webkit-appearance: none; |
86 | background: image-url('wittle/slider.png'); | 86 | background: image-url('slider.png'); |
87 | background-size: 17px 33px; | 87 | background-size: 17px 33px; |
88 | height: 33px; | 88 | height: 33px; |
89 | width: 17px; | 89 | width: 17px; |
@@ -190,7 +190,7 @@ input[type="range"]::-ms-thumb { | |||
190 | margin-right: 1em; | 190 | margin-right: 1em; |
191 | 191 | ||
192 | a { | 192 | a { |
193 | background-image: image-url("wittle/wittle_normal.png"); | 193 | background-image: image-url("wittle_normal.png"); |
194 | background-size: cover; | 194 | background-size: cover; |
195 | display: block; | 195 | display: block; |
196 | width: 215px; | 196 | width: 215px; |
@@ -206,7 +206,7 @@ input[type="range"]::-ms-thumb { | |||
206 | margin-right: 1em; | 206 | margin-right: 1em; |
207 | 207 | ||
208 | a { | 208 | a { |
209 | background-image: image-url("wittle/wittle_hard.png"); | 209 | background-image: image-url("wittle_hard.png"); |
210 | background-size: cover; | 210 | background-size: cover; |
211 | display: block; | 211 | display: block; |
212 | width: 215px; | 212 | width: 215px; |
@@ -221,7 +221,7 @@ input[type="range"]::-ms-thumb { | |||
221 | width: 215px; | 221 | width: 215px; |
222 | 222 | ||
223 | a { | 223 | a { |
224 | background-image: image-url("wittle/wittle_expert.png"); | 224 | background-image: image-url("wittle_expert.png"); |
225 | background-size: cover; | 225 | background-size: cover; |
226 | display: block; | 226 | display: block; |
227 | width: 215px; | 227 | width: 215px; |
diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 0000000..d672697 --- /dev/null +++ b/app/channels/application_cable/channel.rb | |||
@@ -0,0 +1,4 @@ | |||
1 | module ApplicationCable | ||
2 | class Channel < ActionCable::Channel::Base | ||
3 | end | ||
4 | end | ||
diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 0000000..0ff5442 --- /dev/null +++ b/app/channels/application_cable/connection.rb | |||
@@ -0,0 +1,4 @@ | |||
1 | module ApplicationCable | ||
2 | class Connection < ActionCable::Connection::Base | ||
3 | end | ||
4 | end | ||
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..09705d1 --- /dev/null +++ b/app/controllers/application_controller.rb | |||
@@ -0,0 +1,2 @@ | |||
1 | class ApplicationController < ActionController::Base | ||
2 | end | ||
diff --git a/app/controllers/puzzles_controller.rb b/app/controllers/puzzles_controller.rb new file mode 100644 index 0000000..b996022 --- /dev/null +++ b/app/controllers/puzzles_controller.rb | |||
@@ -0,0 +1,109 @@ | |||
1 | class PuzzlesController < ApplicationController | ||
2 | before_action :prepare_session | ||
3 | |||
4 | def about | ||
5 | @normal_puzzle = Puzzle.normal.order(created_at: :desc).first | ||
6 | if session[:puzzles]["normal"]["id"] == @normal_puzzle.id | ||
7 | @normal_started = session[:puzzles]["normal"]["started"] | ||
8 | @normal_solved = session[:puzzles]["normal"]["solved"] | ||
9 | else | ||
10 | @normal_started = false | ||
11 | @normal_solved = false | ||
12 | end | ||
13 | |||
14 | @hard_puzzle = Puzzle.hard.order(created_at: :desc).first | ||
15 | if session[:puzzles]["hard"]["id"] == @hard_puzzle.id | ||
16 | @hard_started = session[:puzzles]["hard"]["started"] | ||
17 | @hard_solved = session[:puzzles]["hard"]["solved"] | ||
18 | else | ||
19 | @hard_started = false | ||
20 | @hard_solved = false | ||
21 | end | ||
22 | |||
23 | @expert_puzzle = Puzzle.expert.order(created_at: :desc).first | ||
24 | if session[:puzzles]["expert"]["id"] == @expert_puzzle.id | ||
25 | @expert_started = session[:puzzles]["expert"]["started"] | ||
26 | @expert_solved = session[:puzzles]["expert"]["solved"] | ||
27 | else | ||
28 | @expert_started = false | ||
29 | @expert_solved = false | ||
30 | end | ||
31 | end | ||
32 | |||
33 | def index | ||
34 | @puzzles = Puzzle.select(:id, :created_at, :category).order(created_at: :asc).all.chunk { |puzzle| puzzle.created_at.localtime.to_date }.to_h.transform_values { |by_date| by_date.sort_by(&:category).chunk { |puzzle| puzzle.category }.to_h } | ||
35 | end | ||
36 | |||
37 | def show | ||
38 | @puzzle = Puzzle.find(params["id"]) | ||
39 | |||
40 | if @puzzle.latest? | ||
41 | if session[:puzzles][@puzzle.category]["id"] == @puzzle.id | ||
42 | @playable = !(session[:puzzles][@puzzle.category]["solved"]) | ||
43 | @already_started = session[:puzzles][@puzzle.category]["started"] | ||
44 | |||
45 | unless @playable | ||
46 | @solution = session[:puzzles][@puzzle.category]["path"] | ||
47 | end | ||
48 | else | ||
49 | @playable = true | ||
50 | @already_started = false | ||
51 | end | ||
52 | else | ||
53 | @playable = false | ||
54 | @already_started = false | ||
55 | @solution = @puzzle.solved_data | ||
56 | end | ||
57 | end | ||
58 | |||
59 | def start | ||
60 | @puzzle = Puzzle.find(params["id"]) | ||
61 | |||
62 | if session[:puzzles][@puzzle.category]["id"] != @puzzle.id | ||
63 | session[:puzzles][@puzzle.category] = { "id" => @puzzle.id } | ||
64 | end | ||
65 | |||
66 | session[:puzzles][@puzzle.category]["started"] = true | ||
67 | end | ||
68 | |||
69 | def solve | ||
70 | @puzzle = Puzzle.find(params["id"]) | ||
71 | |||
72 | raise ActiveRecord::RecordNotFound unless @puzzle.latest? | ||
73 | |||
74 | if @puzzle.solved_data.nil? | ||
75 | @puzzle.solved_data = params["solved"] | ||
76 | @puzzle.save! | ||
77 | end | ||
78 | |||
79 | @time = (params.include? :time) ? params[:time] : nil | ||
80 | |||
81 | if session[:puzzles][@puzzle.category]["id"] != @puzzle.id | ||
82 | session[:puzzles][@puzzle.category] = { "id" => @puzzle.id } | ||
83 | end | ||
84 | |||
85 | session[:puzzles][@puzzle.category]["solved"] = true | ||
86 | session[:puzzles][@puzzle.category]["path"] = params["solved"] | ||
87 | end | ||
88 | |||
89 | def submit | ||
90 | @puzzle = Puzzle.find(params["id"]) | ||
91 | |||
92 | raise ActiveRecord::RecordNotFound unless @puzzle.latest? | ||
93 | |||
94 | @puzzle.scores.create(name: params[:name], ip: request.ip, seconds_taken: (params.include? :time) ? params[:time] : nil) | ||
95 | |||
96 | redirect_to @puzzle | ||
97 | end | ||
98 | |||
99 | private | ||
100 | |||
101 | def prepare_session | ||
102 | session[:puzzles] ||= { | ||
103 | normal: { "id" => 0 }, | ||
104 | hard: { "id" => 0 }, | ||
105 | expert: { "id" => 0 }, | ||
106 | } | ||
107 | end | ||
108 | |||
109 | end | ||
diff --git a/app/controllers/wittle/application_controller.rb b/app/controllers/wittle/application_controller.rb deleted file mode 100644 index 252a28e..0000000 --- a/app/controllers/wittle/application_controller.rb +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | module Wittle | ||
2 | class ApplicationController < ActionController::Base | ||
3 | end | ||
4 | end | ||
diff --git a/app/controllers/wittle/puzzles_controller.rb b/app/controllers/wittle/puzzles_controller.rb deleted file mode 100644 index a937aa1..0000000 --- a/app/controllers/wittle/puzzles_controller.rb +++ /dev/null | |||
@@ -1,120 +0,0 @@ | |||
1 | module Wittle | ||
2 | class PuzzlesController < ApplicationController | ||
3 | before_action :prepare_session | ||
4 | after_action :commit_session | ||
5 | |||
6 | def about | ||
7 | @normal_puzzle = Puzzle.normal.order(created_at: :desc).first | ||
8 | if @session_puzzles["normal"]["id"] == @normal_puzzle.id | ||
9 | @normal_started = @session_puzzles["normal"]["started"] | ||
10 | @normal_solved = @session_puzzles["normal"]["solved"] | ||
11 | else | ||
12 | @normal_started = false | ||
13 | @normal_solved = false | ||
14 | end | ||
15 | |||
16 | @hard_puzzle = Puzzle.hard.order(created_at: :desc).first | ||
17 | if @session_puzzles["hard"]["id"] == @hard_puzzle.id | ||
18 | @hard_started = @session_puzzles["hard"]["started"] | ||
19 | @hard_solved = @session_puzzles["hard"]["solved"] | ||
20 | else | ||
21 | @hard_started = false | ||
22 | @hard_solved = false | ||
23 | end | ||
24 | |||
25 | @expert_puzzle = Puzzle.expert.order(created_at: :desc).first | ||
26 | if @session_puzzles["expert"]["id"] == @expert_puzzle.id | ||
27 | @expert_started = @session_puzzles["expert"]["started"] | ||
28 | @expert_solved = @session_puzzles["expert"]["solved"] | ||
29 | else | ||
30 | @expert_started = false | ||
31 | @expert_solved = false | ||
32 | end | ||
33 | end | ||
34 | |||
35 | def index | ||
36 | @puzzles = Puzzle.select(:id, :created_at, :category).order(created_at: :asc).all.chunk { |puzzle| puzzle.created_at.localtime.to_date }.to_h.transform_values { |by_date| by_date.sort_by(&:category).chunk { |puzzle| puzzle.category }.to_h } | ||
37 | end | ||
38 | |||
39 | def show | ||
40 | @puzzle = Puzzle.find(params[:id]) | ||
41 | |||
42 | if @puzzle.latest? | ||
43 | if @session_puzzles[@puzzle.category]["id"] == @puzzle.id | ||
44 | @playable = !(@session_puzzles[@puzzle.category]["solved"]) | ||
45 | @already_started = @session_puzzles[@puzzle.category]["started"] | ||
46 | |||
47 | unless @playable | ||
48 | @solution = @session_puzzles[@puzzle.category]["path"] | ||
49 | end | ||
50 | else | ||
51 | @playable = true | ||
52 | @already_started = false | ||
53 | end | ||
54 | else | ||
55 | @playable = false | ||
56 | @already_started = false | ||
57 | @solution = @puzzle.solved_data | ||
58 | end | ||
59 | end | ||
60 | |||
61 | def start | ||
62 | @puzzle = Puzzle.find(params[:id]) | ||
63 | |||
64 | if @session_puzzles[@puzzle.category]["id"] != @puzzle.id | ||
65 | @session_puzzles[@puzzle.category] = { "id" => @puzzle.id } | ||
66 | end | ||
67 | |||
68 | @session_puzzles[@puzzle.category]["started"] = true | ||
69 | end | ||
70 | |||
71 | def solve | ||
72 | @puzzle = Puzzle.find(params[:id]) | ||
73 | |||
74 | raise ActiveRecord::RecordNotFound unless @puzzle.latest? | ||
75 | |||
76 | if @puzzle.solved_data.nil? | ||
77 | @puzzle.solved_data = params[:solved] | ||
78 | @puzzle.save! | ||
79 | end | ||
80 | |||
81 | @time = (params.include? :time) ? params[:time] : nil | ||
82 | |||
83 | if @session_puzzles[@puzzle.category]["id"] != @puzzle.id | ||
84 | @session_puzzles[@puzzle.category] = { "id" => @puzzle.id } | ||
85 | end | ||
86 | |||
87 | @session_puzzles[@puzzle.category]["solved"] = true | ||
88 | @session_puzzles[@puzzle.category]["path"] = params[:solved] | ||
89 | end | ||
90 | |||
91 | def submit | ||
92 | @puzzle = Puzzle.find(params[:id]) | ||
93 | |||
94 | raise ActiveRecord::RecordNotFound unless @puzzle.latest? | ||
95 | |||
96 | @puzzle.scores.create(name: params[:name], ip: request.ip, seconds_taken: (params.include? :time) ? params[:time] : nil) | ||
97 | |||
98 | redirect_to @puzzle | ||
99 | end | ||
100 | |||
101 | private | ||
102 | |||
103 | def prepare_session | ||
104 | if cookies.encrypted[:puzzles].nil? | ||
105 | @session_puzzles = { "normal" => { id: nil }, "hard" => { id: nil }, "expert" => { id: nil } } | ||
106 | else | ||
107 | @session_puzzles = JSON.parse(cookies.encrypted[:puzzles]) | ||
108 | end | ||
109 | |||
110 | # Temporary hack | ||
111 | if session.has_key? :puzzle_solutions | ||
112 | session[:puzzle_solutions].clear() | ||
113 | end | ||
114 | end | ||
115 | |||
116 | def commit_session | ||
117 | cookies.encrypted[:puzzles] = JSON.generate(@session_puzzles) | ||
118 | end | ||
119 | end | ||
120 | end | ||
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/app/helpers/application_helper.rb | |||
@@ -0,0 +1,2 @@ | |||
1 | module ApplicationHelper | ||
2 | end | ||
diff --git a/app/helpers/puzzles_helper.rb b/app/helpers/puzzles_helper.rb new file mode 100644 index 0000000..ded1e8d --- /dev/null +++ b/app/helpers/puzzles_helper.rb | |||
@@ -0,0 +1,7 @@ | |||
1 | module PuzzlesHelper | ||
2 | |||
3 | def humanize_interval(seconds) | ||
4 | "#{(seconds / 60).to_s.rjust(2, '0')}:#{(seconds % 60).to_s.rjust(2, '0')}" | ||
5 | end | ||
6 | |||
7 | end | ||
diff --git a/app/helpers/wittle/application_helper.rb b/app/helpers/wittle/application_helper.rb deleted file mode 100644 index 8fcb2c9..0000000 --- a/app/helpers/wittle/application_helper.rb +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | module Wittle | ||
2 | module ApplicationHelper | ||
3 | end | ||
4 | end | ||
diff --git a/app/helpers/wittle/puzzles_helper.rb b/app/helpers/wittle/puzzles_helper.rb deleted file mode 100644 index 64364c6..0000000 --- a/app/helpers/wittle/puzzles_helper.rb +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | module Wittle | ||
2 | module PuzzlesHelper | ||
3 | |||
4 | def humanize_interval(seconds) | ||
5 | "#{(seconds / 60).to_s.rjust(2, '0')}:#{(seconds % 60).to_s.rjust(2, '0')}" | ||
6 | end | ||
7 | |||
8 | end | ||
9 | end | ||
diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000..d394c3d --- /dev/null +++ b/app/jobs/application_job.rb | |||
@@ -0,0 +1,7 @@ | |||
1 | class ApplicationJob < ActiveJob::Base | ||
2 | # Automatically retry jobs that encountered a deadlock | ||
3 | # retry_on ActiveRecord::Deadlocked | ||
4 | |||
5 | # Most jobs are safe to ignore if the underlying records are no longer available | ||
6 | # discard_on ActiveJob::DeserializationError | ||
7 | end | ||
diff --git a/app/jobs/wittle/application_job.rb b/app/jobs/wittle/application_job.rb deleted file mode 100644 index b0ab02e..0000000 --- a/app/jobs/wittle/application_job.rb +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | module Wittle | ||
2 | class ApplicationJob < ActiveJob::Base | ||
3 | end | ||
4 | end | ||
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000..3c34c81 --- /dev/null +++ b/app/mailers/application_mailer.rb | |||
@@ -0,0 +1,4 @@ | |||
1 | class ApplicationMailer < ActionMailer::Base | ||
2 | default from: "from@example.com" | ||
3 | layout "mailer" | ||
4 | end | ||
diff --git a/app/mailers/wittle/application_mailer.rb b/app/mailers/wittle/application_mailer.rb deleted file mode 100644 index 5a563c4..0000000 --- a/app/mailers/wittle/application_mailer.rb +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | module Wittle | ||
2 | class ApplicationMailer < ActionMailer::Base | ||
3 | default from: "from@example.com" | ||
4 | layout "mailer" | ||
5 | end | ||
6 | end | ||
diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..b63caeb --- /dev/null +++ b/app/models/application_record.rb | |||
@@ -0,0 +1,3 @@ | |||
1 | class ApplicationRecord < ActiveRecord::Base | ||
2 | primary_abstract_class | ||
3 | end | ||
diff --git a/app/models/puzzle.rb b/app/models/puzzle.rb new file mode 100644 index 0000000..4f57d9c --- /dev/null +++ b/app/models/puzzle.rb | |||
@@ -0,0 +1,14 @@ | |||
1 | class Puzzle < ApplicationRecord | ||
2 | extend Enumerize | ||
3 | |||
4 | has_many :scores | ||
5 | |||
6 | validates :data, presence: true | ||
7 | |||
8 | validates :category, presence: true | ||
9 | enumerize :category, in: [:normal, :hard, :expert], scope: :shallow | ||
10 | |||
11 | def latest? | ||
12 | Puzzle.where(category: category).order(created_at: :desc).first.id == id | ||
13 | end | ||
14 | end | ||
diff --git a/app/models/score.rb b/app/models/score.rb new file mode 100644 index 0000000..1958389 --- /dev/null +++ b/app/models/score.rb | |||
@@ -0,0 +1,7 @@ | |||
1 | class Score < ApplicationRecord | ||
2 | belongs_to :puzzle | ||
3 | |||
4 | validates :name, presence: true | ||
5 | validates :ip, presence: true | ||
6 | validates_uniqueness_of :name, scope: :puzzle_id | ||
7 | end | ||
diff --git a/app/models/wittle/application_record.rb b/app/models/wittle/application_record.rb deleted file mode 100644 index be1dfe5..0000000 --- a/app/models/wittle/application_record.rb +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | module Wittle | ||
2 | class ApplicationRecord < ActiveRecord::Base | ||
3 | self.abstract_class = true | ||
4 | end | ||
5 | end | ||
diff --git a/app/models/wittle/puzzle.rb b/app/models/wittle/puzzle.rb deleted file mode 100644 index f9009bc..0000000 --- a/app/models/wittle/puzzle.rb +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | module Wittle | ||
2 | class Puzzle < ApplicationRecord | ||
3 | extend Enumerize | ||
4 | |||
5 | has_many :scores | ||
6 | |||
7 | validates :data, presence: true | ||
8 | |||
9 | validates :category, presence: true | ||
10 | enumerize :category, in: [:normal, :hard, :expert], scope: :shallow | ||
11 | |||
12 | def latest? | ||
13 | Puzzle.where(category: category).order(created_at: :desc).first.id == id | ||
14 | end | ||
15 | end | ||
16 | end | ||
diff --git a/app/models/wittle/score.rb b/app/models/wittle/score.rb deleted file mode 100644 index 54d2b89..0000000 --- a/app/models/wittle/score.rb +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | module Wittle | ||
2 | class Score < ApplicationRecord | ||
3 | belongs_to :puzzle | ||
4 | |||
5 | validates :name, presence: true | ||
6 | validates :ip, presence: true | ||
7 | validates_uniqueness_of :name, scope: :puzzle_id | ||
8 | end | ||
9 | end | ||
diff --git a/app/views/layouts/wittle/application.html.haml b/app/views/layouts/application.html.haml index 1226d79..cae8de9 100644 --- a/app/views/layouts/wittle/application.html.haml +++ b/app/views/layouts/application.html.haml | |||
@@ -4,8 +4,8 @@ | |||
4 | %title Wittle | 4 | %title Wittle |
5 | = csrf_meta_tags | 5 | = csrf_meta_tags |
6 | = csp_meta_tag | 6 | = csp_meta_tag |
7 | = stylesheet_link_tag "wittle/application", media: "all" | 7 | = stylesheet_link_tag "application", "data-turbo-track": "reload" |
8 | = javascript_include_tag "wittle/application" | 8 | = javascript_include_tag "application" |
9 | %body | 9 | %body |
10 | #wrap | 10 | #wrap |
11 | %header#banner | 11 | %header#banner |
diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000..3aac900 --- /dev/null +++ b/app/views/layouts/mailer.html.erb | |||
@@ -0,0 +1,13 @@ | |||
1 | <!DOCTYPE html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
5 | <style> | ||
6 | /* Email styles need to be inline */ | ||
7 | </style> | ||
8 | </head> | ||
9 | |||
10 | <body> | ||
11 | <%= yield %> | ||
12 | </body> | ||
13 | </html> | ||
diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000..37f0bdd --- /dev/null +++ b/app/views/layouts/mailer.text.erb | |||
@@ -0,0 +1 @@ | |||
<%= yield %> | |||
diff --git a/app/views/wittle/puzzles/_handle_puzzle.html.erb b/app/views/puzzles/_handle_puzzle.html.erb index f0e3227..f0e3227 100644 --- a/app/views/wittle/puzzles/_handle_puzzle.html.erb +++ b/app/views/puzzles/_handle_puzzle.html.erb | |||
diff --git a/app/views/wittle/puzzles/_submission.html.haml b/app/views/puzzles/_submission.html.haml index a3d0740..a3d0740 100644 --- a/app/views/wittle/puzzles/_submission.html.haml +++ b/app/views/puzzles/_submission.html.haml | |||
diff --git a/app/views/wittle/puzzles/about.html.haml b/app/views/puzzles/about.html.haml index f1f7aa0..f1f7aa0 100644 --- a/app/views/wittle/puzzles/about.html.haml +++ b/app/views/puzzles/about.html.haml | |||
diff --git a/app/views/wittle/puzzles/index.html.haml b/app/views/puzzles/index.html.haml index fe497e4..fe497e4 100644 --- a/app/views/wittle/puzzles/index.html.haml +++ b/app/views/puzzles/index.html.haml | |||
diff --git a/app/views/wittle/puzzles/show.html.haml b/app/views/puzzles/show.html.haml index 47db8f2..47db8f2 100644 --- a/app/views/wittle/puzzles/show.html.haml +++ b/app/views/puzzles/show.html.haml | |||
diff --git a/app/views/wittle/puzzles/solve.js.erb b/app/views/puzzles/solve.js.erb index 2aa22e9..2aa22e9 100644 --- a/app/views/wittle/puzzles/solve.js.erb +++ b/app/views/puzzles/solve.js.erb | |||