X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=base_rules.js;h=8ad54a42315492f312e5605e4edbcc662f7289b6;hb=8cc2f6d0a723c9583a99f9228bb441d8d8c5da5a;hp=2d95f6c4362b97fb538c11a909276405ee4447c4;hpb=635418a5af6d4bf3f497d319a235bf72e40c5683;p=xogo.git diff --git a/base_rules.js b/base_rules.js index 2d95f6c..8ad54a4 100644 --- a/base_rules.js +++ b/base_rules.js @@ -1347,6 +1347,8 @@ export default class ChessRules { }); } +// TODO: pawnfall + Cannibal issues + pawnPostProcess(moves, color, oppCol) { let moreMoves = []; const lastRank = (color == "w" ? 0 : this.size.x - 1); @@ -1361,7 +1363,12 @@ export default class ChessRules { ); if (!promotionOk) return; //nothing to do - if (!this.options["pawnfall"]) { + if (this.options["pawnfall"]) { + m.appear.shift(); + m.pawnfall = true; //required in prePlay() /// ???????????? + return; + } + //if (!this.options["pawnfall"]) { --> OK if ( this.options["cannibal"] && this.board[x2][y2] != "" && @@ -1371,7 +1378,7 @@ export default class ChessRules { } else finalPieces = this.pawnPromotions; - } + //} m.appear[0].p = finalPieces[0]; if (initPiece == "!") //cannibal king-pawn m.appear[0].p = C.CannibalKingCode[finalPieces[0]]; @@ -1386,8 +1393,6 @@ export default class ChessRules { } let newMove = this.getBasicMove([x1, y1], [x2, y2], tr); if (this.options["pawnfall"]) { - newMove.appear.shift(); - newMove.pawnfall = true; //required in prePlay() } moreMoves.push(newMove); } @@ -1946,6 +1951,11 @@ export default class ChessRules { }); } + +// TODO: englober + de cas ici... + // + generique start/end board or reserve + // + bien séparer les options... ? + prePlay(move) { if ( typeof move.start.x == "number" && @@ -2154,6 +2164,10 @@ export default class ChessRules { return; } let movingPiece = this.getDomPiece(move.start.x, move.start.y); + if (!movingPiece) { //TODO this shouldn't be required + callback(); + return; + } const initTransform = movingPiece.style.transform; let chessboard = document.getElementById(this.containerId).querySelector(".chessboard"); @@ -2180,18 +2194,10 @@ export default class ChessRules { const [i2, j2] = move.segments[index][1]; const dep = this.getPixelPosition(i1, j1, r); const arr = this.getPixelPosition(i2, j2, r); - -console.log(dep,arr); //TODO: this seems right, but translations don't work well. - - // Start from i1, j1: - movingPiece.style.transform = - `translate(${dep[0] - ix}px, ${dep[1] - iy}px)`; - movingPiece.style.transitionDuration = "0s"; const distance = Math.sqrt((arr[0] - dep[0]) ** 2 + (arr[1] - dep[1]) ** 2); const duration = 0.2 + (distance / maxDist) * 0.3; - movingPiece.style.transform = - `translate(${arr[0] - dep[0]}px, ${arr[1] - dep[1]}px)`; + movingPiece.style.transform = `translate(${arr[0]}px, ${arr[1]}px)`; movingPiece.style.transitionDuration = duration + "s"; setTimeout(cb, duration * 1000); };