Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonl99 committed Feb 16, 2017
1 parent 3e0353d commit 658f31c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
Binary file modified card_game
Binary file not shown.
2 changes: 1 addition & 1 deletion src/card_game/card_game.slang
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ div#hand
- hand.each_with_index do |card,idx|
span.card-holder
img.card src=card_image(card) data-item="#{dom_id}-card-#{idx}" data-event-attributes="src" data-events="click"
div#chat-room data-item=chat_room.dom_id
== chat_room.rendered_content
div#stats
span.game-name = "game: #{name}"
span.cards-remaining
Expand Down
13 changes: 12 additions & 1 deletion src/card_game/chat_room.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
require "./chat_message"
module CardGame
class ChatRoom < Lattice::Connected::StaticBuffer
class ChatRoom < Lattice::Connected::ObjectList

# Each chaat message rolls off the display (we don't keep all of them around)
# for this demo, we only keep the last five message.
@max_items = 5

def after_initialize
@items_dom_id = dom_id("items")
add_element_class "chat-room"
puts open_tag.colorize(:blue).on(:white)
end

def send_chat(chat_message : ChatMessage)
puts "Subscribers #{@subscribers.size} Add #{chat_message.content}"
add_content new_content: chat_message.content
end

Expand All @@ -25,6 +32,10 @@ module CardGame
# checking the dom-item since we only have one input form).
# this is where censoring could occurr (message = params["new-mesg"]...)
def on_event(event, sender)
session_id = event.session_id
puts session_id
puts "session_id #{session_id}"
puts "Received an #{event.event_type} #{event.direction} on session #{session_id} chat message #{event.message}"
if event.direction == "In" && event.session_id && (player_name = session_string(session_id: event.session_id.as(String), value_of: "name"))
message = event.message.as(Hash(String,JSON::Type))
action = message["action"]
Expand Down
9 changes: 4 additions & 5 deletions src/card_game/chat_room.slang
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
div.chat-room data-item=dom_id
div.message-holder data-item=dom_id(%{items})
== item_content
div#form-holder data-item=dom_id(%{form-holder})
== display_form
div.message-holder data-item=dom_id(%{items})
== item_content
div#form-holder data-item=dom_id(%{form-holder})
== display_form
10 changes: 5 additions & 5 deletions src/card_game/game_observer.cr
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
module CardGame

class GameObserver < Lattice::Connected::StaticBuffer
class GameObserver < Lattice::Connected::ObjectList
@max_items = 20
# When an event occurs, render it and add the rendered content
# def content
# # by putting this in rendered content we orverrid the autorendering
# render "./src/card_game/game_observer.slang"
# end
def after_initialize
add_element_class "observed-events"
end

def on_event( event, speaker )
if event.session_id && (session = Session.get event.session_id.as(String))
event_user = session.string?("name") || ""
end
add_content render "./src/card_game/observed_event.slang"
end

def after_initialize
# @element_class = "observed-events"
end

end
end

0 comments on commit 658f31c

Please sign in to comment.