- setupPieces() {
- for (let i=0; i<this.size.x; i++) {
- for (let j=0; j<this.size.y; j++) {
- if (this.board[i][j] != "") {
- const sqColor = (this.getColor(i, j) == 'w' ? "white" : "black");
- const elt = document.getElementById(this.coordsToId({x: i, y: j}));
- elt.classList.remove("neutral-square");
- elt.classList.add("bg-" + sqColor);
- }
- }
- }
- }
-
- initMouseEvents() {
- const mousedown = (e) => {
- if (e.touches && e.touches.length > 1)
- e.preventDefault();
- const cd = this.idToCoords(e.target.id);
- if (cd) {
- const move = this.doClick(cd);
- if (move)
- this.playPlusVisual(move);
- }
- };
-
- if ('onmousedown' in window) {
- document.addEventListener("mousedown", mousedown);
- document.addEventListener("wheel",
- (e) => this.rescale(e.deltaY < 0 ? "up" : "down"));
- }
- if ('ontouchstart' in window)
- document.addEventListener("touchstart", mousedown, {passive: false});
- }
-