JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Piles display and removing cards mostly working
[peach-cgt.git] / common.coffee
index 3cf6867..d2667ac 100644 (file)
@@ -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) ->