From: Jason Woofenden Date: Thu, 27 Oct 2011 18:56:14 +0000 (-0400) Subject: add agent argument to set_cards X-Git-Url: https://jasonwoof.com/gitweb/?p=peach-cgt.git;a=commitdiff_plain;h=7797a9aab5a31f89b84ebc86c5a7bc3d12ef6602 add agent argument to set_cards --- diff --git a/client.coffee b/client.coffee index fbe2815..63fd6c6 100644 --- a/client.coffee +++ b/client.coffee @@ -120,11 +120,13 @@ init = -> @cards[card].view.toggleClass 'flipped', state if agent is me tell_server ['flip', agent, card, state] - state.on 'set_cards', (cards) -> + state.on 'set_cards', (agent, cards) -> # FIXME add agent arg and tell server if it's not us $('.card').remove() for card in cards instantiate_card card + if agent is me + tell_server ['set_cards', agent, cards] # timeout so browser will stop showing that we're loading timeout 1, poll_for_updates diff --git a/common.coffee b/common.coffee index ce09f13..cc33785 100644 --- a/common.coffee +++ b/common.coffee @@ -46,7 +46,7 @@ class GameState # FIXME implement set_pile(pile, card_order_array) - set_cards: (cards) -> + set_cards: (agent, cards) -> @cards = [] @piles = {} for card in cards @@ -56,7 +56,7 @@ class GameState unless @piles[card.pile]? @piles[card.pile] = [] @piles[card.pile].push card - @trigger 'set_cards', @cards + @trigger 'set_cards', agent, @cards process_messages: (messages) -> unless typeof messages is 'array' or typeof messages is 'object' diff --git a/server.coffee b/server.coffee index ab0ca9f..29cddb1 100644 --- a/server.coffee +++ b/server.coffee @@ -169,15 +169,15 @@ new_game = (id) -> forward_events.call this, 'mark', agent, card, state game.on 'flip', (agent, card, state) -> forward_events.call this, 'flip', agent, card, state - game.on 'set_cards', (cards) -> - forward_events.call this, 'set_cards', cards + game.on 'set_cards', (agent, cards) -> + forward_events.call this, 'set_cards', agent, cards return game test_init = -> test_game = new_game 'test' timeout 4000, -> - test_game.set_cards [ + test_game.set_cards 'server', [ { text: "Wildabeast 2/2", x: 20, y: 140} { text: "Wild beast 2/2", x: 150, y: 140} { text: "Angora bunny 1/1", x: 300, y: 140}