preview.js
// generate box content representing the board at (l, t)
generate box content representing the board at (l, t)
generate box content representing the board at ( l t )
board_content(l, t, board) {
    let [from_x, from_y, to_x, to_y] = [-1,-1,-1,-1];
    let highlight_color = MOVE_BG;
    if (t === 0 && Board.game.initial_board_indices.findIndex(x => x === l) !== -1) {
    } else {
      let tl = Board.game.get_timeline(l);
      if (tl) {
        let move = tl.moves[t - tl.begins_at - (tl.synthetic ? 0 : 1)];
        if (move) {
          if (move.from && move.kind === MOVE_KIND.MOVE || move.kind === MOVE_KIND.JUMP_OUT) {
            [from_x, from_y] = [move.from[2], move.from[3]];
          }
          if (move.to && move.kind === MOVE_KIND.MOVE || move.kind === MOVE_KIND.JUMP_IN) {
            [to_x, to_y] = [move.to[2], move.to[3]];
          }
          if ((move.kind === MOVE_KIND.JUMP_OUT) || (move.kind === MOVE_KIND.JUMP_IN)) {
            highlight_color = JUMP_BG;
          }
        }
      }
    }
    let content = "";
    for (let y = Board.game.height - 1; y >= 0; y--) {
      for (let x = 0; x < Board.game.width; x++) {
        content += ((x + y) % 2) ? WHITE_BG : BLACK_BG;
        if ((x === from_x && y === from_y) || (x === to_x && y === to_y)) content += highlight_color;
        content += Board.piece_set[board[x + y * Board.game.width]] + "{/}";
      }
    }
    return content;
  }
board_content ( l , t , board ) { let [ from_x , from_y , to_x , to_y ] = [ - 1 , - 1 , - 1 , - 1 ] ; let highlight_color = MOVE_BG ; if ( t === 0 && Board . game . initial_board_indices . findIndex ( x => x === l ) !== - 1 ) { } else { let tl = Board . game . get_timeline ( l ) ; if ( tl ) { let move = tl . moves [ t - tl . begins_at - ( tl . synthetic ? 0 : 1 ) ] ; if ( move ) { if ( move . from && move . kind === MOVE_KIND . MOVE || move . kind === MOVE_KIND . JUMP_OUT ) { [ from_x , from_y ] = [ move . from [ 2 ] , move . from [ 3 ] ] ; } if ( move . to && move . kind === MOVE_KIND . MOVE || move . kind === MOVE_KIND . JUMP_IN ) { [ to_x , to_y ] = [ move . to [ 2 ] , move . to [ 3 ] ] ; } if ( ( move . kind === MOVE_KIND . JUMP_OUT ) || ( move . kind === MOVE_KIND . JUMP_IN ) ) { highlight_color = JUMP_BG ; } } } } let content = "" ; for ( let y = Board . game . height - 1 ; y >= 0 ; y -- ) { for ( let x = 0 ; x < Board . game . width ; x ++ ) { content += ( ( x + y ) % 2 ) ? WHITE_BG : BLACK_BG ; if ( ( x === from_x && y === from_y ) || ( x === to_x && y === to_y ) ) content += highlight_color ; content += Board . piece_set [ board [ x + y * Board . game . width ] ] + "{/}" ; } } return content ; }
generate box content representing the board at (l, t)
generate box content representing the board at ( l t )