- const newRatio = r.width / r.height;
- const aspectRatio = this.size.y / this.size.x;
- let newWidth = r.width,
- newHeight = r.height;
- if (newRatio > aspectRatio) {
- newWidth = r.height * aspectRatio;
- chessboard.style.width = newWidth + "px";
- }
- else if (newRatio < aspectRatio) {
- newHeight = r.width / aspectRatio;
- chessboard.style.height = newHeight + "px";
+ const pieceWidth = this.getPieceWidth(r.width);
+ for (let x=0; x<this.size.x; x++) {
+ for (let y=0; y<this.size.y; y++) {
+ if (!this.enlightened[x][y] && this.oldEnlightened[x][y]) {
+ let elt = document.getElementById(this.coordsToId({x: x, y: y}));
+ elt.classList.add("in-shadow");
+ if (this.g_pieces[x][y])
+ this.g_pieces[x][y].classList.add("hidden");
+ }
+ else if (this.enlightened[x][y] && !this.oldEnlightened[x][y]) {
+ let elt = document.getElementById(this.coordsToId({x: x, y: y}));
+ elt.classList.remove("in-shadow");
+ if (this.g_pieces[x][y])
+ this.g_pieces[x][y].classList.remove("hidden");
+ }
+ }
+ }
+ }
+
+ // Resize board: no need to destroy/recreate pieces
+ rescale(mode) {
+ let chessboard =
+ document.getElementById(this.containerId).querySelector(".chessboard");
+ const r = chessboard.getBoundingClientRect();
+ const multFact = (mode == "up" ? 1.05 : 0.95);
+ let [newWidth, newHeight] = [multFact * r.width, multFact * r.height];
+ // Stay in window:
+ if (newWidth > window.innerWidth) {
+ newWidth = window.innerWidth;
+ newHeight = newWidth / this.size.ratio;