Fix block skin changes in random mode with improved logging and UI updates

This commit is contained in:
cmclark00 2025-03-31 17:08:16 -04:00
parent 5faa780c62
commit b60c106a08

View file

@ -806,6 +806,18 @@ class MainActivity : AppCompatActivity(),
gameBoard.reset() gameBoard.reset()
gameView.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 // Show game elements
gameView.visibility = View.VISIBLE gameView.visibility = View.VISIBLE
binding.gameControlsContainer.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 themes: ${unlockedThemes.joinToString()}")
Log.d("RandomMode", "Available blocks: ${unlockedBlocks.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 // Only proceed if there are unlocked themes and blocks
if (unlockedThemes.isNotEmpty() && unlockedBlocks.isNotEmpty()) { if (unlockedThemes.isNotEmpty() && unlockedBlocks.isNotEmpty()) {
// Apply random theme from unlocked themes - make sure not to pick the current theme // 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 // 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 != currentBlockSkin }
val availableBlocks = unlockedBlocks.filter { it != currentSkin }
val randomBlock = if (availableBlocks.isNotEmpty()) { val randomBlock = if (availableBlocks.isNotEmpty()) {
availableBlocks.random() availableBlocks.random()
} else { } else {
@ -1919,20 +1934,27 @@ class MainActivity : AppCompatActivity(),
currentTheme = randomTheme currentTheme = randomTheme
applyTheme(randomTheme) applyTheme(randomTheme)
// Force update the block skin with a specific call // Force update the block skin with a specific call - with intentional delay
gameView.setBlockSkin(randomBlock) handler.post {
progressionManager.setSelectedBlockSkin(randomBlock) Log.d("RandomMode", "Setting block skin to: $randomBlock")
gameView.setBlockSkin(randomBlock)
progressionManager.setSelectedBlockSkin(randomBlock)
// Update the UI to reflect the changes // Get current block skin after change for debugging
themeSelector.updateThemes(progressionManager.getUnlockedThemes(), currentTheme) val newBlockSkin = gameView.getCurrentBlockSkin()
blockSkinSelector.updateBlockSkins( Log.d("RandomMode", "Block skin after change: $newBlockSkin")
progressionManager.getUnlockedBlocks(),
randomBlock,
progressionManager.getPlayerLevel()
)
// Add a vibration to indicate the change to the player // Update the UI to reflect the changes
gameHaptics.vibrateForPieceLock() 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 { } else {
Log.d("RandomMode", "Cannot apply random theme/skin - no unlocked options available") Log.d("RandomMode", "Cannot apply random theme/skin - no unlocked options available")
} }