X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=client.coffee;h=177f3b450cb67148cc4d3e029e1e69e57a8b9e8c;hb=4eb019697492c1f826548e05f0811cbef887a8ad;hp=63fd6c6d15137fabda6b1ed9316fa49758ec76b3;hpb=7797a9aab5a31f89b84ebc86c5a7bc3d12ef6602;p=peach-cgt.git diff --git a/client.coffee b/client.coffee index 63fd6c6..177f3b4 100644 --- a/client.coffee +++ b/client.coffee @@ -23,27 +23,31 @@ unless Array::shuffle? new_button = (text) -> $ $ "
#{text}
" -instantiate_card = (model) -> - text = model.text - x = model.x - y = model.y - card = $ $ "
#{text}
" +instantiate_card = (card) -> + text = card.text + x = card.x + y = card.y + view = $ $ "
#{text}
" button_box = $ $ '
' flip_button = new_button "flip over" mark_button = new_button "mark" flip_button.bind 'click', -> - state.flip state.agent, model.number, ! card.hasClass 'flipped' + state.flip state.agent, card.number, ! view.hasClass 'flipped' mark_button.bind 'click', -> - state.mark state.agent, model.number, ! card.hasClass 'marked' + state.mark state.agent, card.number, ! view.hasClass 'marked' button_box.append flip_button button_box.append mark_button - card.append button_box - $table.append card - card.draggable stack: '.card' - card.bind 'dragstop', (event, ui) -> - p = card.position() - state.move state.agent, model.number, p.left, p.top - model.view = card + view.append button_box + if card.marked + view.addClass 'marked' + if card.flipped + view.addClass 'flipped' + $table.append view + view.draggable stack: '.card' + view.bind 'dragstop', (event, ui) -> + p = view.position() + state.move state.agent, card.number, p.left, p.top + card.view = view error_lag = 3 @@ -130,6 +134,9 @@ init = -> # timeout so browser will stop showing that we're loading timeout 1, poll_for_updates + timeout 2, -> + # ask for initial state + tell_server ['send_state', state.agent] $ -> $table = $ '#table'