X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=public%2Fjavascripts%2Futils%2FprintDiagram.js;h=4727430382c9a9cdbb7bffc7f2962dccb6a722e2;hp=ef750490ed02ad88c3af54663ac3de12606e78b1;hb=69f3d8014e594ef949792d04d97b8286e9c2c268;hpb=da06a6eb0237123ce43fdb01cb06246b8b57f5e5 diff --git a/public/javascripts/utils/printDiagram.js b/public/javascripts/utils/printDiagram.js index ef750490..47274303 100644 --- a/public/javascripts/utils/printDiagram.js +++ b/public/javascripts/utils/printDiagram.js @@ -7,17 +7,70 @@ function getDiagram(args) const board = VariantRules.GetBoard(args.position); const orientation = args.orientation || "w"; let markArray = []; - if (!!args.marks) + if (!!args.marks && args.marks != "-") { // Turn (human) marks into coordinates markArray = doubleArray(sizeX, sizeY, false); let squares = args.marks.split(","); for (let i=0; i= 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; } } let boardDiv = ""; @@ -30,13 +83,15 @@ function getDiagram(args) for (let j=startY; j>=0 && j"; + ((i+j)%2==0 ? "light-square-diag" : "dark-square-diag") + + (shadowArray.length > 0 && shadowArray[i][j] ? " in-shadow" : "") + + "'>"; if (board[i][j] != V.EMPTY) { boardDiv += ""; } - if (!!args.marks && markArray[i][j]) + if (markArray.length > 0 && markArray[i][j]) boardDiv += ""; boardDiv += ""; }