Permalink
Browse files

Clone all the game properties.

  • Loading branch information...
1 parent ce3d57f commit 138044a8132d2c7b5727a15e3470361d6ae779a8 @pokoli committed Apr 20, 2012
Showing with 14 additions and 1 deletion.
  1. +8 −1 src/game.js
  2. +6 −0 test/game.test.js
View
9 src/game.js
@@ -58,7 +58,13 @@ module.exports.clone = function(game,type) {
if(game.players)
_game.players=game.players;
if(game._events)
- _game._events=game._events;
+ _game._events=game._events;
+ if(game.watchers)
+ _game.watchers=game.watchers;
+ if(game.state)
+ _game.state=game.state;
+ if(game.min_players)
+ _game.min_players=game.min_players;
return _game;
};
@@ -110,5 +116,6 @@ Game.prototype.numberOfWatchers = function(){
Game.prototype.start = function(){
if(this.numberOfPlayers() < this.min_players) throw new Error(i18n.__('Not enough players'));
this.state=i18n.__('running');
+ this.emit('updated',this);
}
View
6 test/game.test.js
@@ -57,6 +57,12 @@ module.exports = {
"If we clone a game it should be the same" : function(){
var clonedGame = Game.clone(game);
clonedGame.should.eql(game);
+ var newGame = Game.create('Test game');
+ newGame.state='running';
+ newGame.watchers=[1,2];
+ newGame.players=[2,1];
+ var clonedNewGame = Game.clone(newGame);
+ clonedNewGame.should.eql(newGame);
},
"The game should have a state property, 'waiting'' by default" : function(){
game.should.have.property('state');

0 comments on commit 138044a

Please sign in to comment.