]> git.sesse.net Git - remoteglot-book/blobdiff - www/js/book.js
Show move number.
[remoteglot-book] / www / js / book.js
index 0b1e4372264a7afa77d9cae8dbdf0c5bfbf464e2..a489a6a3ed3c1a1dc0ef199789b870274ee42032 100644 (file)
@@ -1,7 +1,7 @@
 (function() {
 
 var board = null;
-var moves = [];
+var history = [];
 var move_override = 0;
 
 var entity_map = {
@@ -21,7 +21,7 @@ function escape_html(string) {
 var get_game = function() {
        var game = new Chess();
        for (var i = 0; i < move_override; ++i) {
-               game.move(moves[i]);
+               game.move(history[i]);
        }
        return game;
 }
@@ -188,6 +188,14 @@ var show_lines = function(data, game) {
                                var td = document.createElement("td");
                                tr.appendChild(td);
                                $(td).addClass("move");
+                               if (line[j] !== undefined) {
+                                       if (history.length % 2 == 0) {
+                                               $(td).text(((history.length / 2) + 1) + ". ");
+                                       } else {
+                                               $(td).text(((history.length / 2) + 0.5) + ". …");
+                                       }
+                               }
+
                                var move_a = document.createElement("a");
                                move_a.href = "javascript:make_move('" + line[j] + "')";
                                td.appendChild(move_a);
@@ -206,9 +214,9 @@ var show_lines = function(data, game) {
 }
 
 var make_move = function(move) {
-       moves.length = move_override;
-       moves.push(move);
-       move_override = moves.length;
+       history.length = move_override;
+       history.push(move);
+       move_override = history.length;
        update();
 }
 window['make_move'] = make_move;
@@ -222,7 +230,7 @@ var prev_move = function() {
 window['prev_move'] = prev_move;
 
 var next_move = function() {
-       if (move_override < moves.length) {
+       if (move_override < history.length) {
                ++move_override;
                update();
        }
@@ -251,8 +259,8 @@ var onDrop = function(source, target) {
        // illegal move
        if (move === null) return 'snapback';
 
-       moves = game.history({ verbose: true });
-       move_override = moves.length;
+       history = game.history({ verbose: true });
+       move_override = history.length;
 };
 
 // update the board position after the piece snap