Fixed bug where enemy attack was showing as player attack sprite for a moment before animation.

This commit is contained in:
lightheel 2025-08-04 12:21:41 -04:00
parent cfa52bce9b
commit c5cebd8213

View File

@ -205,6 +205,11 @@ fun PlayerBattleView(
opponent: APIBattleCharacter?, opponent: APIBattleCharacter?,
onSetPendingDamage: (Float, Float) -> Unit onSetPendingDamage: (Float, Float) -> Unit
) { ) {
// Track previous character ID to detect transitions
var previousCharacterId by remember { mutableStateOf<String?>(null) }
var previousAttackPhase by remember { mutableStateOf<Int?>(null) }
var isTransitioning by remember { mutableStateOf(false) }
Box( Box(
modifier = Modifier.fillMaxSize() modifier = Modifier.fillMaxSize()
) { ) {
@ -293,20 +298,35 @@ fun PlayerBattleView(
else -> activeCharacter?.charaId ?: "dim011_mon01" // Use player's character ID else -> activeCharacter?.charaId ?: "dim011_mon01" // Use player's character ID
} }
// Handle sprite transition
LaunchedEffect(characterId, battleSystem.attackPhase) {
if ((previousCharacterId != null && previousCharacterId != characterId) ||
(previousAttackPhase != null && previousAttackPhase != battleSystem.attackPhase)) {
// Character ID or attack phase changed, start transition
isTransitioning = true
delay(100) // Brief invisibility period
isTransitioning = false
}
previousCharacterId = characterId
previousAttackPhase = battleSystem.attackPhase
}
println("PlayerBattleView - Attack sprite - Phase: ${battleSystem.attackPhase}, Progress: $attackAnimationProgress, X Offset: $xOffset, CurrentView: ${battleSystem.currentView}") println("PlayerBattleView - Attack sprite - Phase: ${battleSystem.attackPhase}, Progress: $attackAnimationProgress, X Offset: $xOffset, CurrentView: ${battleSystem.currentView}")
AttackSpriteImage( if (!isTransitioning) {
characterId = characterId, AttackSpriteImage(
isLarge = true, characterId = characterId,
modifier = Modifier isLarge = true,
.size(60.dp) modifier = Modifier
.offset( .size(60.dp)
x = xOffset, .offset(
y = 0.dp x = xOffset,
) y = 0.dp
.scale(if (battleSystem.attackPhase == 4) 1f else -1f, 1f), // Don't flip opponent attacks )
contentScale = ContentScale.Fit .scale(if (battleSystem.attackPhase == 4) 1f else -1f, 1f), // Don't flip opponent attacks
) contentScale = ContentScale.Fit
)
}
} }
} }
} }
@ -434,6 +454,11 @@ fun OpponentBattleView(
activeCharacter: APIBattleCharacter? = null, activeCharacter: APIBattleCharacter? = null,
playerCharacter: APIBattleCharacter? = null playerCharacter: APIBattleCharacter? = null
) { ) {
// Track previous character ID to detect transitions
var previousCharacterId by remember { mutableStateOf<String?>(null) }
var previousAttackPhase by remember { mutableStateOf<Int?>(null) }
var isTransitioning by remember { mutableStateOf(false) }
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
@ -478,20 +503,35 @@ fun OpponentBattleView(
else -> "dim011_mon01" else -> "dim011_mon01"
} }
// Handle sprite transition
LaunchedEffect(characterId, battleSystem.attackPhase) {
if ((previousCharacterId != null && previousCharacterId != characterId) ||
(previousAttackPhase != null && previousAttackPhase != battleSystem.attackPhase)) {
// Character ID or attack phase changed, start transition
isTransitioning = true
delay(100) // Brief invisibility period
isTransitioning = false
}
previousCharacterId = characterId
previousAttackPhase = battleSystem.attackPhase
}
println("OpponentBattleView - Attack sprite - Phase: ${battleSystem.attackPhase}, Progress: $attackAnimationProgress, X Offset: $xOffset, CurrentView: ${battleSystem.currentView}") println("OpponentBattleView - Attack sprite - Phase: ${battleSystem.attackPhase}, Progress: $attackAnimationProgress, X Offset: $xOffset, CurrentView: ${battleSystem.currentView}")
AttackSpriteImage( if (!isTransitioning) {
characterId = characterId, AttackSpriteImage(
isLarge = true, characterId = characterId,
modifier = Modifier isLarge = true,
.size(60.dp) modifier = Modifier
.offset( .size(60.dp)
x = xOffset, .offset(
y = 0.dp x = xOffset,
) y = 0.dp
.scale(if (battleSystem.attackPhase == 2) -1f else 1f, 1f), // Flip player attacks only )
contentScale = ContentScale.Fit .scale(if (battleSystem.attackPhase == 2) -1f else 1f, 1f), // Flip player attacks only
) contentScale = ContentScale.Fit
)
}
} }
} }