mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-11-15 09:21:25 +00:00
ebd60d19eb
This will change the gather format to allow for players to volunteer to be captain / commander. The gather will not change from the running state until 2 commanders have volunteered. Once commanders have volunteered the gather will switch to the picking state. The voting state is no longer used. Also, added a new sound alert that will be played when the gather is full but doesn't have 2 captains. This alert will loop every 10 seconds unless you're the commander. And changed the music to play once the gather switches to the picking state and only if the player doesn't have the gather page on focus.
111 lines
2.6 KiB
Ruby
111 lines
2.6 KiB
Ruby
class GathersController < ApplicationController
|
|
before_filter :get_gather, except: [:latest, :index, :create]
|
|
respond_to :html, :js
|
|
|
|
def index
|
|
@gathers = Gather.ordered.limit(50).all
|
|
end
|
|
|
|
def show
|
|
render layout: 'full'
|
|
end
|
|
|
|
def latest
|
|
@gather = Gather.last(params[:game])
|
|
redirect_to @gather
|
|
end
|
|
|
|
def edit
|
|
@gather.admin = true
|
|
end
|
|
|
|
def create
|
|
@gather = Gather.new
|
|
@gather.category_id = params[:gather][:category_id]
|
|
raise AccessError unless @gather.can_create? cuser
|
|
|
|
if @gather.save
|
|
flash[:notice] = t(:gather_create)
|
|
end
|
|
|
|
redirect_to_back
|
|
end
|
|
|
|
def update
|
|
@gather = Gather.basic.find(params[:id])
|
|
raise AccessError unless @gather.can_update? cuser
|
|
|
|
Gatherer.transaction do
|
|
Gather.transaction do
|
|
if @gather.update_attributes params[:gather]
|
|
flash[:notice] = 'Gather was successfully updated.'
|
|
end
|
|
end
|
|
end
|
|
|
|
redirect_to @gather
|
|
end
|
|
|
|
def pick
|
|
@gatherer = @gather.gatherers.find(params[:player])
|
|
raise AccessError unless @gatherer.can_update? cuser, params
|
|
|
|
Gatherer.transaction do
|
|
Gather.transaction do
|
|
if @gatherer.update_attribute :team, @gatherer.gather.turn
|
|
flash[:notice] = t(:gathers_user_pick)
|
|
else
|
|
flash[:error] = @gatherer.errors.full_messages.to_s
|
|
end
|
|
end
|
|
end
|
|
|
|
redirect_to @gather
|
|
end
|
|
|
|
def captain
|
|
raise AccessError unless @gatherer
|
|
|
|
if @gather.captain1.nil? and @gather.captain2 != @gatherer
|
|
@gather.update_attribute :captain1, @gatherer
|
|
elsif @gather.captain2.nil? and @gather.captain1 != @gatherer
|
|
@gather.update_attribute :captain2, @gatherer
|
|
elsif @gatherer == @gather.captain1
|
|
@gather.update_attribute :captain1, nil
|
|
elsif @gatherer == @gather.captain2
|
|
@gather.update_attribute :captain2, nil
|
|
end
|
|
|
|
redirect_to @gather
|
|
end
|
|
|
|
private
|
|
|
|
def get_gather
|
|
Gather.transaction do
|
|
@gather = Gather.basic.find(params[:id], :lock => true)
|
|
@gather.refresh cuser
|
|
end
|
|
|
|
@gatherer = @gather.gatherers.of_user(cuser).first if cuser
|
|
update_gatherers
|
|
end
|
|
|
|
def update_gatherers
|
|
# Update user that has left and came back
|
|
if @gatherer and @gatherer.status == Gatherer::STATE_LEAVING
|
|
@gatherer.update_attribute(:status, Gatherer::STATE_ACTIVE)
|
|
end
|
|
|
|
# Remove any users that left over 30 seconds ago
|
|
removed_users = false
|
|
@gather.gatherers.each do |gatherer|
|
|
if gatherer.status == Gatherer::STATE_LEAVING and gatherer.updated_at < Time.now - 30
|
|
removed_users = true
|
|
gatherer.destroy
|
|
end
|
|
end
|
|
|
|
@gather.reload if removed_users
|
|
end
|
|
end
|