From 2a9c4a6a76a3af7fe86740eb4343151cc83d4631 Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Sun, 20 Oct 2019 16:55:12 -0700 Subject: [PATCH] Adds top seat, player, controls --- app/controllers/games_controller.rb | 2 +- app/views/games/show.html.haml | 4 +-- app/views/tables/_seat.html.haml | 36 +++++++++++++++++++++ app/views/tables/_seats.html.haml | 0 app/views/tables/show.html.haml | 50 ++++------------------------- 5 files changed, 45 insertions(+), 47 deletions(-) create mode 100644 app/views/tables/_seat.html.haml create mode 100644 app/views/tables/_seats.html.haml diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 69fccde..6b9587f 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -123,7 +123,7 @@ class GamesController < ApplicationController @game.errors.messages.each do |key, msg| flash[key] = msg.join end - redirect_to(@game) + redirect_to(@game.table) return end flash[:notice] = 'Game started.' diff --git a/app/views/games/show.html.haml b/app/views/games/show.html.haml index 8b91b28..b1ded1b 100644 --- a/app/views/games/show.html.haml +++ b/app/views/games/show.html.haml @@ -13,7 +13,7 @@ = link_to 'Join', game_join_path(@game) - if @game.startable? && @game.already_has?(current_user) - = link_to 'Start', game_start_path(@game) + = link_to 'Start', start_game_path(@game) -#.debug = button_to 'Debug Start', game_start_path(@game), method: :get @@ -56,7 +56,7 @@ %h1 Open table .controls - - if @game.control_user == current_user + - if @game.controlling_user == current_user // Play hand form = form_for @game, :url => play_hand_game_path(@game), remote: true do |f| // Provide id of current game diff --git a/app/views/tables/_seat.html.haml b/app/views/tables/_seat.html.haml new file mode 100644 index 0000000..92db7fe --- /dev/null +++ b/app/views/tables/_seat.html.haml @@ -0,0 +1,36 @@ +- @game = seat.game +.seat + .seat-controls + - if seat.occupied? + - if seat.occupied_by? current_user + = button_to "Stand", + stand_seat_path(seat) + - else + = button_to "Sit", + sit_seat_path(seat) + + - if seat.player + .player + .user-name= seat.player.display_name + - if @game.started? + %h1 hi + .inventory-count= seat.player.inventory.count + + -# Show player controls if player is owned by current_user + - if seat.player.soft_token = current_user.soft_token + = form_for @game, play_hand_game_path do |f| + %ul#inventory + - seat.player.inventory.each do |card| + %li + %label + %input{form: "player_controls_" + card.player_id, + type: "checkbox", + name: "player_card_ids[]", + data: {card_name: card.rank.gsub('11','J') .gsub('12','Q') .gsub('13','K') .gsub('14','A') .gsub('15','2') + ' ' + card.suit}, value: card.id} + %img{src: "/assets/cards/png/" + (card.rank.gsub('J','jack').gsub('Q','queen').gsub('K','king').gsub('A','ace') + '_of_' + card.suit.downcase + "s.png").gsub('11','jack') .gsub('12','queen') .gsub('13','king') .gsub('14','ace') .gsub('15','2') } + -# = image_tag("hi") + + %input{type: "submit", value: "Play Hand", name: "commit"} + -# %input{type: "submit", value: "Pass", name: "pass"} + = f.submit "Pass" + diff --git a/app/views/tables/_seats.html.haml b/app/views/tables/_seats.html.haml new file mode 100644 index 0000000..e69de29 diff --git a/app/views/tables/show.html.haml b/app/views/tables/show.html.haml index d459b68..82983d8 100644 --- a/app/views/tables/show.html.haml +++ b/app/views/tables/show.html.haml @@ -7,7 +7,7 @@ %h1= @table.title - if @game.startable? && @game.already_has?(current_user) - = link_to 'Start', game_start_path(@game) + = button_to 'Start', start_game_path(@game) -#.debug = button_to 'Debug Start', game_start_path(@game), method: :get @@ -54,8 +54,8 @@ - else %h1 Open table - .controls - - if @game.control_user == current_user + -# .controls + - if @game.controlling_player.soft_token == current_user.soft_token // Play hand form = form_for @game, :url => play_hand_game_path(@game), remote: true do |f| // Provide id of current game @@ -83,45 +83,7 @@ #playerList #top - .game-seat.position-1 - .seat - .seat-controls - - if @seats[0].occupied? - - if @seats[0].occupied_by? current_user - = button_to "Stand", - stand_seat_path(@seats[0]) - - else - = button_to "Sit", - sit_seat_path(@seats[0]) - - - if @seats[0].player - .player - .user-name= @seats[0].player.display_name - - if @game.started? - .inventory-count= @seats[0].player.inventory.count - - -# Show player controls if player is owned by current_user - - if @seats[0].player.soft_token = current_user.soft_token - = form_for @game, play_hand_game_path - %ul#inventory - - @seats[0].player.inventory.each do |card| - %li - %label - %input{form: "player_controls_" + card.player_id, - type: "checkbox", - name: "player_card_ids[]", - data: {card_name: card.rank.gsub('11','J') .gsub('12','Q') .gsub('13','K') .gsub('14','A') .gsub('15','2') + ' ' + card.suit}, value: card.id} - %img{src: "/assets/cards/png/" + (card.rank.gsub('J','jack').gsub('Q','queen').gsub('K','king').gsub('A','ace') + '_of_' + card.suit.downcase + "s.png").gsub('11','jack') .gsub('12','queen') .gsub('13','king') .gsub('14','ace') .gsub('15','2') } - -# = image_tag("hi") - - - %input{type: "submit", - value: "Play Hand", - name: "commit"} - - %input{disabled: (@game.controlling_player_id == @seats[0].player.id ? nil : "disabled"), - type: "submit", - value: "Pass", - name: "pass"} - + = render "seat", seat: @seats[0] + #mid + = render "seat", seat: @seats[1]