JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
hide other players hand
authorJason Woofenden <jason@jasonwoof.com>
Thu, 3 Nov 2011 02:31:59 +0000 (22:31 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Thu, 3 Nov 2011 02:31:59 +0000 (22:31 -0400)
client.coffee
style.less

index 95e1306..139158d 100644 (file)
@@ -61,6 +61,9 @@ find_pile = (x, y) ->
                        return pile
        return null
 
                        return pile
        return null
 
+in_your_hand = (card) ->
+       return (not (card.pile?)) and ((transform_y card.y) < (card_height * 0.8))
+
 uninstantiate_card = (card) ->
        show_message "uninstantiate card #{card.number}"
        card.view.remove()
 uninstantiate_card = (card) ->
        show_message "uninstantiate card #{card.number}"
        card.view.remove()
@@ -77,6 +80,9 @@ instantiate_card = (card) ->
        else
                card_class = 'your_card'
 
        else
                card_class = 'your_card'
 
+       if in_your_hand card
+               card_class = "#{card_class} your_hand"
+
        if card.z > top_card_z
                top_card_z = card.z
 
        if card.z > top_card_z
                top_card_z = card.z
 
@@ -177,7 +183,6 @@ initialize_cards = () ->
        # instantiate cards in play
        for card in state.cards
                delete card.view
        # instantiate cards in play
        for card in state.cards
                delete card.view
-               instantiate_card card unless card.pile?
 
        unless piles?
                piles = [ # global
 
        unless piles?
                piles = [ # global
@@ -196,6 +201,7 @@ initialize_cards = () ->
 
        update_pile_views()
 
 
        update_pile_views()
 
+# also makes sure all non-piled cards are instantiated FIXME rename
 update_pile_views = ->
        ps = {}
        for card in state.cards
 update_pile_views = ->
        ps = {}
        for card in state.cards
@@ -211,6 +217,9 @@ update_pile_views = ->
                                        uninstantiate_card card
                        else
                                ps[card.pile] = { total: 1, top_card: card, top_z: card.z }
                                        uninstantiate_card card
                        else
                                ps[card.pile] = { total: 1, top_card: card, top_z: card.z }
+               else
+                       # not in a pile
+                       instantiate_card card unless card.view?
 
        for pile in piles
                # where should the caption be?
 
        for pile in piles
                # where should the caption be?
@@ -245,6 +254,10 @@ init = ->
        state = window.game_model.new me
        state.on 'move', (agent, card, x, y, z, pile) ->
                update_pile_views()
        state = window.game_model.new me
        state.on 'move', (agent, card, x, y, z, pile) ->
                update_pile_views()
+               if state.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]
+
                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
index 2473abf..31bb99d 100644 (file)
@@ -102,7 +102,7 @@ h1 {
        border-color: black;
 }
 
        border-color: black;
 }
 
-.flipped {
+.flipped, .your_hand {
        .cardtext {
                display: none;
        }
        .cardtext {
                display: none;
        }