- const newR = { x: newX, y: newY, width: newWidth, height: newHeight };
- const pieceWidth = this.getPieceWidth(newWidth);
- for (let i=0; i < this.size.x; i++) {
- for (let j=0; j < this.size.y; j++) {
- if (this.g_pieces[i][j]) {
- // NOTE: could also use CSS transform "scale"
- this.g_pieces[i][j].style.width = pieceWidth + "px";
- this.g_pieces[i][j].style.height = pieceWidth + "px";
- const [ip, jp] = this.getPixelPosition(i, j, newR);
- this.g_pieces[i][j].style.transform = `translate(${ip}px,${jp}px)`;
+ const newR = {x: newX, y: newY, width: newWidth, height: newHeight};
+ const pieceWidth = self.getPieceWidth(newWidth);
+ // NOTE: next "if" for variants which use squares filling
+ // instead of "physical", moving pieces
+ if (this.g_pieces) {
+ for (let i=0; i < self.size.x; i++) {
+ for (let j=0; j < self.size.y; j++) {
+ if (self.g_pieces[i][j]) {
+ // NOTE: could also use CSS transform "scale"
+ self.g_pieces[i][j].style.width = pieceWidth + "px";
+ self.g_pieces[i][j].style.height = pieceWidth + "px";
+ const [ip, jp] = self.getPixelPosition(i, j, newR);
+ // Translate coordinates to use chessboard as reference:
+ self.g_pieces[i][j].style.transform =
+ `translate(${ip - newX}px,${jp - newY}px)`;
+ }