Skip to content

Commit

Permalink
changed location of Faker data
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonl99 committed Feb 22, 2017
1 parent dfb89bb commit f510542
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ dependencies:
faker:
github: askn/faker
lattice-core:
# github: jasonl99/lattice-core
github: jasonl99/lattice-core
# branch: user_class
path: /home/jason/crystal/lattice-core
# path: /home/jason/crystal/lattice-core

sqlite3:
github: crystal-lang/crystal-sqlite3
Expand Down
16 changes: 2 additions & 14 deletions src/card_game.cr
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,8 @@ module CardGame
end

get "/cardgame/:game" do |context|
if context.session.id && (player = Player.find?(context.session.id) )
user_name = player.name
else
player = Player.new(context.session.id)
user_name = Faker::Name.first_name
player.name = user_name
end

# if (user_name = context.params.query["player_name"]?)
# context.session.string("name",user_name)
# end
# unless (user_name = context.session.string?("name"))
# context.session.string("name",user_name)
# end
player = Player.find_or_create(context.session.id)
user_name = player.name
game_name = context.params.url["game"]
begin
javascript, card_game = CardGame.preload(name: game_name, session_id: context.session.id, create: true)
Expand Down
4 changes: 2 additions & 2 deletions src/card_game/game_observer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ module CardGame
end

def on_event( event, speaker )
if (player = event.user)
if (player = event.user) && event.direction = "In"
event_user = player.as(Player).name
else
event_user = "Visitor"
event_user = "[Server]"
end
add_content render "./src/card_game/observed_event.slang"
end
Expand Down
7 changes: 6 additions & 1 deletion src/card_game/player.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ class Player < Lattice::BasicUser
puts "Player #{name} has left the table."
end

def default_name
Faker::Name.first_name
end

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

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

def name
@name ||= session_string("name","Visitor").as(String)
@name.as(String)
Expand Down

0 comments on commit f510542

Please sign in to comment.