From 0929719a845897cc8567cf972e07a69a71f0fa6f Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Thu, 30 Nov 2023 13:29:08 -0500 Subject: Migrate to a full rails app --- app/views/puzzles/_handle_puzzle.html.erb | 76 +++++++++++++++++++++++++++++++ app/views/puzzles/_submission.html.haml | 9 ++++ app/views/puzzles/about.html.haml | 53 +++++++++++++++++++++ app/views/puzzles/index.html.haml | 26 +++++++++++ app/views/puzzles/show.html.haml | 41 +++++++++++++++++ app/views/puzzles/solve.js.erb | 5 ++ 6 files changed, 210 insertions(+) create mode 100644 app/views/puzzles/_handle_puzzle.html.erb create mode 100644 app/views/puzzles/_submission.html.haml create mode 100644 app/views/puzzles/about.html.haml create mode 100644 app/views/puzzles/index.html.haml create mode 100644 app/views/puzzles/show.html.haml create mode 100644 app/views/puzzles/solve.js.erb (limited to 'app/views/puzzles') diff --git a/app/views/puzzles/_handle_puzzle.html.erb b/app/views/puzzles/_handle_puzzle.html.erb new file mode 100644 index 0000000..f0e3227 --- /dev/null +++ b/app/views/puzzles/_handle_puzzle.html.erb @@ -0,0 +1,76 @@ + diff --git a/app/views/puzzles/_submission.html.haml b/app/views/puzzles/_submission.html.haml new file mode 100644 index 0000000..a3d0740 --- /dev/null +++ b/app/views/puzzles/_submission.html.haml @@ -0,0 +1,9 @@ +%h3 Congrats! +%p Would you like to submit your time? += form_with url: submit_puzzle_path(@puzzle) do |form| + - unless @time.nil? + = form.hidden_field :time, value: @time + %p + = form.label :name, "Name:" + = form.text_field :name + %p= form.submit "Submit" diff --git a/app/views/puzzles/about.html.haml b/app/views/puzzles/about.html.haml new file mode 100644 index 0000000..f1f7aa0 --- /dev/null +++ b/app/views/puzzles/about.html.haml @@ -0,0 +1,53 @@ +%p.summary Wittle gives you daily randomly-generated puzzles in the style of those from the 2016 indie game, The Witness. There are three difficulties of puzzles to choose from: +%h2#current-date= @normal_puzzle.created_at.localtime.strftime("%B %-d, %Y") +%nav#choose-difficulty + #normal-link + = link_to "Normal", @normal_puzzle + - if @normal_solved + %p.puzzle-status Solved! + - elsif @normal_started + %p.puzzle-status Started + #hard-link + = link_to "Hard", @hard_puzzle + - if @hard_solved + %p.puzzle-status Solved! + - elsif @hard_started + %p.puzzle-status Started + #expert-link + = link_to "Expert", @expert_puzzle + - if @expert_solved + %p.puzzle-status Solved! + - elsif @expert_started + %p.puzzle-status Started +#new-puzzles + - if @normal_puzzle.created_at.localtime.to_date != DateTime.now.localtime.to_date + New puzzles are being generated... + - else + Time until new puzzles: 00:00:00 + :javascript + function pad(val) { + var valString = val + "" + if (valString.length < 2) + { + return "0" + valString + } else { + return valString + } + } + function setTime() { + --totalSeconds + if (totalSeconds == 0) + { + $("#new-puzzles").text("Refresh the page for today's puzzles!") + clearInterval(timerInterval) + } else { + $("#seconds").text(pad(totalSeconds%60)) + $("#minutes").text(pad(parseInt(totalSeconds/60)%60)) + $("#hours").text(pad(parseInt(parseInt(totalSeconds/60)/60))) + } + } + var totalSeconds = #{(Time.now.tomorrow.beginning_of_day - Time.now).to_i + 1} + setTime() + var timerInterval = setInterval(setTime, 1000); +%p.summary Wittle was created by Hatkirby, with major help from Sigma144 (who wrote the puzzle generation code) and jbzdarkid (who wrote the puzzle solving web interface). The source code is available here. If you encounter any bugs, or have feedback regarding puzzle difficulty level, feel free to contact me! I am hatkirby on Discord, and you can also find me in the Witness Speedrunning server. +%p.summary There is an archive of past puzzles for those interested. diff --git a/app/views/puzzles/index.html.haml b/app/views/puzzles/index.html.haml new file mode 100644 index 0000000..fe497e4 --- /dev/null +++ b/app/views/puzzles/index.html.haml @@ -0,0 +1,26 @@ +.breadcrumb= link_to "← Back to home page", root_path +%h1 Archive +%table#archive + %tr + %th + %th Normal + %th Hard + %th Expert + - @puzzles.each do |date, dps| + %tr{ class: cycle("even", "odd") } + %td= date.strftime("%B %-d, %Y") + %td + - if dps.has_key? "normal" + %ul + - dps["normal"].each do |puzzle| + %li= link_to "\##{puzzle.id}", puzzle + %td + - if dps.has_key? "hard" + %ul + - dps["hard"].each do |puzzle| + %li= link_to "\##{puzzle.id}", puzzle + %td + - if dps.has_key? "expert" + %ul + - dps["expert"].each do |puzzle| + %li= link_to "\##{puzzle.id}", puzzle diff --git a/app/views/puzzles/show.html.haml b/app/views/puzzles/show.html.haml new file mode 100644 index 0000000..47db8f2 --- /dev/null +++ b/app/views/puzzles/show.html.haml @@ -0,0 +1,41 @@ +.breadcrumb= link_to "← Back to home page", root_path +%h1 Wittle ##{@puzzle.id} +.puzzle-description #{@puzzle.category.capitalize} - #{@puzzle.created_at.localtime.strftime("%B %-d, %Y")} +#puzzle-container{ style: "display: flex; justify-content: center; align-items: center" } + %svg#puzzle{ style: "pointer-events: auto"} +#submission-form +- if @playable + - unless @already_started + #activation-button + %button{ type: "button" } Reveal Puzzle + #timer + %label#minutes 00 + %label#colon : + %label#seconds 00 +- if @playable or @puzzle.latest? + %details#trace-settings + %summary Settings + .things + %label{ for: "sens" } Mouse Speed 2D + %input#sens{ type: "range", min: "0.1", max: "1.3", step: "0.1" } + %label{ for: "volume" } Volume + %input#volume{ type: "range", min: "0", max: "0.24", step: "0.02" } +- unless @playable + #scores + #by-time + %h2 Fastest Solves + %table + - @puzzle.scores.where("seconds_taken IS NOT NULL").order(seconds_taken: :asc, created_at: :asc).limit(100).each_with_index do |score, i| + %tr + %td #{(i + 1)}. + %td= score.name + %td.score-field= humanize_interval(score.seconds_taken) + #by-when + %h2 Completion Order + %table + - @puzzle.scores.order(created_at: :asc).limit(100).each_with_index do |score, i| + %tr + %td #{(i + 1)}. + %td= score.name + %td.score-field= score.created_at.getlocal().strftime("%-I:%M:%S%P") += render partial: "handle_puzzle" diff --git a/app/views/puzzles/solve.js.erb b/app/views/puzzles/solve.js.erb new file mode 100644 index 0000000..2aa22e9 --- /dev/null +++ b/app/views/puzzles/solve.js.erb @@ -0,0 +1,5 @@ +$("#submission-form").html('<%= escape_javascript(render partial: "submission") %>'); +$("#submission-form #name").val(window.settings.player_name) +$("#submission-form #name").on("change", function() { + window.settings.player_name = this.value +}) -- cgit 1.4.1