X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fclient_OLD%2Fjavascripts%2Futils%2FprintDiagram.js;fp=client%2Fclient_OLD%2Fjavascripts%2Futils%2FprintDiagram.js;h=ba7b1e9707f23b342be7ab1d3f9bdf011d3a7f0b;hb=625022fdcf750f0aff8fcd699f7e9b89730e1d10;hp=0000000000000000000000000000000000000000;hpb=b955c65b942d09d24b5c3bed0d755d4f2f8f71f1;p=vchess.git diff --git a/client/client_OLD/javascripts/utils/printDiagram.js b/client/client_OLD/javascripts/utils/printDiagram.js new file mode 100644 index 00000000..ba7b1e97 --- /dev/null +++ b/client/client_OLD/javascripts/utils/printDiagram.js @@ -0,0 +1,108 @@ +// Turn (human) marks into coordinates +function getMarkArray(marks) +{ + if (!marks || marks == "-") + return []; + let markArray = doubleArray(V.size.x, V.size.y, false); + const squares = 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; + } + return shadowArray; +} + +// args: object with position (mandatory), and +// orientation, marks, shadow (optional) +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 && j 0 && shadowArray[i][j] ? " in-shadow" : "") + + "'>"; + if (board[i][j] != V.EMPTY) + { + boardDiv += ""; + } + if (markArray.length > 0 && markArray[i][j]) + boardDiv += ""; + boardDiv += ""; + } + boardDiv += ""; + } + return boardDiv; +}