From b60c106a086dbb5a399e7b93c39b3da7e7d6c25a Mon Sep 17 00:00:00 2001 From: cmclark00 Date: Mon, 31 Mar 2025 17:08:16 -0400 Subject: [PATCH] Fix block skin changes in random mode with improved logging and UI updates --- app/src/main/java/com/mintris/MainActivity.kt | 54 +++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/mintris/MainActivity.kt b/app/src/main/java/com/mintris/MainActivity.kt index 40818fa..76acec8 100644 --- a/app/src/main/java/com/mintris/MainActivity.kt +++ b/app/src/main/java/com/mintris/MainActivity.kt @@ -806,6 +806,18 @@ class MainActivity : AppCompatActivity(), gameBoard.reset() gameView.reset() + // Ensure block skin is properly set (helps with random mode) + val selectedSkin = progressionManager.getSelectedBlockSkin() + Log.d("RandomMode", "Game start: Setting block skin to $selectedSkin") + gameView.setBlockSkin(selectedSkin) + + // Update selectors to refresh UI state + blockSkinSelector.updateBlockSkins( + progressionManager.getUnlockedBlocks(), + selectedSkin, + progressionManager.getPlayerLevel() + ) + // Show game elements gameView.visibility = View.VISIBLE binding.gameControlsContainer.visibility = View.VISIBLE @@ -1894,6 +1906,10 @@ class MainActivity : AppCompatActivity(), Log.d("RandomMode", "Available themes: ${unlockedThemes.joinToString()}") Log.d("RandomMode", "Available blocks: ${unlockedBlocks.joinToString()}") + // Get current block skin for debugging + val currentBlockSkin = gameView.getCurrentBlockSkin() + Log.d("RandomMode", "Current block skin before change: $currentBlockSkin") + // Only proceed if there are unlocked themes and blocks if (unlockedThemes.isNotEmpty() && unlockedBlocks.isNotEmpty()) { // Apply random theme from unlocked themes - make sure not to pick the current theme @@ -1905,8 +1921,7 @@ class MainActivity : AppCompatActivity(), } // Apply random block skin from unlocked block skins - make sure not to pick the current skin - val currentSkin = gameView.getCurrentBlockSkin() - val availableBlocks = unlockedBlocks.filter { it != currentSkin } + val availableBlocks = unlockedBlocks.filter { it != currentBlockSkin } val randomBlock = if (availableBlocks.isNotEmpty()) { availableBlocks.random() } else { @@ -1919,20 +1934,27 @@ class MainActivity : AppCompatActivity(), currentTheme = randomTheme applyTheme(randomTheme) - // Force update the block skin with a specific call - gameView.setBlockSkin(randomBlock) - progressionManager.setSelectedBlockSkin(randomBlock) - - // Update the UI to reflect the changes - themeSelector.updateThemes(progressionManager.getUnlockedThemes(), currentTheme) - blockSkinSelector.updateBlockSkins( - progressionManager.getUnlockedBlocks(), - randomBlock, - progressionManager.getPlayerLevel() - ) - - // Add a vibration to indicate the change to the player - gameHaptics.vibrateForPieceLock() + // Force update the block skin with a specific call - with intentional delay + handler.post { + Log.d("RandomMode", "Setting block skin to: $randomBlock") + gameView.setBlockSkin(randomBlock) + progressionManager.setSelectedBlockSkin(randomBlock) + + // Get current block skin after change for debugging + val newBlockSkin = gameView.getCurrentBlockSkin() + Log.d("RandomMode", "Block skin after change: $newBlockSkin") + + // Update the UI to reflect the changes + themeSelector.updateThemes(progressionManager.getUnlockedThemes(), currentTheme) + blockSkinSelector.updateBlockSkins( + progressionManager.getUnlockedBlocks(), + randomBlock, + progressionManager.getPlayerLevel() + ) + + // Add a vibration to indicate the change to the player + gameHaptics.vibrateForPieceLock() + } } else { Log.d("RandomMode", "Cannot apply random theme/skin - no unlocked options available") }