From f47758f678c7343382e835b8cd8e2c420500936d Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 20 Jun 2015 23:14:58 +0200 Subject: [PATCH] Factor out halfmove -> move formatting into a separate JS function. --- www/js/remoteglot.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/www/js/remoteglot.js b/www/js/remoteglot.js index 43b2e1d..8df6085 100644 --- a/www/js/remoteglot.js +++ b/www/js/remoteglot.js @@ -692,10 +692,9 @@ var update_board = function(current_data, display_data) { if (display_data) { // Displaying some non-current position, pick out the last move // from the history. This will work even if the fetch failed. - last_move = format_move_with_number( + last_move = format_halfmove_with_number( current_display_line.pretty_pv[current_display_move], - Math.floor((current_display_move + 1) / 2) + 1, - (current_display_move % 2 == 1)); + current_display_move + 1); headline += ' after ' + last_move; } else if (data['position']['last_move'] !== 'none') { last_move = format_move_with_number( @@ -1011,6 +1010,17 @@ var format_move_with_number = function(move, move_num, white_to_play) { return ret; } +/** + * @param {string} move + * @param {Number} halfmove_num + */ +var format_halfmove_with_number = function(move, halfmove_num) { + return format_move_with_number( + move, + Math.floor(halfmove_num / 2) + 1, + halfmove_num % 2 == 0); +} + /** * @param {boolean} sort_by_score */ -- 2.39.2