X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Futils%2FprintDiagram.js;h=aebdc247628e27031a8f30415f497108e99d780a;hp=bf078cee0c7dc07abb2ec59ef426261c724cd98c;hb=6808d7a16ec1e761c6a2dffec2281c96953e4d89;hpb=ae2c49bb0bbaac3953f63be5b720e9c6835f00b6 diff --git a/client/src/utils/printDiagram.js b/client/src/utils/printDiagram.js index bf078cee..aebdc247 100644 --- a/client/src/utils/printDiagram.js +++ b/client/src/utils/printDiagram.js @@ -1,14 +1,11 @@ import { ArrayFun } from "@/utils/array"; // Turn (human) marks into coordinates -function getMarkArray(marks) -{ - if (!marks || marks == "-") - return []; +function getMarkArray(marks) { + if (!marks || marks == "-") return []; let markArray = ArrayFun.init(V.size.x, V.size.y, false); const squares = marks.split(","); - for (let i=0; i= 0) - { + if (squares[i].indexOf("-") >= 0) { // Shadow a range of squares, horizontally or vertically const firstLastSq = squares[i].split("-"); - const range = - [ + const range = [ V.SquareToCoords(firstLastSq[0]), V.SquareToCoords(firstLastSq[1]) ]; - const step = - [ + const step = [ range[1].x == range[0].x ? 0 : (range[1].x - range[0].x) / Math.abs(range[1].x - range[0].x), @@ -59,9 +46,11 @@ function getShadowArray(shadow) : (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]) - { + 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; @@ -75,30 +64,31 @@ function getShadowArray(shadow) // args: object with position (mandatory), and // orientation, marks, shadow (optional) -export function getDiagram(args) -{ +export function getDiagram(args) { // Obtain the array of pieces images names: const board = V.GetBoard(args.position); const orientation = args.orientation || "w"; const markArray = getMarkArray(args.marks); const shadowArray = getShadowArray(args.shadow); let boardDiv = ""; - const [startX,startY,inc] = orientation == 'w' - ? [0, 0, 1] - : [V.size.x-1, V.size.y-1, -1]; - for (let i=startX; i>=0 && i= 0 && i < V.size.x; i += inc) { boardDiv += "
"; - for (let j=startY; j>=0 && j= 0 && j < V.size.y; j += inc) { + boardDiv += + "
"; - if (board[i][j] != V.EMPTY) - { - boardDiv += ""; } if (markArray.length > 0 && markArray[i][j])