JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
draw deck starting to work
authorJason Woofenden <jason@jasonwoof.com>
Tue, 1 Nov 2011 20:23:04 +0000 (16:23 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Tue, 1 Nov 2011 20:23:04 +0000 (16:23 -0400)
client.coffee
server.coffee

index 5a5341c..1e2c966 100644 (file)
@@ -150,32 +150,41 @@ initialize_cards = () ->
 
        # build piles
        piles = [
-               {key: 'p2_draw', x: transform_x(160), y: transform_y(20), name: "Draw Pile"}
+               {key: 'p2_draw', x: transform_x(140), y: transform_y(20), name: "Draw Pile"}
                {key: 'p2_discard', x: transform_x(20), y: transform_y(20), name: "Discard Pile"}
-               {key: 'p1_draw', x: transform_x(160), y: transform_y(flip_y(20)), name: "Draw Pile"}
+               {key: 'p1_draw', x: transform_x(140), y: transform_y(flip_y(20)), name: "Draw Pile"}
                {key: 'p1_discard', x: transform_x(20), y: transform_y(flip_y(20)), name: "Discard Pile"}
        ]
        for pile in piles
-               pile.$blank = new_blank_card pile.x, pile.y
-               count = 0
-               top = null
-               if state.piles[pile.key]?.length
-                       count = state.piles[pile.key].length
-                       top = state.piles[pile.key][0]
-               $caption = $ $ "<div class=\"pile_caption\"><div>#{pile.name}:</div><div class=\"n_cards\">#{n_cards count}</div></div>"
-               pile.$caption = $caption
-               if top?
-                       top.x = pile.x
-                       top.y = pile.y
-                       instantiate_card top
-                       top = top.view
-               else
-                       top = pile.$blank
-
-               top.append $caption
-
-               #pile.drag_handler = top.bind 'dragstart', ->
-               # FIXME
+               manage_pile = (pile) ->
+                       pile.$blank = new_blank_card pile.x, pile.y
+                       count = 0
+                       top = null
+                       if state.piles[pile.key]?.length
+                               count = state.piles[pile.key].length
+                               top = state.piles[pile.key][0]
+                       $caption = $ $ "<div class=\"pile_caption\"><div>#{pile.name}:</div><div class=\"n_cards\">#{n_cards count}</div></div>"
+                       pile.$caption = $caption
+                       if top?
+                               top.x = pile.x
+                               top.y = pile.y
+                               instantiate_card top
+                               view = top.view
+                       else
+                               view = pile.$blank
+
+                       view.append $caption
+
+                       if top?
+                               pile.drag_handler = view.bind 'dragstart', ->
+                                       pile.$caption.remove()
+                                       delete top.pile
+                                       state.piles[pile.key].shift()
+                                       manage_pile pile
+                                       # FIXME make sure this state change is sent
+                                       # FIXME handle this message coming in
+
+               manage_pile pile
 
 
 init = ->
index 43e0bc6..3ba1034 100644 (file)
@@ -191,9 +191,9 @@ test_init = ->
                        { text: "Ent 0/5", x: 800, y: 200, owner: 'p2'}
                        { text: "Carnivore 2/1", x: 220, y: 420, owner: 'p1'}
                        { text: "Herbivore 1/2", x: 360, y: 420, owner: 'p1'}
-                       { text: "Stone Wall 0/10", x: 500, y: 420, owner: 'p1'}
-                       { text: "Log 0/1", x: 660, y: 420, owner: 'p1', pile: 'p1_draw'}
-                       { text: "Ent 0/5", x: 800, y: 420, owner: 'p1'}
+                       { text: "Stone Wall 0/10", x: 500, y: 420, owner: 'p1', pile: 'p1_draw', flipped: true}
+                       { text: "Log 0/1", x: 660, y: 420, owner: 'p1', pile: 'p1_draw', flipped: true}
+                       { text: "Ent 0/5", x: 800, y: 420, owner: 'p1', pile: 'p1_draw', flipped: true}
                ]
 
 test_init()