]> git.sesse.net Git - remoteglot-book/blobdiff - www/js/book.js
Show move number.
[remoteglot-book] / www / js / book.js
index c54fb94e700d9a8e1338f8c9db38ebada169f20e..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;
 }
@@ -177,6 +177,10 @@ var show_lines = function(data, game) {
                var line = lines[i];
                var tr = document.createElement("tr");
 
+               if (line[0] === undefined || line[0] === null) {
+                       $(tr).addClass("totals");
+               }
+
                for (var j = 0; j < line.length; ++j) {
                        if (line[j] === null) {
                                add_td(tr, "");
@@ -184,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);
@@ -202,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;
@@ -218,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();
        }
@@ -247,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