| @ -0,0 +1 @@ | |||
| <svg xmlns="http://www.w3.org/2000/svg" width="20" height="22" viewBox="0 0 20 22"><path d="M18.04,3.25l-.83-2.49c-.1-.31-.39-.51-.71-.51h-7.35l-.22.27-2.28,2.73H0v1.5h1.76l.99,16.3c.02.4.35.7.75.7h4.5v-1.5h-3.79l-.94-15.5h13.47l-.35,5.7.75.05.75.05.35-5.8h1.76v-1.5h-1.96ZM9.85,1.75h6.11l.5,1.5h-7.86l1.25-1.5ZM9.64,16.72h-.76l-.21-.4-1.32-2.47.66-.35.66-.35.77,1.44c1.06-1.78,3.19-2.74,5.3-2.17,1.3.35,2.32,1.2,2.93,2.29l-.66.36-.66.36c-.41-.75-1.12-1.33-2-1.57-1.73-.46-3.52.56-3.98,2.3l-.15.56h-.58ZM18.46,17.7l1.22,2.46-.67.33-.67.33-.73-1.47c-1.05,1.82-3.21,2.8-5.33,2.23-1.27-.34-2.28-1.16-2.88-2.21l.65-.38.65-.38c.42.72,1.11,1.28,1.97,1.51,1.73.46,3.52-.56,3.98-2.3l.15-.56h1.46l.21.42Z"/></svg> | |||
| @ -1,29 +1,50 @@ | |||
| class Player < ApplicationRecord | |||
| # progress shape: | |||
| # { "1" => { "answer_id" => 42, "result_id" => 99 }, "2" => { ... } } | |||
| # { "1" => { "answer_id" => 42, "result_id" => 99 }, "2" => { ... }, | |||
| # "last_save" => { "answer_id" => 7 } } | |||
| LAST_SAVE_KEY = "last_save".freeze | |||
| def record_answer(stage, answer_id) | |||
| stage_data(stage)["answer_id"] = answer_id | |||
| save | |||
| end | |||
| def record_result(stage, result_id) | |||
| stage_data(stage)["result_id"] = result_id | |||
| save | |||
| end | |||
| def answer_id_for(stage) | |||
| progress[stage.to_s]&.dig("answer_id") | |||
| end | |||
| def result_id_for(stage) | |||
| progress[stage.to_s]&.dig("result_id") | |||
| end | |||
| def record_last_save_answer(answer_id) | |||
| stage_data(LAST_SAVE_KEY)["answer_id"] = answer_id | |||
| save | |||
| end | |||
| def last_save_answer_id | |||
| progress[LAST_SAVE_KEY]&.dig("answer_id") | |||
| end | |||
| private | |||
| def stage_data(stage) | |||
| progress[stage.to_s] ||= {} | |||
| end | |||
| end | |||
| @ -0,0 +1,18 @@ | |||
| <% is_last_save = @node.path_ids.include?(last_save_node&.id) %> | |||
| <div class="stage-header-container"> | |||
| <ol class="stage-progress" role="progressbar"> | |||
| <% n_stages.times do |i| %> | |||
| <%= tag.li class: ("done" if is_last_save or stage_index >= (i + 1)) %> | |||
| <% end %> | |||
| </ol> | |||
| <div class="stage-header"> | |||
| <div class="stage-icon"><%= svg (is_last_save ? t("icons.last_save") : t("icons.stages")[stage_index]) %></div> | |||
| <div> | |||
| <%= tag.div t("game.stage_i_of_n", i: (is_last_save ? n_stages : stage_index), n: n_stages), class: "stage-progress" %> | |||
| <%= tag.h1 @node.title %> | |||
| </div> | |||
| </div> | |||
| </div> | |||
| @ -0,0 +1,24 @@ | |||
| <%- content_for :title, node_title(@node) %> | |||
| <% image_attachment = @node.attachments.select { |a| a.asset&.file&.image? }[0] %> | |||
| <%= render partial: "stage_header" %> | |||
| <div class="hero-container"> | |||
| <%# render_responsive_picture(image_attachment.asset, alt: "Hero", fetchpriority: "high") %> | |||
| <article> | |||
| <%= @result_node.attachments[0]&.body&.html_safe %> | |||
| </article> | |||
| <%= svg "ico-wave" %> | |||
| </div> | |||
| <article class="answers-container"> | |||
| <%= @result_node.attachments[1]&.body&.html_safe %> | |||
| <div> | |||
| <%= link_to tag.span(t("game.drumroll_see_the_result")), | |||
| { action: "result" }, | |||
| class: (@result_node.parent.chance? and @result_node.bad_answer?) ? "cta last_save" : "cta" %> | |||
| </div> | |||
| </article> | |||
| @ -0,0 +1,20 @@ | |||
| <%- content_for :title, node_title(@node) %> | |||
| <% image_attachment = @node.attachments.select { |a| a.asset&.file&.image? }[0] %> | |||
| <%= render partial: "stage_header" %> | |||
| <div class="hero-container"> | |||
| <%= render_responsive_picture(image_attachment.asset, alt: "Hero", fetchpriority: "high") %> | |||
| <article> | |||
| <%= image_attachment.body.html_safe %> | |||
| </article> | |||
| <%= svg "ico-wave" %> | |||
| </div> | |||
| <article class="answers-container" data-controller="chance"> | |||
| <% @node.children.each do |node| %> | |||
| <%= button_to node.title, url_for(action: "answer_last_save", value: node.id) %> | |||
| <% end %> | |||
| </article> | |||
| @ -0,0 +1 @@ | |||
| <%- content_for :title, node_title(@node) %> | |||
| @ -1,32 +1,26 @@ | |||
| <%- content_for :title, node_title(@node) %> | |||
| <% image_attachment = @node.attachments.select { |a| a.asset&.file&.image? }[0] %> | |||
| <div class="stage-header-container"> | |||
| <ol class="stage-progress" role="progressbar"> | |||
| <% n_stages.times do |i| %> | |||
| <%= tag.li class: ("done" if stage_index >= (i + 1)) %> | |||
| <% end %> | |||
| </ol> | |||
| <div class="stage-header"> | |||
| <div class="stage-icon"><%= svg t("icons.stages")[stage_index] %></div> | |||
| <div> | |||
| <%= tag.div t("game.stage_i_of_n", i: stage_index, n: n_stages), class: "stage-progress" %> | |||
| <%= tag.h1 @node.title %> | |||
| </div> | |||
| </div> | |||
| </div> | |||
| <%= render partial: "stage_header" %> | |||
| <div class="hero-container"> | |||
| <%= render_responsive_picture(image_attachment.asset, alt: "Hero", fetchpriority: "high") %> | |||
| <%# render_responsive_picture(image_attachment.asset, alt: "Hero", fetchpriority: "high") %> | |||
| <article> | |||
| <%= image_attachment.body.html_safe %> | |||
| <%= @result_node.attachments[0]&.body&.html_safe %> | |||
| </article> | |||
| <%= svg "ico-wave" %> | |||
| </div> | |||
| <article class="answers-container"> | |||
| <%= @result_node.attachments[1]&.body&.html_safe %> | |||
| <div> | |||
| <% if @result_node.parent.chance? and @result_node.bad_answer? %> | |||
| <%= link_to tag.span(t("game.let_me_try")), {action: "last_save" }, class: "cta last_save" %> | |||
| <% else %> | |||
| <%= link_to tag.span(t("game.next_stage")), {action: "stage", id: stage_index + 1 }, class: "cta" %> | |||
| <% end %> | |||
| </div> | |||
| </article> | |||