From 3f89f7dbaf990e3f219c1c782fe55455eaa68cbc Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Thu, 27 Oct 2011 17:19:15 -0400 Subject: [PATCH] player 2 sees table mirrored vertically --- client.coffee | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/client.coffee b/client.coffee index 177f3b4..7f22674 100644 --- a/client.coffee +++ b/client.coffee @@ -1,5 +1,6 @@ # globals $table = null +table_height = 0 state = null server_url = null @@ -23,11 +24,18 @@ unless Array::shuffle? 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 +transform_coords = (coords) -> + ret = {left: coords.left, top: coords.top} + if state.agent is 'p2' + ret.top = table_height - ret.top + return ret + instantiate_card = (card) -> text = card.text - x = card.x - y = card.y - view = $ $ "
#{text}
" + view_coords = transform_coords {left: card.x, top: card.y} + view = $ $ "
#{text}
" button_box = $ $ '
' flip_button = new_button "flip over" mark_button = new_button "mark" @@ -45,7 +53,7 @@ instantiate_card = (card) -> $table.append view view.draggable stack: '.card' view.bind 'dragstop', (event, ui) -> - p = view.position() + p = transform_coords view.position() state.move state.agent, card.number, p.left, p.top card.view = view @@ -115,7 +123,8 @@ init = -> if agent is me tell_server ['move', agent, card, x, y] else - state.cards[card].view.animate { left: "#{x}px", top: "#{y}px"}, 800 + coords = transform_coords {left: x, top: y} + state.cards[card].view.animate { left: "#{coords.left}px", top: "#{coords.top}px"}, 800 state.on 'mark', (agent, card, state) -> @cards[card].view.toggleClass 'marked', state if agent is me @@ -140,4 +149,5 @@ init = -> $ -> $table = $ '#table' + table_height = $table.height() - 148 # FIXME auto-detect card height init() -- 1.7.10.4