X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=base_rules.js;h=6303060aa497bbaff63d594301c28c88f2512a67;hb=bc34b505e536fc0d66747197fbb62b5ea1f85721;hp=30cb2726491ffa700c6a3f19e5c6fb6c3f625eb7;hpb=1aa9054d1d0564f97e8e01504a0363859d07c7f8;p=xogo.git diff --git a/base_rules.js b/base_rules.js index 30cb272..6303060 100644 --- a/base_rules.js +++ b/base_rules.js @@ -495,8 +495,8 @@ export default class ChessRules { let elt = document.getElementById(this.coordsToId([x, y])); elt.classList.remove("in-shadow"); if (this.board[x][y] != "") { - const color = this.getColor(i, j); - const piece = this.getPiece(i, j); + const color = this.getColor(x, y); + const piece = this.getPiece(x, y); this.g_pieces[x][y] = document.createElement("piece"); let newClasses = [ this.pieces()[piece]["class"], @@ -859,7 +859,7 @@ export default class ChessRules { // Touch screen, dragend touchLocation = e.changedTouches[0]; if (touchLocation) - return {x: touchLocation.pageX, y: touchLocation.pageY}; + return {x: touchLocation.clientX, y: touchLocation.clientY}; return [0, 0]; //Big trouble here =) } @@ -909,6 +909,9 @@ export default class ChessRules { e.preventDefault(); centerOnCursor(curPiece, e); } + else if (e.changedTouches && e.changedTouches.length >= 1) + // Attempt to prevent horizontal swipe... + e.preventDefault(); }; const mouseup = (e) => { @@ -949,6 +952,7 @@ export default class ChessRules { document.addEventListener("touchmove", mousemove, {passive: false}); document.addEventListener("touchend", mouseup, {passive: false}); } + // TODO: onpointerdown/move/up ? See reveal.js /controllers/touch.js } showChoices(moves, r) { @@ -2141,6 +2145,7 @@ export default class ChessRules { const maxDist = Math.sqrt((this.size.x - 1)** 2 + (this.size.y - 1) ** 2); const multFact = (distance - 1) / (maxDist - 1); //1 == minDist const duration = 0.2 + multFact * 0.3; + const initTransform = startPiece.style.transform; startPiece.style.transform = `translate(${arrival[0] + rs[0]}px, ${arrival[1] + rs[1]}px)`; startPiece.style.transitionDuration = duration + "s"; @@ -2150,6 +2155,10 @@ export default class ChessRules { if (this.options["rifle"]) startArray[i1][j1].style.opacity = "1"; startPiece.remove(); } + else { + startPiece.style.transform = initTransform; + startPiece.style.transitionDuration = "0s"; + } callback(); }, duration * 1000