/** Currently displayed refutation lines (on-screen).
* Can either come from the current_analysis_data, displayed_analysis_data,
* or hash_refutation_lines.
+ *
+ * TODO: This is a mess, and we should probably just let update_refutation_lines()
+ * decide anew every time instead of storing the state here in multiple global
+ * variables.
*/
let refutation_lines = [];
*/
let hash_refutation_lines = null;
+/**
+ * What FEN refutation_lines is relative to. Will usually be base_fen,
+ * but if another move gets loaded while we are looking, they can diverge.
+ */
+let refutation_lines_base_fen = null;
+
/** @type {number} @private */
let ims = 0;
* Also recreates the global "display_lines".
*/
function update_refutation_lines() {
- if (base_fen === null) {
+ if (refutation_lines_base_fen === null) {
return;
}
if (display_lines.length > 2) {
moves.push(move);
}
- let invert = (find_toplay(base_fen) === 'b');
+ let invert = (find_toplay(refutation_lines_base_fen) === 'b');
if (current_display_line && current_display_move % 2 == 0 && !current_display_line_is_history) {
invert = !invert;
}
let pv_td = document.createElement("td");
tr.appendChild(pv_td);
pv_td.classList.add("pv");
- pv_td.append(add_pv(base_fen, base_line.concat([ line['move'] ]), scores, start_display_move_num));
+ pv_td.append(add_pv(refutation_lines_base_fen, base_line.concat([ line['move'] ]), scores, start_display_move_num));
tbl.append(tr);
continue;
let pv_td = document.createElement("td");
tr.appendChild(pv_td);
pv_td.classList.add("pv");
- pv_td.append(add_pv(base_fen, base_line.concat(line['pv']), scores, start_display_move_num, 10));
+ pv_td.append(add_pv(refutation_lines_base_fen, base_line.concat(line['pv']), scores, start_display_move_num, 10));
tbl.append(tr);
}
document.getElementById("whiteclock").replaceChildren();
document.getElementById("blackclock").replaceChildren();
refutation_lines = [];
+ refutation_lines_base_fen = null;
update_refutation_lines();
clear_arrows();
update_displayed_line();
// Update the refutation lines.
base_fen = data['position']['fen'];
- refutation_lines = hash_refutation_lines || data['refutation_lines'];
+ if (hash_refutation_lines === null) {
+ refutation_lines = data['refutation_lines'];
+ refutation_lines_base_fen = base_fen;
+ }
update_refutation_lines();
// Update the sparkline last, since its size depends on how everything else reflowed.
current_display_line = null;
current_display_move = null;
hash_refutation_lines = null;
+ refutation_lines_base_fen = base_fen;
if (displayed_analysis_data) {
// TODO: Support exiting to history position if we are in an
// analysis line of a history position.
}
current_hash_display_timer = null;
hash_refutation_lines = data['lines'];
+ refutation_lines_base_fen = fen;
update_board();
}