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()
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)
// 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)
// Update the UI to reflect the changes
themeSelector.updateThemes(progressionManager.getUnlockedThemes(), currentTheme)
blockSkinSelector.updateBlockSkins(
progressionManager.getUnlockedBlocks(),
randomBlock,
progressionManager.getPlayerLevel()
)
// Get current block skin after change for debugging
val newBlockSkin = gameView.getCurrentBlockSkin()
Log.d("RandomMode", "Block skin after change: $newBlockSkin")
// Add a vibration to indicate the change to the player
gameHaptics.vibrateForPieceLock()
// 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")
}