mirror of
https://github.com/nacabaro/vbhelper.git
synced 2026-01-28 00:15:32 +00:00
Algorithm to obscure undiscovered digimon
Logic still needs to be implemented to distinguish discovered from undiscovered.
This commit is contained in:
parent
ce1cf3eddb
commit
98bd74c544
@ -16,16 +16,18 @@ import androidx.compose.ui.unit.dp
|
||||
import com.github.nacabaro.vbhelper.domain.Sprites
|
||||
import com.github.nacabaro.vbhelper.utils.BitmapData
|
||||
import com.github.nacabaro.vbhelper.utils.getBitmap
|
||||
import com.github.nacabaro.vbhelper.utils.getObscuredBitmap
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
@Composable
|
||||
fun CharacterEntry(
|
||||
icon: BitmapData,
|
||||
obscure: Boolean = false,
|
||||
modifier: Modifier = Modifier,
|
||||
onClick: () -> Unit = { }
|
||||
) {
|
||||
val bitmap = remember (icon.bitmap) {
|
||||
icon.getBitmap()
|
||||
if(obscure) icon.getObscuredBitmap() else icon.getBitmap()
|
||||
}
|
||||
val imageBitmap = remember(bitmap) { bitmap.asImageBitmap() }
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.github.nacabaro.vbhelper.screens
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
@ -54,6 +55,7 @@ fun DiMScreen(
|
||||
items(characterList.value) { character ->
|
||||
CharacterEntry(
|
||||
onClick = { },
|
||||
obscure = true,
|
||||
icon = BitmapData(
|
||||
bitmap = character.sprite1,
|
||||
width = character.spritesWidth,
|
||||
|
||||
@ -14,6 +14,30 @@ fun BitmapData.getBitmap(): Bitmap {
|
||||
return Bitmap.createBitmap(createARGBIntArray(), this.width, this.height, Bitmap.Config.HARDWARE)
|
||||
}
|
||||
|
||||
object ARGBMasks {
|
||||
const val ALPHA = (0xFF shl 24)
|
||||
const val RED = (0xFF shl 16)
|
||||
const val GREEN = (0xFF shl 8)
|
||||
const val BLUE = 0xFF
|
||||
|
||||
}
|
||||
|
||||
const val BLACK = ARGBMasks.ALPHA
|
||||
|
||||
fun BitmapData.getObscuredBitmap(): Bitmap {
|
||||
val argbPixels = createARGBIntArray()
|
||||
for(i in argbPixels.indices) {
|
||||
val currentPixel = argbPixels[i]
|
||||
if( currentPixel and ARGBMasks.ALPHA != 0) {
|
||||
// non transparent pixel
|
||||
argbPixels[i] = BLACK
|
||||
}
|
||||
}
|
||||
return Bitmap.createBitmap(argbPixels, this.width, this.height, Bitmap.Config.HARDWARE)
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun BitmapData.createARGBIntArray(): IntArray {
|
||||
// hack to get it into correct format by relying on the DIM Sprites methods since we haven't changed the raw pixel data at this point.
|
||||
val bytes = SpriteData.Sprite.builder().width(this.width).height(this.height).pixelData(this.bitmap).build()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user