X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=base_rules.js;h=e7d58b26ebfa2c5b7470ea13cf4213cf4cf7bbae;hb=449d72e350051d3ddb86a360c7bb4a4327cbeb75;hp=d743c0e27f8301928dca99454094827a5998385d;hpb=15106e8201ee8e46ce14f1dd369cae960e9a860c;p=xogo.git diff --git a/base_rules.js b/base_rules.js index d743c0e..e7d58b2 100644 --- a/base_rules.js +++ b/base_rules.js @@ -2180,24 +2180,22 @@ 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); - // 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); }; - if (!move.segments) - move.segments = [[move.start.x, move.start.y], [move.end.x, move.end.y]]; + if (!move.segments) { + move.segments = [ + [[move.start.x, move.start.y], [move.end.x, move.end.y]] + ]; + } let index = 0; - animateSegment(index, () => { + const animateSegmentCallback = () => { if (index < move.segments.length) - animateSegment(++index); + animateSegment(index++, animateSegmentCallback); else { if (move.drag) movingPiece.remove(); @@ -2207,7 +2205,8 @@ export default class ChessRules { } callback(); } - }); + }; + animateSegmentCallback(); } playReceivedMove(moves, callback) {