JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
you can drag onto piles
authorJason Woofenden <jason@jasonwoof.com>
Wed, 2 Nov 2011 23:23:58 +0000 (19:23 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Wed, 2 Nov 2011 23:23:58 +0000 (19:23 -0400)
client.coffee
server.coffee

index 3022adb..95e1306 100644 (file)
@@ -54,6 +54,13 @@ new_blank_card = (x, y, css_class) ->
        $table.append view
        return view
 
        $table.append view
        return view
 
+find_pile = (x, y) ->
+       fudge = 40
+       for pile in piles
+               if -fudge < pile.x - x < fudge and -fudge < pile.y - y < fudge
+                       return pile
+       return null
+
 uninstantiate_card = (card) ->
        show_message "uninstantiate card #{card.number}"
        card.view.remove()
 uninstantiate_card = (card) ->
        show_message "uninstantiate card #{card.number}"
        card.view.remove()
@@ -98,8 +105,15 @@ instantiate_card = (card) ->
                update_pile_views()
        view.bind 'dragstop', (event, ui) ->
                p = view.position()
                update_pile_views()
        view.bind 'dragstop', (event, ui) ->
                p = view.position()
-               pile = null # FIXME figure out what pile we moved to
-               state.move state.agent, card.number, transform_x(p.left), transform_y(p.top), card.z, pile
+               x = transform_x(p.left)
+               y = transform_y(p.top)
+               pile = find_pile x, y
+               if pile?
+                       x = pile.x
+                       y = pile.y
+                       pile = pile.key
+                       view.css {left: transform_x(x), top: transform_y(y)}
+               state.move state.agent, card.number, x, y, card.z, pile
 
 error_lag = 3
 
 
 error_lag = 3
 
@@ -193,6 +207,8 @@ update_pile_views = ->
                                                uninstantiate_card ps[card.pile].top_card
                                        ps[card.pile].top_card = card
                                        ps[card.pile].top_z = card.z
                                                uninstantiate_card ps[card.pile].top_card
                                        ps[card.pile].top_card = card
                                        ps[card.pile].top_z = card.z
+                               else if card.view
+                                       uninstantiate_card card
                        else
                                ps[card.pile] = { total: 1, top_card: card, top_z: card.z }
 
                        else
                                ps[card.pile] = { total: 1, top_card: card, top_z: card.z }
 
@@ -232,7 +248,7 @@ init = ->
                if agent is me
                        tell_server ['move', agent, card, x, y, z, pile]
                else
                if agent is me
                        tell_server ['move', agent, card, x, y, z, pile]
                else
-                       # FIXME should we use the z from the server? Should p1 use odd numbers and p2 even?
+                       # FIXME use the z from the server
                        bring_card_to_front state.cards[card]
                        state.cards[card].view.animate { left: "#{transform_x x}px", top: "#{transform_y y}px"}, 800
        state.on 'mark', (agent, card, state) ->
                        bring_card_to_front state.cards[card]
                        state.cards[card].view.animate { left: "#{transform_x x}px", top: "#{transform_y y}px"}, 800
        state.on 'mark', (agent, card, state) ->
index 089523a..82e4872 100644 (file)
@@ -161,8 +161,8 @@ new_game = (id) ->
        game.p1_queue = []
        game.p2_queue = []
 
        game.p1_queue = []
        game.p2_queue = []
 
-       game.on 'move', (agent, card, x, y, z) ->
-               forward_events.call this, 'move', agent, card, x, y, z
+       game.on 'move', (agent, card, x, y, z, pile) ->
+               forward_events.call this, 'move', agent, card, x, y, z, pile
        game.on 'mark', (agent, card, state) ->
                forward_events.call this, 'mark', agent, card, state
        game.on 'flip', (agent, card, state) ->
        game.on 'mark', (agent, card, state) ->
                forward_events.call this, 'mark', agent, card, state
        game.on 'flip', (agent, card, state) ->