Skip to content

Commit

Permalink
Cleaned up some object reference errors in the move processing logic;…
Browse files Browse the repository at this point in the history
… closes issue #10
  • Loading branch information
beartums committed Jun 5, 2014
1 parent dbd102e commit 344ce23
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
1 change: 0 additions & 1 deletion assets/CASEFONT.WOFF

This file was deleted.

3 changes: 1 addition & 2 deletions css/chesslogger.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
@CHARSET "ISO-8859-1";
@font-face {
font-family: "Chess";
src: url('assets/CASEFONT.WOFF') format("woff"),
url('assets/CASEFONT.TTF'') format("truetype");
src: url('./assets/CASEFONT.TTF'') format("truetype");
}
.chess-font {
font-family: "Chess";
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<div class="alert alert-dismissable cssFade"
ng-class="{'alert-success':message.isSuccess,'alert-danger':!message.isSuccess}"
ng-hide="!message.text">
<button type="button" class="close cssFade" data-dismiss="alert" aria-hidden="true">&times;</button>
{{message.text}}
</div>
<div class="text-right"><small><em>check out the developer documentation <a href="./docs">here</a>.</em></small></div>
Expand Down
30 changes: 23 additions & 7 deletions js/chessWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,30 +111,43 @@
if (!this.isValidMove(source,target,game)) return "snapback";

// must do this pass before setting a new line so that we can get the SAN
//console.log(this.game.fen(),game.fen());
if (this.isPromotion(target,piece)) { // if promoting a pawn, select the piece
//var thisObj = this;
this.promotionSelector().then(function(selectedPiece) {
//
this.promotionSelector().then(bind(this,function(selectedPiece) {
moveObj.promotion = selectedPiece;
var move = game.move(moveObj);
});
this.processDrop(game, moveObj);
}));
} else {
var move = game.move(moveObj);
this.processDrop(game, moveObj);
}
}

/**
* In order to do the same things after a promotion modal (returning a promise) and after an
* ordinary move, we have to break the post-modal processing into a separate routine that can be
* bound to this instance of ChessWrapper
* @param {object} game The game in which the move is made
* @param {object} moveObj The move information to be used to make the move
*/

ChessWrapper.prototype.processDrop = function(game, moveObj) {
// don't start a new line if the move has already been made
//var x = this.game.fen()
if (!this.atEndOfMoveList()) {
var tempos = []
// collect the already-made next-moves
if (this.line.tempos.length>this.line.tempos.indexOf(this.selectedTempo)+1) {
tempos.push(this.line.tempos[this.line.tempos.indexOf(this.selectedTempo)+1]);
}
if (this.selectedTempo.lines.length>0) { // already other lines?
if (this.selectedTempo.lines && this.seltectedTempo.lines.length>0) { // already other lines?
for (var i = 0; i < this.selectedTempo.lines.length; i++) {
tempos.push(this.selectedTempo.lines[i].tempos[0]);
}
}
// test all the next-moves to see if they are the same. if so set the position and exit
var g = new Chess(game.fen());
var move = g.move(moveObj);
for (var i = 0; i < tempos.length; i++) {
if (tempos[i].san==move.san) {
this.setPosition(tempos[i]);
Expand All @@ -145,7 +158,10 @@
this.setNewLine();
}
// now make the actual move
move = this.game.move(moveObj);
//var x = this.game.fen()
move = game.move(moveObj);
if (!move) return 'snapback';
this.game=game;
this.addMove(move);

}
Expand Down

0 comments on commit 344ce23

Please sign in to comment.