From 9d3a190888805312a572177bf960f842481cab9a Mon Sep 17 00:00:00 2001 From: cmclark00 Date: Tue, 25 Mar 2025 19:03:13 -0400 Subject: [PATCH] Fix hard drop issues on mobile: prevent unwanted rotations when 3D effects are off and fix non-working hard drops when 3D effects are on --- script.js | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/script.js b/script.js index b167102..2c53eb2 100644 --- a/script.js +++ b/script.js @@ -670,6 +670,11 @@ class Piece { // Hard drop hardDrop() { + // Skip if we're in the middle of an animation already + if (this.rotationTransition || this.showCompletionEffect) { + return; + } + // Cancel any ongoing rotations or animations this.rotationTransition = false; this.showCompletionEffect = false; @@ -677,6 +682,14 @@ class Piece { this.rotationAngleY = 0; this.rotationAngleZ = 0; + // Clear rotation state completely + this.rotationDirection = null; + this.targetTetromino = null; + this.targetPattern = undefined; + this.targetKick = undefined; + this.originalTetromino = null; + this.rotationProgress = 0; + // Clear previous position this.undraw(); clearPreviousPiecePosition(); @@ -2188,7 +2201,10 @@ function handleControllerAction(action) { p.mirrorVertical(); break; case 'hardDrop': - p.hardDrop(); + // Only perform hard drop if not in the middle of an animation + if (!p.rotationTransition && !p.showCompletionEffect) { + p.hardDrop(); + } break; case 'pause': togglePause(); @@ -2409,13 +2425,13 @@ function handleTouchEnd(event) { const touchX = touch.clientX; const touchY = touch.clientY; - // Skip if we're in the middle of a rotation animation - if (p.rotationTransition || p.showCompletionEffect) { + // If a double tap is in progress, prevent further processing + if (doubleTapInProgress) { return; } - // If a double tap is in progress, prevent further processing - if (doubleTapInProgress) { + // Skip if we're in the middle of a rotation animation + if (p.rotationTransition || p.showCompletionEffect) { return; } @@ -2434,8 +2450,10 @@ function handleTouchEnd(event) { // This is a double tap - perform hard drop doubleTapInProgress = true; - // Perform the hard drop - p.hardDrop(); + // Perform the hard drop if not in an animation + if (!p.rotationTransition && !p.showCompletionEffect) { + p.hardDrop(); + } // Reset tap tracking tapCount = 0;