]> git.sesse.net Git - remoteglot/commitdiff
More fixes for relative move numbering after the recent refactoring.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 28 Dec 2023 14:06:54 +0000 (15:06 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 28 Dec 2023 14:06:54 +0000 (15:06 +0100)
www/js/remoteglot.js

index 69f0134b1d86487dad4748a121eb42810ddbf394..ceeff7b3c94de6c10ff6f013d837b414c500227f 100644 (file)
@@ -174,7 +174,9 @@ let display_fen = null;
  *    start_display_move_num: number
  * }}
  *
- * "start_display_move_num" is the (half-)move number to start displaying the PV at.
+ * "start_display_move_num" is the (half-)move number to start displaying the PV at,
+ * i.e., the index into pv.
+ *
  * "score" is also evaluated at this point. scores can be empty and is frequently
  * sparse; it's generally only really useful for history (we obviously don't know
  * much about how the score will * move during e.g. a PV, except that a mate/TB
@@ -199,7 +201,11 @@ let current_display_line = null;
 /** @type {boolean} @private */
 let current_display_line_is_history = false;
 
-/** @type {?number} @private */
+/** @type {?number} @private
+ *
+ * The highlighted/used/shown move in current_display_line.pv, in terms of absolute index
+ * (not relative to e.g. the start FEN).
+ */
 let current_display_move = null;
 
 /**
@@ -746,6 +752,7 @@ function print_pv(line_num, splicepos, opt_limit, opt_showlast) {
        let display_line = display_lines[line_num];
        let pv = display_line.pv;
        let halfmove_num = find_halfmove_num(display_line.start_fen) + 2;  // From two, for simplicity.
+       let start_halfmove_num = halfmove_num;
 
        let ret = document.createDocumentFragment();
 
@@ -806,9 +813,9 @@ function print_pv(line_num, splicepos, opt_limit, opt_showlast) {
 
                let link = document.createElement('a');
                link.className = 'move';
-               link.setAttribute('id', 'automove' + line_num + '-' + i);
+               link.setAttribute('id', 'automove' + line_num + '-' + (halfmove_num - start_halfmove_num));
                link.textContent = pv[i];
-               link.href = 'javascript:show_line(' + line_num + ', ' + i + ');';
+               link.href = 'javascript:show_line(' + line_num + ', ' + (halfmove_num - start_halfmove_num) + ');';
                ret.appendChild(link);
        }
        if (in_tb) {
@@ -1758,7 +1765,7 @@ function show_line(line_num, move_num) {
                return;
        } else {
                current_display_line = {...display_lines[line_num]};  // Shallow clone.
-               current_display_move = move_num + current_display_line.start_display_move_num;
+               current_display_move = move_num;
        }
        current_display_line_is_history = (line_num == 0);
 
@@ -1925,7 +1932,7 @@ function update_move_highlight() {
                        display_lines[1].pv = [];
                }
 
-               highlighted_move = document.getElementById("automove" + display_line_num + "-" + (current_display_move - current_display_line.start_display_move_num));
+               highlighted_move = document.getElementById("automove" + display_line_num + "-" + current_display_move);
                if (highlighted_move !== null) {
                        highlighted_move.classList.add('highlight');
                }
@@ -2289,7 +2296,7 @@ function onSnapEnd(source, target) {
                }
                let line = display_lines[i];
                if (line.pv[line.start_display_move_num] === move.san) {
-                       show_line(i, 0);
+                       show_line(i, line.start_display_move_num);
                        return;
                }
        }