From 5dbc2990d8211d8422b474a69b0ea379e6fe198e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 20 Mar 2016 15:50:49 +0100 Subject: [PATCH] Refactor print_pv a bit. --- www/js/remoteglot.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/www/js/remoteglot.js b/www/js/remoteglot.js index da9f70a..8b16f7c 100644 --- a/www/js/remoteglot.js +++ b/www/js/remoteglot.js @@ -562,30 +562,35 @@ var thousands = function(x) { } /** - * @param {!string} fen + * @param {!string} start_fen * @param {Array.} pretty_pv * @param {number} move_num * @param {!string} toplay * @param {number=} opt_limit * @param {boolean=} opt_showlast */ -var add_pv = function(fen, pretty_pv, move_num, toplay, opt_limit, opt_showlast) { +var add_pv = function(start_fen, pretty_pv, move_num, toplay, start_display_move_num, opt_limit, opt_showlast) { display_lines.push({ - start_fen: fen, + start_fen: start_fen, pretty_pv: pretty_pv, + move_num: parseInt(move_num), + toplay: toplay, + start_display_move_num: start_display_move_num, }); - return print_pv(display_lines.length - 1, pretty_pv, move_num, toplay, opt_limit, opt_showlast); + return print_pv(display_lines.length - 1, opt_limit, opt_showlast); } /** * @param {number} line_num - * @param {Array.} pretty_pv - * @param {number} move_num - * @param {!string} toplay * @param {number=} opt_limit * @param {boolean=} opt_showlast */ -var print_pv = function(line_num, pretty_pv, move_num, toplay, opt_limit, opt_showlast) { +var print_pv = function(line_num, opt_limit, opt_showlast) { + var display_line = display_lines[line_num]; + var pretty_pv = display_line.pretty_pv; + var move_num = display_line.move_num; + var toplay = display_line.toplay; + var pv = ''; var i = 0; if (opt_limit && opt_showlast && pretty_pv.length > opt_limit) { @@ -643,11 +648,11 @@ var update_history = function() { if (display_lines[0] === null || display_lines[0].pretty_pv.length == 0) { $("#history").html("No history"); } else if (truncate_display_history) { - $("#history").html(print_pv(0, display_lines[0].pretty_pv, 1, 'W', 8, true)); + $("#history").html(print_pv(0, 8, true)); } else { $("#history").html( '(collapse) ' + - print_pv(0, display_lines[0].pretty_pv, 1, 'W')); + print_pv(0, 1, 'W')); } } -- 2.39.2