+ <% @node.children.each do |node| %> + <%= button_to node.title, url_for(action: "answer", value: node.id), + class: ("chance" if node.chance?), + form: ((stage_index == 1 and node.chance?) ? { data: { action: "submit->chance#confirm" } } : {}) %> + <% end %> + + <% if stage_index == 1 %> + + + <%= t("game.take_a_chance") %> + <%= tag.h2 t("game.its_risky").html_safe %> + + + <%= svg "ico-wave" %> + + <%= t("game.cancel") %> + <%= t("game.ok") %> + + + + + <% end %> + +
- <%= tag.h1 t("game.intro_title").html_safe %> + + + diff --git a/app/views/site/start.html.erb b/app/views/game/start.html.erb similarity index 86% rename from app/views/site/start.html.erb rename to app/views/game/start.html.erb index de3e647..604595f 100644 --- a/app/views/site/start.html.erb +++ b/app/views/game/start.html.erb @@ -13,7 +13,8 @@ <%= tag.h1 t("game.intro_title").html_safe %> <%= tag.p t("game.intro_description") %> - <%= link_to tag.span(t("game.let_me_try")), {action: "facts"}, class: "cta" %> + <%= button_to tag.span(t("game.let_me_try")), start_path, class: "cta" %> + <%= tag.div class: "play-time" do %> <%= svg "ico-clock" %> <%= tag.span t("game.play_time") %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c503512..4fb0276 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -17,7 +17,7 @@ <%= stylesheet_link_tag "reset", "application" %> - <%= frontend_javascript_importmap_tags %w[application @hotwired/turbo-rails @hotwired/stimulus language_menu_controller carousel_controller intro_controller] %> + <%= frontend_javascript_importmap_tags %w[application @hotwired/turbo-rails @hotwired/stimulus language_menu_controller carousel_controller intro_controller chance_controller] %> <%= content_for :header %> diff --git a/config/importmap.rb b/config/importmap.rb index 416b4cb..dda8381 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -17,3 +17,4 @@ pin "application", preload: false pin "language_menu_controller", preload: false pin "carousel_controller", preload: false pin "intro_controller", preload: false +pin "chance_controller", preload: false diff --git a/config/locales/en.yml b/config/locales/en.yml index 1c06079..6586d5c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -18,6 +18,13 @@ en: got_it_lets_get_started: Got it, let’s get started stage_i_of_n: Stage %{i} of %{n} + take_a_chance: Take a chance + its_risky: | + It’s risky + but it can boost your score. + ok: Ok + cancel: Cancel + countries: au: Australia at: Austria @@ -326,7 +333,12 @@ en: tags: sell date_formats: schedule subscribers: group - newsletters: mail + newsletters: mail + + stages: + - + - ico-soil + - ico-water sessions: login: Log in diff --git a/config/routes.rb b/config/routes.rb index 865a20e..332f71c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -60,12 +60,17 @@ Rails.application.routes.draw do scope ":locale", constraints: { locale: /en|zh|hr|cs|da|nl|fi|fr|fr-CA|de|hu|it|ja|ko|nb|pl|pt|ro|sr|sk|sl|es|sv|uk/ } do # get "*url", to: "site#page", constraints: lambda { |req| req.path.exclude?("storage") } - get "facts", to: "site#facts" - get "intro", to: "site#intro" + post "start", to: "game#start", as: :start + get "facts", to: "game#facts" + get "intro", to: "game#intro" - get "stage/:id", to: "site#stage" + get "stage/:id", to: "game#stage" - get "", to: "site#index", as: :locale_root + post "stage/:id/answer", to: "game#answer" + + get "stage/:id/result", to: "game#stage_result" + + get "", to: "game#index", as: :locale_root end # Defines the root path route ("/") diff --git a/db/migrate/20260603141335_create_players.rb b/db/migrate/20260603141335_create_players.rb new file mode 100644 index 0000000..9cb5d2a --- /dev/null +++ b/db/migrate/20260603141335_create_players.rb @@ -0,0 +1,11 @@ +class CreatePlayers < ActiveRecord::Migration[8.1] + def change + create_table :players do |t| + t.string :locale, null: false + t.integer :score, default: 0, null: false + t.jsonb :progress, default: {}, null: false + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 34cdb3b..f727eeb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2025_04_27_131737) do +ActiveRecord::Schema[8.1].define(version: 2026_06_03_141335) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -114,6 +114,14 @@ ActiveRecord::Schema[8.1].define(version: 2025_04_27_131737) do t.index ["url"], name: "index_nodes_on_url", using: :gin end + create_table "players", force: :cascade do |t| + t.datetime "created_at", null: false + t.string "locale", null: false + t.jsonb "progress", default: {}, null: false + t.integer "score", default: 0, null: false + t.datetime "updated_at", null: false + end + create_table "quiz_results", force: :cascade do |t| t.datetime "created_at", null: false t.string "locale", null: false