From: Jason Woofenden Date: Wed, 2 Nov 2011 22:43:31 +0000 (-0400) Subject: fix view (flip x too), arrange piles correctly X-Git-Url: https://jasonwoof.com/gitweb/?p=peach-cgt.git;a=commitdiff_plain;h=30e517112298f4b68f6f2f5e1e634af4848e1d6c fix view (flip x too), arrange piles correctly --- diff --git a/client.coffee b/client.coffee index f47f0a1..3022adb 100644 --- a/client.coffee +++ b/client.coffee @@ -1,6 +1,8 @@ # globals $table = null +table_width = 0 table_height = 0 +card_width = 0 card_height = 0 state = null server_url = null @@ -33,8 +35,11 @@ new_button = (text) -> $ $ "
#{text}
" # transform coordinates from client-side coords to server-side coords (or back) # this makes it so p2 view everything upside down (mirrored), but still sends coords rightside up +flip_x = (x) -> table_width - card_width - x flip_y = (y) -> table_height - card_height - y -transform_x = (x) -> x +transform_x = (x) -> + return x unless state.agent is 'p2' + return flip_x x transform_y = (y) -> return y unless state.agent is 'p2' return flip_y y @@ -44,8 +49,8 @@ next_card_z = -> return top_card_z += 1 bring_card_to_front = (card) -> card.view.css "z-index": next_card_z() -new_blank_card = (x, y) -> - view = $ $ "
" +new_blank_card = (x, y, css_class) -> + view = $ $ "
" $table.append view return view @@ -162,13 +167,17 @@ initialize_cards = () -> unless piles? piles = [ # global - {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(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"} + {key: 'p2_draw', x: 140, y: 20, name: "Draw Pile"} + {key: 'p2_discard', x: 20, y: 20, name: "Discard Pile"} + {key: 'p1_draw', x: flip_x(140), y: flip_y(20), name: "Draw Pile"} + {key: 'p1_discard', x: flip_x(20), y: flip_y(20), name: "Discard Pile"} ] for pile in piles - pile.$blank = new_blank_card pile.x, pile.y + if pile.key.substr(0, 2) is state.agent + css_class = 'my_card' + else + css_class = 'your_card' + pile.$blank = new_blank_card pile.x, pile.y, css_class pile.$caption = $ $ "
#{pile.name}:
#{n_cards 0}
" update_pile_views() @@ -247,7 +256,9 @@ init = -> $ -> $table = $ '#table' + table_width = $table.width() table_height = $table.height() + card_width = $('#loading-card').outerWidth() card_height = $('#loading-card').outerHeight() init() diff --git a/index.html b/index.html index 797982e..83e4324 100644 --- a/index.html +++ b/index.html @@ -14,6 +14,12 @@

Card Table

-
Loading...
+
+
+
+
Loading...
+
+
Cards in this green area (besides the piles on the right) always appear face-down to the other player.
+