X-Git-Url: https://git.auder.net/assets/icon_infos.svg?a=blobdiff_plain;f=client%2Fsrc%2Futils%2FprintDiagram.js;h=aee1e96a18b11c2f6f1d1df3b93ec21c03d5984c;hb=204b0bb5dc8b5f2760fcbf60cc23deb4552f4305;hp=d4562bf2a76de6454646fa02bffe6cbdeefb5b22;hpb=241bf8f2a9a2c48d793aeb0b1d20207f6371de70;p=vchess.git diff --git a/client/src/utils/printDiagram.js b/client/src/utils/printDiagram.js index d4562bf2..aee1e96a 100644 --- a/client/src/utils/printDiagram.js +++ b/client/src/utils/printDiagram.js @@ -1,4 +1,5 @@ import { ArrayFun } from "@/utils/array"; +import { store } from "@/store"; // Turn (human) marks into coordinates function getMarkArray(marks) { @@ -64,6 +65,10 @@ function getShadowArray(shadow) { // args: object with position (mandatory), and // orientation, marks, shadow (optional) +// TODO: in time, find a strategy to draw middle lines (weiqi, xianqi...) +// and maybe also some diagonals (fanorona...) +// https://stackoverflow.com/questions/40697231/horizontal-line-in-the-middle-of-divs +// + CSS rotate? export function getDiagram(args) { // Obtain the array of pieces images names: const board = V.GetBoard(args.position); @@ -75,28 +80,46 @@ export function getDiagram(args) { 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 < V.size.x; i += inc) { - boardDiv += "
"; + boardDiv += "
"; for (let j = startY; j >= 0 && j < V.size.y; j += inc) { - boardDiv += - "
"; + boardDiv += "
"; if (board[i][j] != V.EMPTY) { boardDiv += ""; } if (markArray.length > 0 && markArray[i][j]) - boardDiv += ""; + boardDiv += ""; boardDiv += "
"; } boardDiv += "
"; } return boardDiv; } + +// Method to replace diagrams in loaded HTML +export function replaceByDiag(match, p1, p2) { + const diagParts = p2.split(" "); + return getDiagram({ + position: diagParts[0], + marks: diagParts[1], + orientation: diagParts[2], + shadow: diagParts[3] + }); +}