2 import { store } from "@/store";
3 import { ArrayFun } from "@/utils/array";
6 props: ["fen","vname"],
11 // args: object with position (mandatory), and
12 // orientation, marks, shadow (optional)
13 args: this.parseFen(this.fen),
20 // Obtain the array of pieces images names:
21 const board = V.GetBoard(this.args.position);
22 const orientation = this.args.orientation || "w";
23 const markArray = this.getMarkArray(this.args.marks);
24 const shadowArray = this.getShadowArray(this.args.shadow);
25 // const [startX,startY,inc] = orientation == 'w'
27 // : [V.size.x-1, V.size.y-1, -1];
35 [...Array(V.size.x).keys()].map(i => {
36 let ci = (orientation=='w' ? i : sizeX-i-1);
44 [...Array(V.size.y).keys()].map(j => {
45 let cj = (orientation=='w' ? j : sizeY-j-1);
47 if (board[ci][cj] != V.EMPTY)
57 src: require("@/assets/images/pieces/" +
58 V.getPpath(board[ci][cj]) + ".svg"),
64 if (markArray.length > 0 && markArray[ci][cj])
74 src: "/images/mark.svg",
85 ['board'+V.size.y]: true,
86 'light-square': (i+j)%2==0,
87 'dark-square': (i+j)%2==1,
88 [this.st.bcolor]: true,
89 'in-shadow': shadowArray.length > 0 && shadowArray[ci][cj],
101 parseFen: function(fen) {
102 const fenParts = fen.split(" ");
104 position: fenParts[0],
106 orientation: fenParts[2],
110 // Turn (human) marks into coordinates
111 getMarkArray: function(marks) {
112 if (!marks || marks == "-")
114 let markArray = ArrayFun.init(V.size.x, V.size.y, false);
115 const squares = marks.split(",");
116 for (let i=0; i<squares.length; i++)
118 const coords = V.SquareToCoords(squares[i]);
119 markArray[coords.x][coords.y] = true;
123 // Turn (human) shadow indications into coordinates
124 getShadowArray: function(shadow) {
125 if (!shadow || shadow == "-")
127 let shadowArray = ArrayFun.init(V.size.x, V.size.y, false);
128 const squares = shadow.split(",");
129 for (let i=0; i<squares.length; i++)
131 const rownum = V.size.x - parseInt(squares[i]);
135 for (let i=0; i<V.size.y; i++)
136 shadowArray[rownum][i] = true;
139 if (squares[i].length == 1)
141 // Shadow a full column
142 const colnum = V.ColumnToCoord(squares[i]);
143 for (let i=0; i<V.size.x; i++)
144 shadowArray[i][colnum] = true;
147 if (squares[i].indexOf("-") >= 0)
149 // Shadow a range of squares, horizontally or vertically
150 const firstLastSq = squares[i].split("-");
153 V.SquareToCoords(firstLastSq[0]),
154 V.SquareToCoords(firstLastSq[1])
158 range[1].x == range[0].x
160 : (range[1].x - range[0].x) / Math.abs(range[1].x - range[0].x),
161 range[1].y == range[0].y
163 : (range[1].y - range[0].y) / Math.abs(range[1].y - range[0].y)
165 // Convention: range always from smaller to larger number
166 for (let x=range[0].x, y=range[0].y; x <= range[1].x && y <= range[1].y;
167 x += step[0], y += step[1])
169 shadowArray[x][y] = true;
173 // Shadow just one square:
174 const coords = V.SquareToCoords(squares[i]);
175 shadowArray[coords.x][coords.y] = true;