Skip to content

Commit

Permalink
All the tests appear to be in working order again
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreSteenveld committed Jun 12, 2014
1 parent 0e048a1 commit 4ec181a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
25 changes: 15 additions & 10 deletions script/Game.js
Expand Up @@ -121,7 +121,7 @@ module.exports = Compose(
? ( this.color = "white" )
: ( this.color = "black" );

this.onStart({ color: this.color });
return this.onStart({ color: this.color });

} else {

Expand All @@ -145,23 +145,28 @@ module.exports = Compose(
// Handlers for the place and occupy methods from the board
//

dispatch: function( single ){
dispatch: function( everyone ){

if( !single ){
var result = null,
_arguments_ = Array.prototype.slice.call( arguments, 1 );

if( !everyone ){

var target = this[ arguments[ 2 ].color || arguments[ 2 ].loser ];

return target.emit.apply( target, Array.prototype.slice.call( arguments, 1 ) );
result = target.emit.apply( target, _arguments_ );

} else {

return RSVP.all([
this.white.emit.apply( this.white, Array.prototype.slice.call( arguments, 1 ) ),
this.black.emit.apply( this.black, Array.prototype.slice.call( arguments, 1 ) )
result = RSVP.all([
this.white.emit.apply( this.white, _arguments_ ),
this.black.emit.apply( this.black, _arguments_ )
]);

}

return result.then( this.emit.apply( this, _arguments_ ) );

},

//
Expand All @@ -175,7 +180,7 @@ module.exports = Compose(

var color = this.turn( ),
turn = color === "white" ? "black" : "white",
data = lib.mixin( { }, _moved_ );
data = Object.create( _moved_ );

var dispatched = this.dispatch( true, "onMoved", _moved_ );

Expand Down Expand Up @@ -286,11 +291,11 @@ module.exports = Compose(
},

onPlayerJoin: function( _joiningPlayer_ ){ /* When a player joins the game */
return this.emit( "onPlayerJoin", _joiningPlayer_ );
return this.dispatch( false, "onPlayerJoin", _joiningPlayer_ );
},

onPlayerLeave: function( _leavingPlayer_ ){ /* When a player leaves and the the game wasn't started */
return this.emit( "onPlayerLeave", _leavingPlayer_ );
return this.dispatch( false, "onPlayerLeave", _leavingPlayer_ );
},

//
Expand Down
34 changes: 11 additions & 23 deletions test/game.js
Expand Up @@ -85,7 +85,7 @@ module.exports = {

});

game.start( );
game.start( ).catch( result.reject );

return result.promise;
},
Expand All @@ -112,7 +112,7 @@ module.exports = {

});

game.start( );
game.start( ).catch( result.reject );

return result.promise;
},
Expand Down Expand Up @@ -151,7 +151,7 @@ module.exports = {
wPlayer.join( game, "white" );
bPlayer.join( game, "black" );

game.start( );
game.start( ).catch( result.reject );

return result.promise;

Expand Down Expand Up @@ -189,7 +189,7 @@ module.exports = {
wPlayer.join( game, "white" );
bPlayer.join( game, "black" );

game.start( );
game.start( ).catch( result.reject );

return result.promise;
},
Expand All @@ -207,7 +207,7 @@ module.exports = {
RSVP.defer( "white | D1 - D3" )
];

var result = new RSVP.all( moves );
var result = RSVP.all( moves );

wPlayer.on( "onTurn", function( _turn_ ){

Expand Down Expand Up @@ -281,9 +281,7 @@ module.exports = {
wPlayer.join( game, "white" );
bPlayer.join( game, "black" );

game.start( );

return result.promise;
return RSVP.all([ game.start( ), result.promise ]);
},

"check event": function( test ){
Expand Down Expand Up @@ -336,9 +334,7 @@ module.exports = {
wPlayer.join( game, "white" );
bPlayer.join( game, "black" );

game.start( );

return result.promise;
return RSVP.all([ game.start( ), result.promise ]);
},

"mate event": function( test ){
Expand Down Expand Up @@ -402,9 +398,7 @@ module.exports = {
wPlayer.join( game, "white" );
bPlayer.join( game, "black" );

game.start( );

return result.promise;
return RSVP.all([ game.start( ), result.promise ]);

},

Expand Down Expand Up @@ -444,9 +438,7 @@ module.exports = {
wPlayer.join( game, "white" );
bPlayer.join( game, "black" );

game.start( );

return result.promise;
return RSVP.all([ game.start( ), result.promise ]);
},

"stale event": function( test ){
Expand Down Expand Up @@ -503,9 +495,7 @@ module.exports = {
wPlayer.join( game, "white" );
bPlayer.join( game, "black" );

game.start( );

return result.promise;
return RSVP.all([ game.start( ), result.promise ]);

},

Expand Down Expand Up @@ -548,9 +538,7 @@ module.exports = {
wPlayer.join( game, "white" );
bPlayer.join( game, "black" );

game.start( );

return result.promise;
return RSVP.all([ game.start( ), result.promise ]);

}

Expand Down
File renamed without changes.

0 comments on commit 4ec181a

Please sign in to comment.