From c947e2519cb963d07458f33622c7aebb934bed10 Mon Sep 17 00:00:00 2001 From: lightheel Date: Sat, 2 Aug 2025 06:25:54 -0400 Subject: [PATCH] Create AttackSpriteImage.kt --- .../vbhelper/components/AttackSpriteImage.kt | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 app/src/main/java/com/github/nacabaro/vbhelper/components/AttackSpriteImage.kt diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/components/AttackSpriteImage.kt b/app/src/main/java/com/github/nacabaro/vbhelper/components/AttackSpriteImage.kt new file mode 100644 index 0000000..9bf6b12 --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/components/AttackSpriteImage.kt @@ -0,0 +1,44 @@ +package com.github.nacabaro.vbhelper.battle + +import android.graphics.Bitmap +import androidx.compose.foundation.Image +import androidx.compose.runtime.* +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.asImageBitmap +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.platform.LocalContext +import com.github.nacabaro.vbhelper.battle.AttackSpriteManager +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext + +@Composable +fun AttackSpriteImage( + characterId: String, + isLarge: Boolean = false, + modifier: Modifier = Modifier, + contentScale: ContentScale = ContentScale.Fit +) { + var bitmap by remember { mutableStateOf(null) } + val coroutineScope = rememberCoroutineScope() + val context = LocalContext.current + + LaunchedEffect(characterId, isLarge) { + coroutineScope.launch { + val attackSpriteManager = AttackSpriteManager(context) + val loadedBitmap = withContext(Dispatchers.IO) { + attackSpriteManager.getAttackSprite(characterId, isLarge) + } + bitmap = loadedBitmap + } + } + + bitmap?.let { bmp -> + Image( + bitmap = bmp.asImageBitmap(), + contentDescription = "Attack Sprite", + modifier = modifier, + contentScale = contentScale + ) + } +} \ No newline at end of file