~cytrogen/vbhelper

074ced10825386b0a1cbde07d4b030e85eb35864 — nacabaro 1 year, 3 months ago ce1cf3e + 98bd74c
Merge pull request #17 from cfogrady/ObscuredDex

Algorithm to obscure undiscovered digimon
M app/src/main/java/com/github/nacabaro/vbhelper/components/CharacterEntry.kt => app/src/main/java/com/github/nacabaro/vbhelper/components/CharacterEntry.kt +3 -1
@@ 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() }


M app/src/main/java/com/github/nacabaro/vbhelper/screens/DimScreen.kt => app/src/main/java/com/github/nacabaro/vbhelper/screens/DimScreen.kt +2 -0
@@ 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,

M app/src/main/java/com/github/nacabaro/vbhelper/utils/BitmapData.kt => app/src/main/java/com/github/nacabaro/vbhelper/utils/BitmapData.kt +24 -0
@@ 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()