Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

moving hacky lobby code to just use channel_id = 0

  • Loading branch information...
commit 22c08370fdb6cd935350a409c1938976b7cddcb1 1 parent 4bdab0d
@bjeanes authored
View
2  app/controllers/application.rb
@@ -12,7 +12,7 @@ def in_channel?(channel)
Juggernaut.client_in_channel?(current_user.id, channel)
end
- def update_user_list(channels = 'lobby')
+ def update_user_list(channels = 0)
channels = [*channels].flatten
channels.each do |channel|
View
10 app/controllers/messages_controller.rb
@@ -3,18 +3,16 @@ def create
@message = Message.new(params[:message])
@message.sender = current_user
- respond_to do |format|
- if in_channel?(@message.channel) && @message.save
- format.js { send_message }
- end
+ if @message.save!
+ send_message
end
+
+ render :nothing => true
end
protected
def send_message
message = render_to_string(:partial => 'messages/message', :object => @message)
Juggernaut.send_to_channel(javascript_chat_message(message), @message.channel)
-
- render :nothing => true
end
end
View
2  app/controllers/stream_controller.rb
@@ -8,7 +8,7 @@ def part
Juggernaut.send_to_channels(msg, params[:channels])
params[:channels].each do |channel|
- unless channel == 'lobby'
+ unless channel.to_i.zero?
game = Game.find(channel.to_i)
if game.started_at.nil? && game.owner == request_user
View
25 app/models/message.rb
@@ -7,18 +7,17 @@ class Message < ActiveRecord::Base
validates_presence_of :content
- validates_presence_of :channel_id, :if => :channel_required?
+ validates_presence_of :channel_id
# the order should be reversed for logical display in view for history
named_scope :history, :limit => 5, :order => 'created_at DESC'
- named_scope :for_lobby, :conditions => {:kind => 'lobby', :recipient_id => nil}
+ named_scope :for_lobby, :conditions => {:channel_id => 0, :recipient_id => nil}
for_channel_block = lambda { |channel|
raise "Missing game object for message finder" if channel.nil?
{
:conditions => {
- :kind => 'channel',
:channel_id => channel.id,
:recipient_id => nil}
}
@@ -27,13 +26,7 @@ class Message < ActiveRecord::Base
named_scope :for_channel, for_channel_block
def lobby?
- channel == 'lobby'
- end
-
- def channel
- return kind if kind == 'lobby'
-
- channel_id
+ channel_id.zero?
end
def sent!
@@ -41,17 +34,7 @@ def sent!
save!
end
- protected
-
- def recipient_required?
- self[:kind] == 'game'
- end
-
- def channel_required?
- self[:kind] != 'lobby'
- false
- end
-
+ protected
def before_create
self.sent = false if self.sent.nil?
true
View
5 app/views/lobby/index.html.erb
@@ -5,13 +5,14 @@
<%= juggernaut \
:host => request.host,
:client_id => current_user.id,
- :channels => ['lobby'] %>
+ :channels => [0] %>
<title>Tower Defense Lobby</title>
</head>
<body id="lobby">
<h3>Open Games <span>(games you can join)</span></h3>
<div id="games">
<ul>
+ <li><%= link_to "[Create game]", "/game/create" %></li>
<% Game.open.each do |game| %>
<li><a href="<%= join_game_path(game) %>"><%= game.name %></a></li>
<% end %>
@@ -19,7 +20,7 @@
</div>
<h3>Lobby Chat</h3>
- <%= render :partial => 'shared/chat', :locals => {:channel => 'lobby'} %>
+ <%= render :partial => 'shared/chat', :locals => {:channel => 0} %>
<div id="users">
<%= render :partial => 'shared/user_list', :locals => {:users => User.online} %>
View
1  app/views/shared/_chat.html.erb
@@ -12,7 +12,6 @@
<%= text_field_tag 'message[content]', '',
{ :id => 'message_content',
:disabled => true} %>
- <%= hidden_field_tag 'message[kind]', 'channel', {:id => 'message_kind'}%>
<%= hidden_field_tag 'message[channel_id]', channel, { :id => 'message_channel' } %>
<%#= hidden_field_tag 'authenticity_token', form_authenticity_token %>
<%= submit_tag "Send", {:id => "message_send", :disabled => true} %>
View
2  lib/tasks/juggernaut.rake
@@ -1,5 +1,5 @@
desc "Runs juggernaut server in background"
task 'juggernaut:run' do
`kill \`cat tmp/pids/juggernaut.pid\` > /dev/null 2>&1`
- `ruby vendor/gems/juggernaut/bin/juggernaut -e -d -c config/juggernaut.yml`
+ `ruby gvendor/gems/juggernaut/bin/juggernaut -e -d -c config/juggernaut.yml`
end
View
8 public/stylesheets/application.css
@@ -1,15 +1,9 @@
-/* @override
- http://towerdefense.local/stylesheets/application.css?1223390273
- http://towerdefense.local/stylesheets/application.css?1223421364
- http://towerdefense.local/stylesheets/application.css?1224062220
-*/
-
html,body{
margin: 0;
padding: 0;
}
-body { background-color: #000; color: #333; }
+body { background-color: #fff; color: #333; }
body, p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
Please sign in to comment.
Something went wrong with that request. Please try again.