X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Futils%2FprintDiagram.js;h=ba7b1e9707f23b342be7ab1d3f9bdf011d3a7f0b;hb=b955c65b942d09d24b5c3bed0d755d4f2f8f71f1;hp=b7282fee8dce0dafd3f0b325b2103111c9021c1c;hpb=5915f72002ae63b04620cebe47adf778174b1bee;p=vchess.git diff --git a/public/javascripts/utils/printDiagram.js b/public/javascripts/utils/printDiagram.js index b7282fee..ba7b1e97 100644 --- a/public/javascripts/utils/printDiagram.js +++ b/public/javascripts/utils/printDiagram.js @@ -1,62 +1,95 @@ -// Assuming V(ariantRules) class is loaded. -// args: object with position (mandatory), orientation, marks (optional) -function getDiagram(args) +// Turn (human) marks into coordinates +function getMarkArray(marks) { - const [sizeX,sizeY] = [V.size.x,V.size.y]; - // Obtain array of pieces images names - const board = VariantRules.GetBoard(args.position); - const orientation = args.orientation || "w"; - let markArray = []; - if (!!args.marks && args.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]) { - // Shadow a full column - const colnum = V.ColumnToCoord(squares[i]); - for (let i=0; i=0 && i=0 && i=0 && j=0 && j 0 && shadowArray[i][j] ? " in-shadow" : "") + "'>";