diff --git a/client/src/ui/components/Tutorial/TutorialGrid.tsx b/client/src/ui/components/Tutorial/TutorialGrid.tsx index 343184b..dd9ad33 100644 --- a/client/src/ui/components/Tutorial/TutorialGrid.tsx +++ b/client/src/ui/components/Tutorial/TutorialGrid.tsx @@ -256,10 +256,7 @@ const TutorialGrid: React.FC = forwardRef( setGameState(GameState.GRAVITY); }, [dragging, initialX]); - const handleMouseDown = (e: React.MouseEvent, block: Block) => { - e.preventDefault(); - e.stopPropagation(); - + const handleBonusApplication = (block: Block) => { setBlockBonus(block); if (bonus === BonusType.Wave) { setBlocks(removeBlocksSameRow(block, blocks)); @@ -280,18 +277,30 @@ const TutorialGrid: React.FC = forwardRef( ); }); } else if (bonus === BonusType.Hammer) { - console.log("Hammer bonus", { block }); setBlocks(removeBlockId(block, blocks)); if (gridPosition === null) return; handleTriggerLocalExplosion( gridPosition.left + block.x * gridSize + (block.width * gridSize) / 2, gridPosition.top + block.y * gridSize, ); + if (tutorialStep === 2) onUpdate(true); } + // Apply gravity immediately after bonus + applyGravity(); + setIsMoving(true); + setGameState(GameState.GRAVITY_BONUS); + if (bonus === BonusType.Hammer && tutorialStep === 2) onUpdate(true); + if (bonus === BonusType.Wave && tutorialStep === 3) onUpdate(true); + if (bonus === BonusType.Totem && tutorialStep === 4) onUpdate(true); + }; + + const handleMouseDown = (e: React.MouseEvent, block: Block) => { + e.preventDefault(); + e.stopPropagation(); + if (bonus !== BonusType.None) { - setIsMoving(true); - setGameState(GameState.GRAVITY_BONUS); + handleBonusApplication(block); return; } handleDragStart(e.clientX, block); @@ -308,41 +317,10 @@ const TutorialGrid: React.FC = forwardRef( e.preventDefault(); e.stopPropagation(); - setBlockBonus(block); - if (bonus === BonusType.Wave) { - setBlocks(removeBlocksSameRow(block, blocks)); - getBlocksSameRow(block.y, blocks).forEach((b) => { - if (gridPosition === null) return; - handleTriggerLocalExplosion( - gridPosition.left + b.x * gridSize + (b.width * gridSize) / 2, - gridPosition.top + b.y * gridSize, - ); - }); - } else if (bonus === BonusType.Totem) { - setBlocks(removeBlocksSameWidth(block, blocks)); - getBlocksSameWidth(block, blocks).forEach((b) => { - if (gridPosition === null) return; - handleTriggerLocalExplosion( - gridPosition.left + b.x * gridSize + (b.width * gridSize) / 2, - gridPosition.top + b.y * gridSize, - ); - }); - } else if (bonus === BonusType.Hammer) { - setBlocks(removeBlockId(block, blocks)); - if (gridPosition === null) return; - handleTriggerLocalExplosion( - gridPosition.left + block.x * gridSize + (block.width * gridSize) / 2, - gridPosition.top + block.y * gridSize, - ); - if (tutorialStep === 2) onUpdate(true); - } - if (bonus !== BonusType.None) { - setIsMoving(true); - setGameState(GameState.GRAVITY_BONUS); + handleBonusApplication(block); return; } - const touch = e.touches[0]; handleDragStart(touch.clientX, block); };