From: Benjamin Auder Date: Thu, 2 Jun 2022 20:13:40 +0000 (+0200) Subject: Some bugs fixes X-Git-Url: https://git.auder.net/js/css/doc/html/current/pieces/cr.svg?a=commitdiff_plain;h=437dfd42748eb2359103fd87a7d0e780121a7865;p=xogo.git Some bugs fixes --- diff --git a/base_rules.js b/base_rules.js index 0d7b703..3fa4e0b 100644 --- a/base_rules.js +++ b/base_rules.js @@ -29,16 +29,18 @@ export default class ChessRules { {label: "Asymmetric random", value: 2} ] }], - check: [ + input: [ { label: "Capture king", - defaut: false, - variable: "taking" + variable: "taking", + type: "checkbox", + defaut: false }, { label: "Falling pawn", - defaut: false, - variable: "pawnfall" + variable: "pawnfall", + type: "checkbox", + defaut: false } ], // Game modifiers (using "elementary variants"). Default: false @@ -943,11 +945,6 @@ export default class ChessRules { }; const mouseup = (e) => { - const newR = chessboard.getBoundingClientRect(); - if (newR.width != r.width || newR.height != r.height) { - this.rescale(); - return; - } if (!start) return; const [x, y] = [start.x, start.y]; @@ -972,15 +969,12 @@ export default class ChessRules { curPiece.remove(); }; - const wheelResize = (e) => { - this.rescale(e.deltaY < 0 ? "up" : "down"); - }; - if ('onmousedown' in window) { document.addEventListener("mousedown", mousedown); document.addEventListener("mousemove", mousemove); document.addEventListener("mouseup", mouseup); - document.addEventListener("wheel", wheelResize); + document.addEventListener("wheel", + (e) => this.rescale(e.deltaY < 0 ? "up" : "down")); } if ('ontouchstart' in window) { // https://stackoverflow.com/a/42509310/12660887 diff --git a/variants/Benedict/class.js b/variants/Benedict/class.js index bbaf8e9..81fee87 100644 --- a/variants/Benedict/class.js +++ b/variants/Benedict/class.js @@ -35,13 +35,13 @@ export default class BenedictRules extends ChessRules { const attacks = specs.attack || specs.moves; for (let a of attacks) { outerLoop: for (let step of a.steps) { - let [i, j] = [x + step[0], this.computeY(y + step[1])]; + let [i, j] = [x + step[0], this.getY(y + step[1])]; let nbSteps = 1; while (this.onBoard(i, j) && this.board[i][j] == "") { if (a.range <= nbSteps++) continue outerLoop; i += step[0]; - j = this.computeY(j + step[1]); + j = this.getY(j + step[1]); } if ( this.onBoard(i, j) && this.getColor(i, j) == oppCol && diff --git a/variants/Hex/class.js b/variants/Hex/class.js index ab634b8..91a0fe6 100644 --- a/variants/Hex/class.js +++ b/variants/Hex/class.js @@ -171,8 +171,11 @@ export default class HexRules extends ChessRules { } }; - if ('onmousedown' in window) + 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}); }