diff options
author | pommicket <pommicket@gmail.com> | 2024-08-19 22:20:46 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2024-08-19 22:20:46 -0400 |
commit | b6743568630ed182a3791344b3c042c79cc3b559 (patch) | |
tree | 811b496f8036f8078a2a9fd93b3673e269b90c9b /game.js | |
parent | 2deeda6f7c219522218a722bee17b646bd2b7ba6 (diff) |
piece position validation, only update on mouseup, etc.
Diffstat (limited to 'game.js')
-rw-r--r-- | game.js | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -212,7 +212,7 @@ window.addEventListener('load', function () { element; nibTypes; connectedComponent; - upToDateWithServer; + needsServerUpdate; getClipPath() { const nibTypes = this.nibTypes; let shoulderWidth = (pieceWidth - nibSize) / 2; @@ -247,7 +247,7 @@ window.addEventListener('load', function () { this.y = y; this.u = u; this.v = v; - this.upToDateWithServer = true; + this.needsServerUpdate = false; this.connectedComponent = [this]; const element = this.element = document.createElement('div'); element.classList.add('piece'); @@ -300,6 +300,7 @@ window.addEventListener('load', function () { piece.element.classList.remove('no-animation'); piece.element.style.zIndex = pieceZIndexCounter; if (solved) break; + piece.needsServerUpdate = true; const col = piece.col(); const row = piece.row(); const bbox = piece.boundingBox(); @@ -341,7 +342,6 @@ window.addEventListener('load', function () { piece.x += dx; piece.y += dy; piece.updatePosition(); - piece.upToDateWithServer = false; } draggingPieceLastPos.x = e.clientX; draggingPieceLastPos.y = e.clientY; @@ -445,7 +445,7 @@ window.addEventListener('load', function () { // only receive the position of one piece per equivalence class mod is-connected-to if (connectivity[i] !== i) continue; const piece = pieces[i]; - if (!piece.upToDateWithServer) continue; + if (piece.needsServerUpdate) continue; if (draggingPiece && draggingPiece.connectedComponent === piece.connectedComponent) continue; const newPos = canonicalToScreenPos({x: piecePositions[2*i], y: piecePositions[2*i+1]}); const diff = [newPos.x - piece.x, newPos.y - piece.y]; @@ -468,7 +468,7 @@ window.addEventListener('load', function () { if (!receivedAck) return; // last update hasn't been acknowledged yet const motions = []; for (const piece of pieces) { - if (piece.upToDateWithServer) continue; + if (!piece.needsServerUpdate) continue; const canonicalPos = screenPosToCanonical({ x: piece.x, y: piece.y, @@ -530,7 +530,7 @@ window.addEventListener('load', function () { setJoinLink(puzzleID); } else if (e.data === 'ack') { for (const piece of pieces) { - piece.upToDateWithServer = true; + piece.needsServerUpdate = false; } receivedAck = true; } else if (waitingForServerToGiveUsImageUrl && e.data.startsWith('useImage ')) { |