Sprites now load correctly for Digimon and attacks.

This commit is contained in:
lightheel 2025-08-03 11:37:43 -04:00
parent fa8546f283
commit a4b159da45
2 changed files with 39 additions and 23 deletions

View File

@ -82,11 +82,18 @@ class BattleSpriteManager(private val context: Context) {
val spriteDataJson = spriteDataFile.readText() val spriteDataJson = spriteDataFile.readText()
val spriteData = gson.fromJson(spriteDataJson, SpriteData::class.java) val spriteData = gson.fromJson(spriteDataJson, SpriteData::class.java)
// Debug: Print sprite coordinates
println("Sprite coordinates: x=${spriteData.texture_rect.x}, y=${spriteData.texture_rect.y}, width=${spriteData.texture_rect.width}, height=${spriteData.texture_rect.height}")
println("Texture dimensions: width=${fullBitmap.width}, height=${fullBitmap.height}")
// Calculate the correct Y coordinate (inverted coordinate system)
val correctedY = fullBitmap.height - spriteData.texture_rect.y.toInt() - spriteData.texture_rect.height.toInt()
// Extract the sprite from the atlas using texture_rect coordinates // Extract the sprite from the atlas using texture_rect coordinates
val spriteBitmap = Bitmap.createBitmap( val spriteBitmap = Bitmap.createBitmap(
fullBitmap, fullBitmap,
spriteData.texture_rect.x.toInt(), spriteData.texture_rect.x.toInt(),
spriteData.texture_rect.y.toInt(), correctedY,
spriteData.texture_rect.width.toInt(), spriteData.texture_rect.width.toInt(),
spriteData.texture_rect.height.toInt() spriteData.texture_rect.height.toInt()
) )

View File

@ -252,10 +252,10 @@ fun BattleScreen(
.fillMaxSize() .fillMaxSize()
.background(Color.Black) .background(Color.Black)
) { ) {
println("Current battle view: ${battleSystem.currentView}") //println("Current battle view: ${battleSystem.currentView}")
when (battleSystem.currentView) { when (battleSystem.currentView) {
0 -> { 0 -> {
println("Showing PlayerBattleView") //println("Showing PlayerBattleView")
PlayerBattleView( PlayerBattleView(
battleSystem = battleSystem, battleSystem = battleSystem,
stage = stage, stage = stage,
@ -270,7 +270,7 @@ fun BattleScreen(
) )
} }
1 -> { 1 -> {
println("Showing OpponentBattleView") //println("Showing OpponentBattleView")
OpponentBattleView( OpponentBattleView(
battleSystem = battleSystem, battleSystem = battleSystem,
stage = stage, stage = stage,
@ -353,11 +353,11 @@ fun PlayerBattleView(
SpriteImage( SpriteImage(
spriteName = "00", // The sprite number (00, 01, 02, etc.) spriteName = "00", // The sprite number (00, 01, 02, etc.)
atlasName = activeCharacter?.charaId ?: when (stage) { atlasName = activeCharacter?.charaId ?: when (stage) {
"rookie" -> "dim000_mon01" "rookie" -> "dim275_mon01"
"champion" -> "dim012_mon04" "champion" -> "dim012_mon04"
"ultimate" -> "dim137_mon09" "ultimate" -> "dim137_mon09"
"mega" -> "dim012_mon14" "mega" -> "dim012_mon14"
else -> "dim000_mon01" else -> "dim275_mon01"
}, },
modifier = Modifier modifier = Modifier
.size(120.dp) .size(120.dp)
@ -386,7 +386,7 @@ fun PlayerBattleView(
// Attack animation overlay // Attack animation overlay
if (attackAnimationProgress > 0) { if (attackAnimationProgress > 0) {
AttackSpriteImage( AttackSpriteImage(
characterId = activeCharacter?.charaId ?: "dim000_mon03", characterId = activeCharacter?.charaId ?: "dim275_mon01",
isLarge = true, isLarge = true,
modifier = Modifier modifier = Modifier
.size(60.dp) .size(60.dp)
@ -423,7 +423,7 @@ fun PlayerBattleView(
) )
// Attack button // Attack button
println("PlayerBattleView: Attack button enabled = ${battleSystem.isAttackButtonEnabled}") //println("PlayerBattleView: Attack button enabled = ${battleSystem.isAttackButtonEnabled}")
Button( Button(
onClick = { onClick = {
println("Attack button clicked!") println("Attack button clicked!")
@ -502,11 +502,11 @@ fun OpponentBattleView(
SpriteImage( SpriteImage(
spriteName = "00", // The sprite number (00, 01, 02, etc.) spriteName = "00", // The sprite number (00, 01, 02, etc.)
atlasName = activeCharacter?.charaId ?: when (stage) { atlasName = activeCharacter?.charaId ?: when (stage) {
"rookie" -> "dim000_mon01" "rookie" -> "dim275_mon01"
"champion" -> "dim012_mon04" "champion" -> "dim012_mon04"
"ultimate" -> "dim137_mon09" "ultimate" -> "dim137_mon09"
"mega" -> "dim012_mon14" "mega" -> "dim012_mon14"
else -> "dim000_mon01" else -> "dim275_mon01"
}, },
modifier = Modifier modifier = Modifier
.size(120.dp) .size(120.dp)
@ -535,7 +535,7 @@ fun OpponentBattleView(
// Attack animation overlay // Attack animation overlay
if (attackAnimationProgress > 0) { if (attackAnimationProgress > 0) {
AttackSpriteImage( AttackSpriteImage(
characterId = activeCharacter?.charaId ?: "dim000_mon03", characterId = activeCharacter?.charaId ?: "dim275_mon01",
isLarge = true, isLarge = true,
modifier = Modifier modifier = Modifier
.size(60.dp) .size(60.dp)
@ -759,7 +759,7 @@ fun BattlesScreen() {
// Create hardcoded character lists for each stage // Create hardcoded character lists for each stage
val rookieCharacters = listOf( val rookieCharacters = listOf(
APIBattleCharacter("AGUMON", "degimon_name_Dim012_003", "dim012_mon03", 0, 1, 1800, 1800, 2400.0f, 700.0f), APIBattleCharacter("AGUMON", "degimon_name_Dim012_003", "dim012_mon03", 0, 1, 1800, 1800, 2400.0f, 700.0f),
APIBattleCharacter("PULSEMON", "degimon_name_Dim000_003", "dim000_mon03", 0, 1, 1800, 1800, 2400.0f, 700.0f), APIBattleCharacter("PULSEMON", "degimon_name_Dim275_001", "dim275_mon01", 0, 1, 1800, 1800, 2400.0f, 700.0f),
APIBattleCharacter("DORUMON", "degimon_name_dim137_mon03", "dim137_mon03", 0, 1, 3000, 3000, 5100.0f, 1050.0f) APIBattleCharacter("DORUMON", "degimon_name_dim137_mon03", "dim137_mon03", 0, 1, 3000, 3000, 5100.0f, 1050.0f)
) )
@ -844,6 +844,15 @@ fun BattlesScreen() {
championButton() championButton()
ultimateButton() ultimateButton()
megaButton() megaButton()
Button(
onClick = {
val spriteFileManager = SpriteFileManager(context)
spriteFileManager.clearSpriteFiles()
println("Sprite files cleared!")
}
) {
Text("Clear Sprite Files")
}
} }
} }