Skip to content

Commit

Permalink
lattice changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonl99 committed Feb 23, 2017
1 parent f510542 commit 39795ce
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
8 changes: 4 additions & 4 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ shards:

faker:
github: askn/faker
version: 0.2.0
version: 0.3.0

kemal:
github: kemalcr/kemal
commit: 14de5c79fb4b2119ace055990dc26be7a672bfbd
commit: e3aea753b56316fda283031ae63f6f1fec0bf067

kemal-session:
path: /home/jason/crystal/kemal-session
version: 0.7.0
github: jasonl99/kemal-session
commit: 0b8f0cc9884871e60b8704b2bbe827d6b86ce53c

kilt:
github: jeromegn/kilt
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
github: askn/faker
lattice-core:
github: jasonl99/lattice-core
# branch: user_class
branch: master
# path: /home/jason/crystal/lattice-core

sqlite3:
Expand Down
19 changes: 13 additions & 6 deletions src/card_game/card_game.cr
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ module CardGame

end

def subscribed( session_id, socket)
chat_room.subscribe(socket, session_id) ##
game_observer.subscribe(socket, session_id)
# if (session = Session.get session_id) && (player_name = session.string?("name") )
# Storage.connection.exec "insert into player_game (player, game) values (?,?)", player_name, name
# end
def subscribed( player : Player )
if ( player_name = player.name ) && (socket = player.socket)
personalize = {"id"=>"#{dom_id}-chatname", "attribute"=>"value", "value"=>player_name}
update_attribute(personalize, [socket])
end
end

# def subscribed( session_id, socket)
# chat_room.subscribe(socket, session_id) ##
# game_observer.subscribe(socket, session_id)
# # if (session = Session.get session_id) && (player_name = session.string?("name") )
# # Storage.connection.exec "insert into player_game (player, game) values (?,?)", player_name, name
# # end
# end

def draw_card
self.deck = new_deck if self.deck.size == 0
card = deck.sample
Expand Down
20 changes: 14 additions & 6 deletions src/card_game/chat_room.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@ module CardGame
add_content new_content: chat_message.content
end

# when a new user is subscribed, the chat input box is personalized with their name
# All users get the same initial page, but each is individuall customized
# over the socket.
def subscribed(session_id : String, socket : HTTP::WebSocket)
if (user_name = session_string(session_id: session_id, value_of: "name"))
personalize = {"id"=>"#{dom_id}-chatname", "attribute"=>"value", "value"=>user_name}
def subscribed( player : Player )
if ( player_name = player.name ) && (socket = player.socket)
personalize = {"id"=>"#{dom_id}-chatname", "attribute"=>"value", "value"=>player_name}
update_attribute(personalize, [socket])
end
super
end

# when a new user is subscribed, the chat input box is personalized with their name
# All users get the same initial page, but each is individuall customized
# over the socket.
# def subscribed(session_id : String, socket : HTTP::WebSocket)
# if (user_name = session_string(session_id: session_id, value_of: "name"))
# personalize = {"id"=>"#{dom_id}-chatname", "attribute"=>"value", "value"=>user_name}
# update_attribute(personalize, [socket])
# end
# super
# end

# the only event we really do anything with is an action submit (we don't even bother
# checking the dom-item since we only have one input form).
# this is where censoring could occurr (message = params["new-mesg"]...)
Expand Down
20 changes: 17 additions & 3 deletions src/card_game/player.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ class Player < Lattice::BasicUser
end

def load
@name = @session.as(Session).string?("name") || default_name
if @session
@name = @session.as(Session).string?("name")
end
unless @name
@name = default_name
save
end

end

def save
if (session = @session )
session.string("name",@name.as(String)) if @name
end
end

def name=(@name)
Expand All @@ -24,8 +37,9 @@ class Player < Lattice::BasicUser

# TODO macros for each type
def session_string( key : String, default ) : String
if @session
@session.as(Session).string?(key).as(String)
if (session = @session) && (key = session.as(Session).string?(key))
key.as(String)
# @session.as(Session).string?(key).as(String)
else
default
end
Expand Down

0 comments on commit 39795ce

Please sign in to comment.