From ab4cb585b8668fb424b69aa43675ca1094d93591 Mon Sep 17 00:00:00 2001 From: TheNeedful-DO Date: Wed, 6 Dec 2023 12:54:04 +0000 Subject: [PATCH] Enable tables and seats --- app/assets/stylesheets/application.css.sass | 2 ++ app/controllers/visitors_controller.rb | 4 ++++ app/models/seat.rb | 21 +++++++++++---------- app/models/table.rb | 5 +++-- app/policies/table_policy.rb | 4 ++-- app/views/tables/_seat.html.haml | 5 +++-- app/views/tables/index.html.haml | 7 ++++--- app/views/tables/show.html.haml | 6 +++--- app/views/visitors/games_index.html.haml | 21 +++++++++++++++++++++ config/routes.rb | 1 + 10 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 app/views/visitors/games_index.html.haml diff --git a/app/assets/stylesheets/application.css.sass b/app/assets/stylesheets/application.css.sass index 7e382196..11a807f4 100644 --- a/app/assets/stylesheets/application.css.sass +++ b/app/assets/stylesheets/application.css.sass @@ -266,3 +266,5 @@ textarea @import microposts @import projects @import rooms +@import tables +@import game diff --git a/app/controllers/visitors_controller.rb b/app/controllers/visitors_controller.rb index debc151b..fbf8810c 100644 --- a/app/controllers/visitors_controller.rb +++ b/app/controllers/visitors_controller.rb @@ -6,4 +6,8 @@ class VisitorsController < ApplicationController @canisters = authorize Canister.all @feed_items = current_user.feed.paginate(page: params[:page]) end + + def games_index + + end end diff --git a/app/models/seat.rb b/app/models/seat.rb index 8b9f23bf..847749de 100644 --- a/app/models/seat.rb +++ b/app/models/seat.rb @@ -1,8 +1,8 @@ class Seat < ActiveRecord::Base belongs_to :table - belongs_to :game - belongs_to :user - belongs_to :player + belongs_to :game, optional: true + belongs_to :user, optional: true + belongs_to :player, optional: true def sit(current_user) if self.occupied? @@ -13,12 +13,13 @@ class Seat < ActiveRecord::Base self.reload if self.player == nil - self.player_id = self.table.current_game.add_player_from_user(current_user).id + # TODO: Decouple seat from game + # self.player_id = self.table.current_game.add_player_from_user(current_user).id end - self.player.user_id = current_user.id - self.player.soft_token = current_user.soft_token - self.player.save + # self.player.user_id = current_user.id + # self.player.soft_token = current_user.soft_token + # self.player.save self.user_id = current_user.id self.user_soft_token = current_user.soft_token @@ -32,9 +33,9 @@ class Seat < ActiveRecord::Base return "Error. Seat not occupied by you." else # self.table.current_game.remove_player_from_user(user) - self.player.user = nil - self.player.soft_token = nil - self.player.save + # self.player.user = nil + # self.player.soft_token = nil + # self.player.save self.user_id = nil self.user_soft_token = nil # self.player_id = nil diff --git a/app/models/table.rb b/app/models/table.rb index 9fa5fb4a..c60efe28 100644 --- a/app/models/table.rb +++ b/app/models/table.rb @@ -37,11 +37,12 @@ class Table < ActiveRecord::Base self.games.create end - private + # private def add_seats + return if self.seats.present? 1.upto(4) do |i| - self.seats.create(position: i) + self.seats.create!(position: i) end end diff --git a/app/policies/table_policy.rb b/app/policies/table_policy.rb index 112186b1..51405109 100644 --- a/app/policies/table_policy.rb +++ b/app/policies/table_policy.rb @@ -7,11 +7,11 @@ class TablePolicy end def index? - false + true end def show? - @current_user.admin? || @current_user == @user + @current_user.admin? || @current_user == @user || true end def create? diff --git a/app/views/tables/_seat.html.haml b/app/views/tables/_seat.html.haml index 8d39f433..ce40c4c9 100644 --- a/app/views/tables/_seat.html.haml +++ b/app/views/tables/_seat.html.haml @@ -12,12 +12,13 @@ - "Leave" - else -# = button_to empty_seat_path(seat), :data => { :confirm => 'Are you sure you want to empty this seat?' } do - = button_to empty_seat_path(seat) do + -# TODO policy check to clear seat + -# = button_to empty_seat_path(seat) do - "Clear Seat" - else = button_to sit_seat_path(seat) do - "Sit" - = button_to add_bot_seat_path(seat) do + -# = button_to add_bot_seat_path(seat) do - "+ Bot" - if seat.player diff --git a/app/views/tables/index.html.haml b/app/views/tables/index.html.haml index 071d706f..3ac651c6 100644 --- a/app/views/tables/index.html.haml +++ b/app/views/tables/index.html.haml @@ -1,7 +1,8 @@ -%h1 Listing tables +.contain + %h1 Listing tables -- if policy(:table).new? - .button= link_to 'New Table', new_table_path + - if policy(:table).new? + .button= link_to 'New Table', new_table_path .tables-container - @tables.each do |table| diff --git a/app/views/tables/show.html.haml b/app/views/tables/show.html.haml index 2b59ed25..618ea136 100644 --- a/app/views/tables/show.html.haml +++ b/app/views/tables/show.html.haml @@ -17,9 +17,9 @@ -# - if @game.winner_player_id || @game.nil? -# = button_to 'New Game', new_game_table_path(@table) - -# - if @game && !@game.startable? - #table-controls - #newgame= button_to 'New Game', new_game_table_path(@table) + - if @game && !@game.startable? + #table-controls + #newgame= button_to 'New Game', new_game_table_path(@table) -# #qrcode -# :javascript diff --git a/app/views/visitors/games_index.html.haml b/app/views/visitors/games_index.html.haml new file mode 100644 index 00000000..f5641244 --- /dev/null +++ b/app/views/visitors/games_index.html.haml @@ -0,0 +1,21 @@ +#home-headline.home-headline + %h1 Web3 Social Gaming
Crypto Rewards + +#main-menu + - if policy(:table).play_now? + = link_to 'Play 13 Now', play_now_path + - else + -# Soon + = link_to 'Browse Tables', tables_path + = link_to 'Tutorial', tutorial_path + = link_to 'About', page_path('about') + +-# - Dir.glob("app/assets/images/cards/png/**").each do |card_img| + - puts card_img + = image_tag + +-# %iframe#videoplayer{:allowfullscreen => "", :frameborder => "0", :height => "480", :mozallowfullscreen => "true", :src => "https://archive.org/embed/my-dinner-with-andre-conspiracy-theory-scene-hd", :webkitallowfullscreen => "true", :width => "640", :autostart => "true"} +-# %iframe{:allow => "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share", :allowfullscreen => "", :frameborder => "0", :height => "315", :src => "https://www.youtube.com/embed/kK-1axSGkXc", :title => "YouTube video player", :width => "560"} +-# %iframe#videoplayer{:allow => "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share", :allowfullscreen => "", :frameborder => "0", :height => "315", :src => "https://www.youtube.com/embed/PhIM5k_m_hs", :title => "YouTube video player", :width => "560"} +-# .video-cover +-# = video_tag "video.mp4", autoplay: true, id: "videoplayer", loop: true diff --git a/config/routes.rb b/config/routes.rb index d8a35f91..24c6aa36 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + get '/games', to: "visitors#games_index" resources :rooms do resources :messages end