X-Git-Url: https://jasonwoof.com/gitweb/?p=peach-cgt.git;a=blobdiff_plain;f=common.coffee;h=d2667ace0dda127e9ad8169d83abcf3deff43fbe;hp=3cf6867af2bd2a0ef15ceca5513290dbc5ba5652;hb=078a999a7b7ed2ae37e27d88b3039221fbc1d90c;hpb=e39c3d01d9c40b425168f1f8dcb2d9ddef975808 diff --git a/common.coffee b/common.coffee index 3cf6867..d2667ac 100644 --- a/common.coffee +++ b/common.coffee @@ -12,7 +12,6 @@ class GameState @agent = agent @hooks = {} @cards = [] - @piles = {} on: (event, callback) -> unless @hooks[event]? @hooks[event] = [] @@ -21,17 +20,19 @@ class GameState return unless @hooks[event]? for callback in @hooks[event] callback.apply this, args - move: (agent, card, x, y, z) -> # FIXME add pile argument + move: (agent, card, x, y, z, pile) -> # FIXME what to do on error? - return unless @cards[card]? #?.pile? - #cur_pile = cards[card].pile - #if pile isnt cur_pile + return unless @cards[card]? @cards[card].x = x @cards[card].y = y @cards[card].z = z + if pile? + @cards[card].pile = pile + else if @cards[card].pile? + delete @cards[card].pile - @trigger 'move', agent, card, x, y, z # FIXME add pile argument + @trigger 'move', agent, card, x, y, z, pile mark: (agent, card, state) -> # FIXME what to do on error? @@ -49,14 +50,10 @@ class GameState set_cards: (agent, cards) -> @cards = [] - @piles = {} for card in cards - card.number = @cards.length + card.number = @cards.length unless card.number + card.z = @cards.length unless card.z @cards.push card - if card.pile? - unless @piles[card.pile]? - @piles[card.pile] = [] - @piles[card.pile].push card @trigger 'set_cards', agent, @cards send_state: (agent) ->