mirror of
https://github.com/nacabaro/vbhelper.git
synced 2026-06-05 22:02:54 +00:00
Create AttackSpriteImage.kt
This commit is contained in:
parent
9bcbe85b7f
commit
c947e2519c
@ -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<Bitmap?>(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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user