X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=client.coffee;h=967917da0ba60935a0c7c27dd4e9b53165c6e970;hb=9f3c815c1cc9fa0b68771487362065bd8df9a17e;hp=5459c7806c030d0ffc3368534a88bd53434ab7d0;hpb=a916776d54224addfe519950f2ea6b7c15bfb16c;p=peach-cgt.git diff --git a/client.coffee b/client.coffee index 5459c78..967917d 100644 --- a/client.coffee +++ b/client.coffee @@ -44,10 +44,18 @@ transform_y = (y) -> return y unless state.agent is 'p2' return flip_y y -next_card_z = -> return top_card_z += 1 +next_card_z = -> + top_card_z += 1 + # p1 gets even numbers, p2 gets odd numbers + if state.agent is 'p1' + top_card_z += top_card_z % 2 + else + top_card_z += 1 - (top_card_z % 2) + + show_message "new z: #{top_card_z}" + + return top_card_z -bring_card_to_front = (card) -> - card.view.css "z-index": next_card_z() new_blank_card = (x, y, css_class) -> view = $ $ "
" @@ -253,23 +261,27 @@ init = -> state = window.game_model.new me state.on 'move', (agent, card, x, y, z, pile) -> + if z > top_card_z + top_card_z = z update_pile_views() # ensures instantiation of all visible cards - if state.cards[card].view? # the card is visible + if @cards[card].view? # the card is visible # show it face down if it's in the other player's hand - state.cards[card].view.toggleClass 'your_hand', in_your_hand state.cards[card] + @cards[card].view.toggleClass 'your_hand', in_your_hand @cards[card] if agent is me tell_server ['move', agent, card, x, y, z, pile] else - # 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 + if @cards[card].view? + @cards[card].view.css "z-index": z + @cards[card].view.animate { left: "#{transform_x x}px", top: "#{transform_y y}px"}, 800 state.on 'mark', (agent, card, state) -> - @cards[card].view.toggleClass 'marked', state + if @cards[card].view? + @cards[card].view.toggleClass 'marked', state if agent is me tell_server ['mark', agent, card, state] state.on 'flip', (agent, card, state) -> - @cards[card].view.toggleClass 'flipped', state + if @cards[card].view? + @cards[card].view.toggleClass 'flipped', state if agent is me tell_server ['flip', agent, card, state] state.on 'set_cards', (agent, cards) ->