X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=client.coffee;h=73fffa1631cc0fd2a42cf0f1ef880ceedef098e1;hb=17ee6e1dba95f184fa1cdf66b4db3153b350e757;hp=0c54a71fb4064273e50fd223f92a2ef21124b5ec;hpb=f12edd687531576f662976ccb4d24a9f5cd42fd9;p=peach-cgt.git diff --git a/client.coffee b/client.coffee index 0c54a71..73fffa1 100644 --- a/client.coffee +++ b/client.coffee @@ -1,3 +1,9 @@ +### +Peach CGT -- Card Game Table simulator +Copyright (C) 2011 Jason Woofenden +Lincensed under AGPLv3. Source here: https://gitorious.org/peach-cgt +### + # globals $table = null table_width = 0 @@ -111,7 +117,7 @@ instantiate_card = (card) -> if card.flipped view.addClass 'flipped' $table.append view - view.draggable containment: '#table', grid: [20, 20] + view.draggable grid: [20, 20] view.bind 'dragstart', (event, ui) -> view.css 'z-index': card.z = next_card_z() if card.pile? @@ -144,11 +150,12 @@ send_updates = -> messages = outgoing_messages outgoing_messages = [] + show_message "#{server_url}/set" $.ajax "#{server_url}/set", { cache: false data: { agent: state.agent - game: 'test' # FIXME, and in the /get call too + game: state.slug messages: JSON.stringify(messages) } type: 'POST' @@ -166,7 +173,7 @@ send_updates = -> error_lag = 3 poll_for_updates = -> - $.ajax "#{server_url}/get?agent=#{state.agent}&game=test", { + $.ajax "#{server_url}/get?agent=#{state.agent}&game=#{state.slug}", { cache: false type: 'GET' dataType: 'json' @@ -298,7 +305,7 @@ init_card_designer = -> container.append ul - submit = $ $ "
#{server_url}##{game}_#{other_player}
"
- state = window.game_model.new me
+ state = window.game_model.new game, me
state.on 'move', (agent, card, x, y, z, pile) ->
if z > top_card_z
top_card_z = z
@@ -368,10 +404,13 @@ init = ->
state.on 'new_cards', (agent, cards) ->
initialize_cards()
- # timeout so browser will stop showing that we're loading
- timeout 1, init_card_designer
- timeout 1, poll_for_updates
- timeout 2, ->
+ # timeouts are so browser will stop showing that we're loading
+ if is_new_game
+ timeout 1, ->
+ tell_server ['new_game', state.slug, state.agent]
+ timeout 2, init_card_designer
+ timeout 3, poll_for_updates
+ timeout 4, ->
# ask for initial state
tell_server ['send_state', state.agent]