X-Git-Url: https://jasonwoof.com/gitweb/?p=peach-cgt.git;a=blobdiff_plain;f=server.coffee;h=29b3e50c2a9ab9675f493e9ed8ca2d8cd80c0036;hp=498e391e689596e870c8cf70572147525242ec08;hb=f12edd687531576f662976ccb4d24a9f5cd42fd9;hpb=d2732fceca505157f58de882f35a4b419690ddd1 diff --git a/server.coffee b/server.coffee index 498e391..29b3e50 100644 --- a/server.coffee +++ b/server.coffee @@ -176,6 +176,10 @@ new_game = (id) -> forward_events.call this, 'mark', agent, card, state game.on 'flip', (agent, card, state) -> forward_events.call this, 'flip', agent, card, state + game.on 'new_cards', (agent, cards) -> + # server assigns card numbers, and tells both clients + # (unlike all other api calls, sending agent expects to get this one back) + forward_events.call this, 'new_cards', 'server', cards game.on 'set_cards', (agent, cards) -> forward_events.call this, 'set_cards', agent, cards game.on 'send_state', (agent) -> @@ -191,23 +195,6 @@ new_game = (id) -> test_init = -> test_game = new_game 'test' - timeout 2, -> - test_game.set_cards 'server', [ - { text: "Wildabeast 2/2", x: 220, y: 200, owner: 'p2'} - { text: "Boar 2/2", x: 360, y: 200, owner: 'p2', pile: 'p2_discard'} - { text: "Angora bunny 1/1", x: 500, y: 200, owner: 'p2'} - { text: "Ambulatory Cactus 2/1", x: 660, y: 200, owner: 'p2'} - { text: "Ent 0/5", x: 800, y: 200, owner: 'p2'} - { text: "Carnivore 2/1", x: 220, y: 420, owner: 'p1'} - { text: "Herbivore 1/2", x: 360, y: 420, owner: 'p1'} - { text: "Stone Wall 0/10", x: 500, y: 420, owner: 'p1', pile: 'p1_draw', flipped: true} - { text: "Log 0/1", x: 660, y: 420, owner: 'p1', pile: 'p1_draw', flipped: true} - { text: "Ent 0/5", x: 800, y: 420, owner: 'p1', pile: 'p1_draw', flipped: true} - { text: "Barricade 0/10", x: 500, y: 420, owner: 'p1', pile: 'p1_draw', flipped: true} - { text: "O(log(n)) 0/1", x: 660, y: 420, owner: 'p1', pile: 'p1_draw', flipped: true} - { text: "Fence 0/5", x: 800, y: 420, owner: 'p1', pile: 'p1_draw', flipped: true} - ] - test_init() @@ -236,6 +223,7 @@ http_server = http.createServer (req, res) -> for key, parg of post_args query[key] = parg return set_handler query, res, req, url_parts + return else if rel_path.substr(rel_path.length - 4) is '/get' return get_handler url_parts.query, res, req, url_parts else if rel_path.substr(rel_path.length - 4) is '.ico'