X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=public%2Fjavascripts%2Futils%2FprintDiagram.js;h=4727430382c9a9cdbb7bffc7f2962dccb6a722e2;hp=b7282fee8dce0dafd3f0b325b2103111c9021c1c;hb=69f3d8014e594ef949792d04d97b8286e9c2c268;hpb=1b61a94dbd13f6a37a89e62216615d2496c760a2 diff --git a/public/javascripts/utils/printDiagram.js b/public/javascripts/utils/printDiagram.js index b7282fee..47274303 100644 --- a/public/javascripts/utils/printDiagram.js +++ b/public/javascripts/utils/printDiagram.js @@ -42,6 +42,32 @@ function getDiagram(args) shadowArray[i][colnum] = true; continue; } + if (squares[i].indexOf("-") >= 0) + { + // Shadow a range of squares, horizontally or vertically + const firstLastSq = squares[i].split("-"); + const range = + [ + V.SquareToCoords(firstLastSq[0]), + V.SquareToCoords(firstLastSq[1]) + ]; + const step = + [ + range[1].x == range[0].x + ? 0 + : (range[1].x - range[0].x) / Math.abs(range[1].x - range[0].x), + range[1].y == range[0].y + ? 0 + : (range[1].y - range[0].y) / Math.abs(range[1].y - range[0].y) + ]; + // Convention: range always from smaller to larger number + for (let x=range[0].x, y=range[0].y; x <= range[1].x && y <= range[1].y; + x += step[0], y += step[1]) + { + shadowArray[x][y] = true; + } + continue; + } // Shadow just one square: const coords = V.SquareToCoords(squares[i]); shadowArray[coords.x][coords.y] = true;