X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=www%2Fjs%2Fremoteglot.js;h=ff566ab85c81c4ba4b33ff8a9853bec23d8f89ca;hp=d614c7ea1016a44f8b92afa841eb42c09b5a81b0;hb=01a8eaa3db2c015b25c0cf53df96b12493f3db58;hpb=064c1bd8e1689b614d75e005e5379fe4806ba15b;ds=sidebyside diff --git a/www/js/remoteglot.js b/www/js/remoteglot.js index d614c7e..ff566ab 100644 --- a/www/js/remoteglot.js +++ b/www/js/remoteglot.js @@ -864,7 +864,7 @@ var update_refutation_lines = function() { */ var chess_from = function(fen, moves, last_move) { var hiddenboard = new Chess(); - if (fen !== null) { + if (fen !== null && fen !== undefined) { hiddenboard.load(fen); } for (var i = 0; i <= last_move; ++i) { @@ -957,7 +957,8 @@ var update_board = function() { // unconditionally taken from current_data (we're not interested in // historic history). if (current_data['position']['history']) { - add_pv('start', current_data['position']['history'], 1, 'W', null, 0, 8, true); + var start = (current_data['position'] && current_data['position']['start_fen']) ? current_data['position']['start_fen'] : 'start'; + add_pv(start, current_data['position']['history'], 1, 'W', null, 0, 8, true); } else { display_lines.push(null); } @@ -1083,7 +1084,8 @@ var update_board = function() { // We don't have historic analysis for this position, but we // can reconstruct what the last move was by just replaying // from the start. - var hiddenboard = chess_from(null, current_display_line.pv, current_display_move); + var position = (data['position'] && data['position']['start_fen']) ? data['position']['start_fen'] : null; + var hiddenboard = chess_from(position, current_display_line.pv, current_display_move); var moves = hiddenboard.history({ verbose: true }); last_move = moves.pop(); highlight_from = last_move.from; @@ -1607,7 +1609,7 @@ var update_historic_analysis = function() { } // Fetch old analysis for this line if it exists. - var hiddenboard = chess_from(null, current_display_line.pv, current_display_move); + var hiddenboard = chess_from(current_display_line.start_fen, current_display_line.pv, current_display_move); var filename = "/history/move" + (current_display_move + 1) + "-" + hiddenboard.fen().replace(/ /g, '_').replace(/\//g, '-') + ".json";