From b66599910416c06551a421273cca2060b4ad91f6 Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Sat, 26 Oct 2019 05:21:20 -0700 Subject: [PATCH] Imorove turn logic regress new end of game bugs --- app/controllers/games_controller.rb | 13 +++++-------- app/controllers/tables_controller.rb | 6 ++++++ app/models/game.rb | 7 ++++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index b315ad3a..2da309f4 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -36,15 +36,12 @@ class GamesController < ApplicationController # Player action: pass # TODO: wtf do we need game params for? And why nest hand_type in it? # if params[:game] - if params[:hand_type] == 'Pass' - @game.set_controlling_player 'next' - flash[:notice] = 'Successfully passed.' - @game.save - end - # end - + if params[:hand_type] == 'Pass' + @game.set_controlling_player 'next' + flash[:notice] = 'Successfully passed.' + @game.save # Player action: play_hand - if params[:player_card_ids] + elsif params[:player_card_ids] @cards_to_play = @game.controlling_player.try(:player_cards).order(:value).find(params[:player_card_ids]) # Instantiate the play @play = @game.controlling_player.plays.new diff --git a/app/controllers/tables_controller.rb b/app/controllers/tables_controller.rb index cff7b2ca..1267a532 100644 --- a/app/controllers/tables_controller.rb +++ b/app/controllers/tables_controller.rb @@ -30,6 +30,12 @@ class TablesController < ApplicationController # GET /tables/1 # GET /tables/1.json def show + # TODO move this to the game.rb model + # Clear play to beat if play returns to owner + if @game.play_to_beat.try(:player).try(:id) == @game.controlling_player_id + @game.play_to_beat_id = nil + @game.save + end end # GET /tables/new diff --git a/app/models/game.rb b/app/models/game.rb index 98992570..823ccfec 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -126,9 +126,9 @@ class Game < ActiveRecord::Base end # Clear play to beat if play returns to owner - if self.play_to_beat.try(:player).try(:id) == self.controlling_player_id - self.play_to_beat_id = nil - end + # if self.play_to_beat.try(:player).try(:id) == self.controlling_player_id + # self.play_to_beat_id = nil + # end end def joinable? user @@ -141,6 +141,7 @@ class Game < ActiveRecord::Base def next_player_id @controlling_player_index = self.player_ids_by_seat_order.index(controlling_player_id) + @controlling_player_index ||= 0 player_ids_by_seat_order[(@controlling_player_index + 1) % self.player_ids_by_seat_order.length] end