vimtronner
Version:
A multi-player Vim trainer.
29 lines (23 loc) • 1.06 kB
text/coffeescript
ClientGameSocket = require './client_game_socket'
class ClientSocket
constructor: (, , )->
?= (socket, game, cycle)->
new ClientGameSocket(socket, game, cycle)
.on 'join',
.on 'list',
onJoin: (gameAttributes, callback=(error, cycle)->)=>
game = .getGame(gameAttributes)
if game?
game, gameAttributes
if (cycle = game.addCycle())?
(, game, cycle)
callback null, cycle.number, game.toJSON()
else
callback message: "Game '#{gameAttributes.name}' is already in progress."
else
callback message: "Could not find or create game named '#{gameAttributes.name}'."
onList: => .emit 'games', .gameList()
adjustGameSize: (game, gameAttributes)->
(game.width = gameAttributes.width) if game.width > gameAttributes.width
(game.height = gameAttributes.height) if game.height > gameAttributes.height
module.exports = ClientSocket