Rewrite without react. Can sit stand at a table

This commit is contained in:
Jesse C. Fisher 2019-10-19 00:38:33 -07:00
parent 5987c3caf3
commit e5145206f8
8 changed files with 204 additions and 18 deletions

View File

@ -66,10 +66,18 @@ class SeatsController < ApplicationController
# POST /seats/1
def sit
@message = @seat.sit current_user
respond_to do |format|
if @seat.save
format.html { redirect_to @seat.table, notice: 'Seat was successfully sat in.' }
else
format.html { redirect_to @seat.table, notice: 'Failed to sit.' }
end
end
end
def stand
@message = @seat.stand current_user
redirect_to @seat.table, notice: @message
end
private

View File

@ -67,6 +67,8 @@ class TablesController < ApplicationController
# Use callbacks to share common setup or constraints between actions.
def set_table
@table = Table.find(params[:id])
@game = @table.current_game
@seats = @table.seats.order(:id)
end
# Never trust parameters from the scary internet, only allow the white list through.

View File

@ -21,11 +21,11 @@ class Seat < ActiveRecord::Base
end
end
def stand(current_user)
unless self.occupied_by?(current_user)
def stand(user)
unless self.occupied_by?(user)
return "Error. Seat not occupied by you."
else
self.table.current_game.remove_player_from_user(current_user)
self.table.current_game.remove_player_from_user(user)
self.user_id = nil
self.user_soft_token = nil
self.player_id = nil

View File

@ -1,32 +1,31 @@
#game-component-container-container= react_component 'Game', props = {id: @game.id, current_user: current_user}, html_options = {id: "game-component-container"}
-# #game-component-container-container= react_component 'Game', props = {id: @game.id, current_user: current_user}, html_options = {id: "game-component-container"}
-# TODO: Remove deprecated commented out code
-#%p
%b Status:
%p
= @game.status
-#%p
%p
%b Title:
= @game.title
-#- if @game.can_accomodate(current_user)
- if @game.can_accomodate(current_user)
= link_to 'Join', game_join_path(@game)
-#- if @game.startable? && @game.already_has?(current_user)
- if @game.startable? && @game.already_has?(current_user)
= link_to 'Start', game_start_path(@game)
-#.debug
= button_to 'Debug Start', game_start_path(@game), method: :get
= link_to 'Edit Game', edit_game_path(@game)
-#.players
.players
%b Players:
%ol
- @game.players.each do |player|
%li
// Show the users email TODO show username instead
= player.user.email
= player.display_name
// Show the user which player they are
= "Me" if player.user == current_user
@ -39,9 +38,10 @@
- if player.user == current_user && player.inventory.empty? == false
-##inventory
-# TODO better logic, not in view
-#- unless @game.status == nil
-#.table
- unless @game.status == nil
.table
-# TODO better logic, not in view. Set play to beat = nil; instead of view logic
- if @game.play_to_beat && @game.player_to_beat != @game.controlling_player
- if @game.play_to_beat.play
@ -49,9 +49,9 @@
Hand to beat
%span.hand-type= @game.play_to_beat.play.hand_type
%div= @game.play_to_beat.play.to_s
-#- @game.play_to_beat.play.player_cards.each do |card|
- @game.play_to_beat.play.player_cards.each do |card|
= card.to_s
%span.player= @game.play_to_beat.play.player.user.email
%span.player= @game.play_to_beat.play.player.display_name
- else
%h1 Open table

View File

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<!DOCTYPE html>
<head>
<title>ThirteenTienLen</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>

View File

@ -3,4 +3,100 @@
= link_to 'Edit', edit_table_path(@table)
= link_to 'Destroy', game, :method => :delete, :data => { :confirm => 'Are you sure?' }
#table-component-container-container= react_component 'Table', props = {url: "#{table_path @table}"}, html_options = {id: "table-component-container"}
-# #table-component-container-container= react_component 'Table', props = {url: "#{table_path @table}"}, html_options = {id: "table-component-container"}
%h1= @table.title
- if @game.startable? && @game.already_has?(current_user)
= link_to 'Start', game_start_path(@game)
-#.debug
= button_to 'Debug Start', game_start_path(@game), method: :get
= link_to 'Edit Game', edit_game_path(@game)
.players
%b Players:
%ol
- @game.players.each do |player|
%li
= player.display_name
// Show the user which player they are
= "Me" if player.soft_token == current_user.soft_token
// Show whose turn it is
- if @game.controlling_player_id
%strong= "My Turn " if @game.controlling_player == player
// Show the players' cards
- if player.user == current_user && player.inventory.empty? == false
-##inventory
%p
%b Game:
= @game.title
%p
= @game.status
-# TODO better logic, not in view
- unless @game.status == nil
.table
-# TODO better logic, not in view. Set play to beat = nil; instead of view logic
- if @game.play_to_beat && @game.player_to_beat != @game.controlling_player
- if @game.play_to_beat.play
%h1
Hand to beat
%span.hand-type= @game.play_to_beat.play.hand_type
%div= @game.play_to_beat.play.to_s
- @game.play_to_beat.play.player_cards.each do |card|
= card.to_s
%span.player= @game.play_to_beat.play.player.display_name
- else
%h1 Open table
.controls
- if @game.control_user == current_user
// Play hand form
= form_for @game, :url => play_hand_game_path(@game), remote: true do |f|
// Provide id of current game
-#= f.hidden_field :id
= f.submit "Play Hand"
= form_for @game, :url => play_hand_game_path(@game) do |f|
// Provide id of current game
-#= f.hidden_field :id
= f.hidden_field :hand_type, value: 'pass'
= f.submit "Pass"
#game-component
%h1= @game.title
- if @game.started?
- else
%section#game-controls
-# TODO: If not joinable, show why. i.e. game full
-# TODO: DEPRECATED use seat sit instead this.state.data.is_joinable ? <button onClick={this.handleJoin}>Join</button> : null
-# TODO: If not startable, show why. i.e. need more players
-# - if @game.can_accomodate(current_user)
= button_to "Join", join_game_path(@game)
#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

View File

@ -7,9 +7,20 @@ Rails.application.routes.draw do
patch 'stand'
end
end
resources :games
resources :games do
# member do
# post :join
# end
end
end
resources :seats do
member do
post 'sit'
post 'stand'
end
end
resources :games do
member do
get 'my-inventory'

69
stashtable.txt Normal file
View File

@ -0,0 +1,69 @@
{/* Show player controls if player is owned by current_user */}
{(this.props.soft_token == this.props.game.current_user_soft_token) && (this.props.game.is_started == true)
? (<PlayerControls
key={this.props.id}
onPlayHandSubmit={this.props.onPlayHandSubmit}
game_id={this.props.game.id}
player_id={this.props.id}
inventory={this.props.inventory}
controlling_player_id={this.props.game.controlling_player_id} /> )
:
<div className='inventory'>
{[...Array(this.props.inventory_count)].map((card, index) => <img key={index} src='/assets/cards/png/back-pink.png' />)}
</div>
}
</div>
<Player
game={this.props.game}
onPlayHandSubmit={this.props.onPlayHandSubmit}
{...this.props.player} />
: "Empty" }
</div>
<Seat
{...this.props.game.seats[0]}
game={this.props.game}
onPlayHandSubmit={this.props.onPlayHandSubmit}
current_user={this.props.current_user}
onSeatSubmit={this.props.onSeatSubmit} />
</div>
</div>
<div id="mid">
<div className="game-seat position-2">
<Seat
{...this.props.game.seats[1]}
game={this.props.game}
onPlayHandSubmit={this.props.onPlayHandSubmit}
current_user={this.props.current_user}
onSeatSubmit={this.props.onSeatSubmit} />
</div>
<HandToBeat cards={this.props.game.cards_to_beat} />
<div className="game-seat position-3">
<Seat
{...this.props.game.seats[2]}
game={this.props.game}
onPlayHandSubmit={this.props.onPlayHandSubmit}
current_user={this.props.current_user}
onSeatSubmit={this.props.onSeatSubmit} />
</div>
</div>
<div id="bot">
<div className="game-seat position-4">
<Seat
{...this.props.game.seats[3]}
game={this.props.game}
onPlayHandSubmit={this.props.onPlayHandSubmit}
current_user={this.props.current_user}
onSeatSubmit={this.props.onSeatSubmit} />
</div>
</div>
</div>