First version of complete Chakart rules (unfinished). Draft diagramer (missing marks...
[xogo.git] / utils / drawDiagrams.js
1 function fenToDiag(vname) {
2 import(`/variants/${vname}/class.js`).then(module => {
3 window.V = module.default;
4 for (const [k, v] of Object.entries(V.Aliases))
5 window[k] = v;
6 drawDiagrams();
7 });
8 }
9
10 // TODO: heuristic to improve for ratio != 1 (how?)
11 function getDiagSize() {
12 if (window.innerWidth > 1000)
13 return 500;
14 if (window.innerWidth < 800)
15 return window.innerWidth;
16 return window.innerWidth / 2;
17 }
18
19 function drawDiagrams() {
20 const diagrams = document.getElementsByClassName("diag");
21 for (let i=0; i<diagrams.length; i++) {
22 let chessboard = document.createElement("div");
23 chessboard.classList.add("chessboard");
24 diagrams[i].appendChild(chessboard);
25 const diagSize = getDiagSize();
26 diagrams[i].style.width = diagSize + "px";
27 diagrams[i].style.height = diagSize + "px";
28 diagrams[i].id = "diag_" + i;
29 const vr = new V({
30 element: "diag_" + i,
31 fen: diagrams[i].dataset.fen,
32 color: diagrams[i].dataset.col || 'w',
33 options: {},
34 diagram: true
35 });
36 }
37 }