Skip to content

Commit

Permalink
working on promotion overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
buzzdecafe committed Sep 26, 2013
1 parent 26c21ab commit 184bfae
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 21 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
build
VERSION


2 changes: 2 additions & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version 0.0.1
Built: Wed Sep 25 2013 21:11:44 GMT-0400 (EDT)
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<script src="lib/chess/chess.min.js"></script>
<script src="lib/chess/chessboardjs/js/chessboard-0.3.0.js"></script>
<script src="lib/angular/angular.min.js"></script>
<script src="lib/bootstrap-custom/ui-bootstrap-custom-tpls-0.6.0.min.js"></script>
<script src="js/app.js"></script>
<script src="js/services.js"></script>
<script src="js/controllers.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


// Declare app level module which depends on filters, and services
angular.module('kinghunt', ['kinghunt.filters', 'kinghunt.services', 'kinghunt.directives', 'kinghunt.controllers']).
angular.module('kinghunt', ['ui.bootstrap', 'kinghunt.filters', 'kinghunt.services', 'kinghunt.directives', 'kinghunt.controllers']).
config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/load', {
templateUrl: 'partials/load.html',
Expand Down
10 changes: 10 additions & 0 deletions app/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ angular.module('kinghunt.controllers', []).
$scope.board = new ChessBoard('board', gameSvc.getBoardConfig($scope));
$scope.setStatus(gameSvc.getStatus($scope.goalMoves));


// handle promotion event
$scope.$on('gameSvc/promote', function(cfg) {
var piece;
// show overlay

// update cfg object with promotion piece
cfg.promotion = piece;
});

// handle boardNav events
$scope.$on('boardNav/prevProblem', function() {
var prev = bookSvc.getPrev($scope.currentId);
Expand Down
5 changes: 0 additions & 5 deletions app/js/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ angular.module('kinghunt.filters', []).
return color;
};
}]).
filter('wholeNumbers', [function() {
return function(remaining) {
return remaining >> 0;
};
}]).
filter('toProblemClass', function() {
return function(isSolved) {
return isSolved ? "glyphicon-check solved" : "glyphicon-unchecked unsolved";
Expand Down
48 changes: 34 additions & 14 deletions app/js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ angular.module('kinghunt.services', []).
return status;
},

isPromotable: function(piece, rank) {
return piece === 'P' && (rank === "1" || rank === "8");
},

getBoardConfig: function(scope) {
return {
position: scope.problem.fen,
Expand All @@ -74,24 +78,40 @@ angular.module('kinghunt.services', []).
return false;
}
},
onDrop: function(source, target) {
// see if the move is legal
var move = game.move({
onDrop: function(source, target, pce) {
var piece = pce.substr(1);
var rank = target.substr(1);
var moveCfg = {
from: source,
to: target,
promotion: 'q' // TODO: handle all promotions
});
to: target
};

function makeMove() {
var move = game.move(moveCfg);

// illegal move
if (move === null) {
return 'snapback';
}

// illegal move
if (move === null) {
return 'snapback';
scope.setStatus(gameObj.getStatus(scope.goalMoves));
scope.$apply();
//if (scope.mode === 'auto') {
// opponentMove();
//}
}

scope.setStatus(gameObj.getStatus(scope.goalMoves));
scope.$apply();
// if (scope.mode === 'auto') {
// opponentMove();
// }
function promotePiece(moveConfig, callback) {
// show the promotion overlay
scope.$broadcast('gameSvc/promote', moveConfig);
return callback();
}

if (gameObj.isPromotable(piece, rank)) {
return promotePiece(moveCfg, makeMove);
} else {
return makeMove();
}
},
onSnapbackEnd: function() {
scope.board.position(game.fen());
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions app/partials/board.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ <h4 id="goal">{{ problem.fen | whoseTurn }} to play and {{ goal | translateStipu
<div class="solveStatus"></div>
</div>
<div id="board" class="board-wrap"></div>
<div id="promote" class="overlay" ng-show="promotion">
<div>
</div>
</div>

0 comments on commit 184bfae

Please sign in to comment.