X-Git-Url: https://jasonwoof.com/gitweb/?p=peach-cgt.git;a=blobdiff_plain;f=common.coffee;h=d827e4ec4e618305728400eccadd9dc4f6370836;hp=d2667ace0dda127e9ad8169d83abcf3deff43fbe;hb=HEAD;hpb=078a999a7b7ed2ae37e27d88b3039221fbc1d90c diff --git a/common.coffee b/common.coffee index d2667ac..d827e4e 100644 --- a/common.coffee +++ b/common.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 +### + # this file is used by the client and server. # work around lack of module system in the browser: @@ -8,7 +14,8 @@ else my_exports = window.game_model class GameState - constructor: (agent) -> + constructor: (slug, agent) -> + @slug = slug @agent = agent @hooks = {} @cards = [] @@ -56,6 +63,13 @@ class GameState @cards.push card @trigger 'set_cards', agent, @cards + new_cards: (agent, cards) -> + for card in cards + card.number = @cards.length unless card.number + card.z = @cards.length unless card.z + @cards.push card + @trigger 'new_cards', agent, cards + send_state: (agent) -> @trigger 'send_state', agent @@ -65,7 +79,9 @@ class GameState return typeof messages for message in messages - unless message instanceof Array and message[0]? and message[0] in ['move', 'mark', 'flip', 'set_cards', 'send_state'] + unless message instanceof Array and message[0]? and message[0] in ['move', 'mark', 'flip', 'set_cards', 'send_state', 'new_cards'] + if console?.log? + console.log "Got unrecognized message: #{JSON.stringify message}" # FIXME what to do on error? return 2 method = message.shift() @@ -73,4 +89,4 @@ class GameState return -my_exports.new = (agent) -> new GameState agent +my_exports.new = (slug, agent) -> new GameState slug, agent