X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Fjs%2Fbook.js;h=6017fd9d0d5eb6a91a1238089c080a7af460c819;hb=1067590eb03c8571f6e4aafc215b71bcb7a71001;hp=78dfed815cf8c3c782266ab5e47cf377383a58a0;hpb=5f6d20ea4cdcddbd10fd8d2c3f2bef89f1e14f42;p=remoteglot-book diff --git a/www/js/book.js b/www/js/book.js index 78dfed8..6017fd9 100644 --- a/www/js/book.js +++ b/www/js/book.js @@ -3,6 +3,7 @@ var board = null; var history = []; var move_override = 0; +var includetransp = true; var entity_map = { "&": "&", @@ -18,9 +19,14 @@ function escape_html(string) { }); } -var get_game = function() { +var get_game = function(skip_last_move) { + var moves_to_drop = 0; + if (skip_last_move === true) { + moves_to_drop = 1; + } + var game = new Chess(); - for (var i = 0; i < move_override; ++i) { + for (var i = 0; i < move_override - moves_to_drop; ++i) { game.move(history[i]); } return game; @@ -59,8 +65,15 @@ var update = function() { var fetch_analysis = function() { var game = get_game(); + var fen = game.fen(); + var prevfen = ""; + if (move_override > 0) { + prevfen = get_game(true).fen(); + } $.ajax({ - url: "/opening-stats.pl?fen=" + encodeURIComponent(game.fen()) + url: "/opening-stats.pl?fen=" + encodeURIComponent(fen) + + ";prevfen=" + encodeURIComponent(prevfen) + + ";includetransp=" + (includetransp ? 1 : 0) }).done(function(data, textstatus, xhr) { show_lines(data, game); }); @@ -240,6 +253,12 @@ var show_lines = function(data, game) { } } +var set_includetransp = function(value) { + includetransp = value; + update(); +} +window['set_includetransp'] = set_includetransp; + var make_move = function(move) { if (move_override < history.length && history[move_override] == move) { // User effectively only moved forward in history. @@ -303,7 +322,6 @@ var onDrop = function(source, target) { history.push(new_history[i].san); } move_override = history.length; - update(); }; // update the board position after the piece snap @@ -311,7 +329,7 @@ var onDrop = function(source, target) { var onSnapEnd = function() { var game = get_game(); board.position(game.fen()); - fetch_analysis(); + update(); }; var init = function() {