X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=common.coffee;h=d2667ace0dda127e9ad8169d83abcf3deff43fbe;hb=8656fbda0ba6b35e8489dc66235e7fc76c07a7af;hp=cc337851c37eadf125451b1fab2e15876f26eff9;hpb=7797a9aab5a31f89b84ebc86c5a7bc3d12ef6602;p=peach-cgt.git diff --git a/common.coffee b/common.coffee index cc33785..d2667ac 100644 --- a/common.coffee +++ b/common.coffee @@ -12,7 +12,6 @@ class GameState @agent = agent @hooks = {} @cards = [] - @piles = {} on: (event, callback) -> unless @hooks[event]? @hooks[event] = [] @@ -21,16 +20,19 @@ class GameState return unless @hooks[event]? for callback in @hooks[event] callback.apply this, args - move: (agent, card, x, y) -> # FIXME add pile argument + move: (agent, card, x, y, z, pile) -> # FIXME what to do on error? - return unless @cards[card]? #?.pile? - #cur_pile = cards[card].pile - #if pile isnt cur_pile + return unless @cards[card]? @cards[card].x = x @cards[card].y = y + @cards[card].z = z + if pile? + @cards[card].pile = pile + else if @cards[card].pile? + delete @cards[card].pile - @trigger 'move', agent, card, x, y # FIXME add pile argument + @trigger 'move', agent, card, x, y, z, pile mark: (agent, card, state) -> # FIXME what to do on error? @@ -48,23 +50,22 @@ class GameState set_cards: (agent, cards) -> @cards = [] - @piles = {} for card in cards - card.number = @cards.length + card.number = @cards.length unless card.number + card.z = @cards.length unless card.z @cards.push card - if card.pile? - unless @piles[card.pile]? - @piles[card.pile] = [] - @piles[card.pile].push card @trigger 'set_cards', agent, @cards + send_state: (agent) -> + @trigger 'send_state', agent + process_messages: (messages) -> unless typeof messages is 'array' or typeof messages is 'object' # FIXME what to do on error? return typeof messages for message in messages - unless message instanceof Array and message[0]? and message[0] in ['move', 'mark', 'flip', 'set_cards'] + unless message instanceof Array and message[0]? and message[0] in ['move', 'mark', 'flip', 'set_cards', 'send_state'] # FIXME what to do on error? return 2 method = message.shift()