mirror of
https://github.com/nacabaro/vbhelper.git
synced 2026-01-27 16:05:32 +00:00
Merge pull request #34 from nacabaro/vb/nfc_compat
Added basic VB support
This commit is contained in:
commit
2b33042fe0
@ -1,5 +1,6 @@
|
||||
package com.github.nacabaro.vbhelper.screens.homeScreens
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
@ -51,9 +52,12 @@ fun HomeScreen(
|
||||
LaunchedEffect(storageRepository, activeMon) {
|
||||
withContext(Dispatchers.IO) {
|
||||
activeMon.value = storageRepository.getActiveCharacter()
|
||||
if (activeMon.value != null) {
|
||||
if (activeMon.value != null && activeMon.value!!.characterType == DeviceType.BEDevice) {
|
||||
beData.value = storageRepository.getCharacterBeData(activeMon.value!!.id)
|
||||
transformationHistory.value = storageRepository.getTransformationHistory(activeMon.value!!.id)
|
||||
} else if (activeMon.value != null && activeMon.value!!.characterType == DeviceType.VBDevice) {
|
||||
vbData.value = storageRepository.getCharacterVbData(activeMon.value!!.id)
|
||||
transformationHistory.value = storageRepository.getTransformationHistory(activeMon.value!!.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -79,6 +83,7 @@ fun HomeScreen(
|
||||
}
|
||||
) { contentPadding ->
|
||||
if (activeMon.value == null || (beData.value == null && vbData.value == null) || transformationHistory.value == null) {
|
||||
Log.d("TetTet", "Something is null")
|
||||
Column (
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
@ -89,6 +94,7 @@ fun HomeScreen(
|
||||
Text(text = "Nothing to see here")
|
||||
}
|
||||
} else {
|
||||
Log.d("TetTet", "Something is not null")
|
||||
if (activeMon.value!!.isBemCard) {
|
||||
BEBEmHomeScreen(
|
||||
activeMon = activeMon.value!!,
|
||||
|
||||
@ -1,9 +1,24 @@
|
||||
package com.github.nacabaro.vbhelper.screens.homeScreens
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.github.nacabaro.vbhelper.R
|
||||
import com.github.nacabaro.vbhelper.components.CharacterEntry
|
||||
import com.github.nacabaro.vbhelper.components.ItemDisplay
|
||||
import com.github.nacabaro.vbhelper.components.TransformationHistoryCard
|
||||
import com.github.nacabaro.vbhelper.domain.device_data.VBCharacterData
|
||||
import com.github.nacabaro.vbhelper.dtos.CharacterDtos
|
||||
import com.github.nacabaro.vbhelper.utils.BitmapData
|
||||
import java.util.Locale
|
||||
|
||||
@Composable
|
||||
fun VBDiMHomeScreen(
|
||||
@ -12,5 +27,129 @@ fun VBDiMHomeScreen(
|
||||
transformationHistory: List<CharacterDtos.TransformationHistory>,
|
||||
contentPadding: PaddingValues
|
||||
) {
|
||||
TODO("Not implemented yet")
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(top = contentPadding.calculateTopPadding())
|
||||
.verticalScroll(state = rememberScrollState())
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
CharacterEntry(
|
||||
icon = BitmapData(
|
||||
bitmap = activeMon.spriteIdle,
|
||||
width = activeMon.spriteWidth,
|
||||
height = activeMon.spriteHeight
|
||||
),
|
||||
multiplier = 8,
|
||||
shape = androidx.compose.material.MaterialTheme.shapes.small,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.aspectRatio(1f)
|
||||
)
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.weight(0.5f)
|
||||
.aspectRatio(0.5f)
|
||||
) {
|
||||
ItemDisplay(
|
||||
icon = R.drawable.baseline_vitals_24,
|
||||
textValue = activeMon.vitalPoints.toString(),
|
||||
definition = "Vitals",
|
||||
modifier = Modifier
|
||||
.weight(0.5f)
|
||||
.aspectRatio(1f)
|
||||
.padding(8.dp)
|
||||
)
|
||||
ItemDisplay(
|
||||
icon = R.drawable.baseline_trophy_24,
|
||||
textValue = activeMon.trophies.toString(),
|
||||
definition = "Trophies",
|
||||
modifier = Modifier
|
||||
.weight(0.5f)
|
||||
.aspectRatio(1f)
|
||||
.padding(8.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
ItemDisplay(
|
||||
icon = R.drawable.baseline_mood_24,
|
||||
textValue = activeMon.mood.toString(),
|
||||
definition = "Mood",
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.aspectRatio(1f)
|
||||
.padding(8.dp)
|
||||
)
|
||||
val transformationCountdownInHours = activeMon.transformationCountdown / 60
|
||||
ItemDisplay(
|
||||
icon = R.drawable.baseline_next_24,
|
||||
textValue = when (transformationCountdownInHours) {
|
||||
0 -> "${activeMon.transformationCountdown} m"
|
||||
else -> "$transformationCountdownInHours h"
|
||||
},
|
||||
definition = "Next timer",
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.aspectRatio(1f)
|
||||
.padding(8.dp)
|
||||
)
|
||||
ItemDisplay(
|
||||
icon = R.drawable.baseline_swords_24,
|
||||
textValue = when {
|
||||
activeMon.totalBattlesLost == 0 -> "0.00 %"
|
||||
else -> {
|
||||
val battleWinPercentage =
|
||||
activeMon.totalBattlesWon.toFloat() / (activeMon.totalBattlesWon + activeMon.totalBattlesLost).toFloat()
|
||||
String.format(
|
||||
Locale.getDefault(),
|
||||
"%.2f",
|
||||
battleWinPercentage * 100
|
||||
) + " %" // Specify locale
|
||||
}
|
||||
},
|
||||
definition = "Total battle win %",
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.aspectRatio(1f)
|
||||
.padding(8.dp)
|
||||
)
|
||||
ItemDisplay(
|
||||
icon = R.drawable.baseline_swords_24,
|
||||
textValue = when {
|
||||
activeMon.totalBattlesLost == 0 -> "0.00 %"
|
||||
else -> {
|
||||
val battleWinPercentage =
|
||||
activeMon.currentPhaseBattlesWon.toFloat() / (activeMon.currentPhaseBattlesWon + activeMon.currentPhaseBattlesLost).toFloat()
|
||||
String.format(
|
||||
Locale.getDefault(),
|
||||
"%.2f",
|
||||
battleWinPercentage * 100
|
||||
) + " %" // Specify locale
|
||||
}
|
||||
},
|
||||
definition = "Current phase win %",
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.aspectRatio(1f)
|
||||
.padding(8.dp)
|
||||
)
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
TransformationHistoryCard(
|
||||
transformationHistory = transformationHistory,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(8.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -11,7 +11,9 @@ import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.github.cfogrady.vbnfc.TagCommunicator
|
||||
import com.github.cfogrady.vbnfc.be.BENfcCharacter
|
||||
import com.github.cfogrady.vbnfc.data.NfcCharacter
|
||||
import com.github.cfogrady.vbnfc.vb.VBNfcCharacter
|
||||
import com.github.nacabaro.vbhelper.ActivityLifecycleListener
|
||||
import com.github.nacabaro.vbhelper.screens.scanScreen.converters.FromNfcConverter
|
||||
import com.github.nacabaro.vbhelper.screens.scanScreen.converters.ToNfcConverter
|
||||
@ -118,7 +120,15 @@ class ScanScreenControllerImpl(
|
||||
) {
|
||||
handleTag(secrets) { tagCommunicator ->
|
||||
try {
|
||||
tagCommunicator.sendCharacter(nfcCharacter)
|
||||
if (nfcCharacter is VBNfcCharacter) {
|
||||
Log.d("SendCharacter", "VBNfcCharacter")
|
||||
val castNfcCharacter: VBNfcCharacter = nfcCharacter
|
||||
tagCommunicator.sendCharacter(castNfcCharacter)
|
||||
} else if (nfcCharacter is BENfcCharacter) {
|
||||
Log.d("SendCharacter", "BENfcCharacter")
|
||||
val castNfcCharacter: BENfcCharacter = nfcCharacter
|
||||
tagCommunicator.sendCharacter(castNfcCharacter)
|
||||
}
|
||||
onComplete.invoke()
|
||||
"Sent character successfully!"
|
||||
} catch (e: Throwable) {
|
||||
@ -157,6 +167,9 @@ class ScanScreenControllerImpl(
|
||||
val nfcGenerator = ToNfcConverter(
|
||||
componentActivity = componentActivity
|
||||
)
|
||||
return nfcGenerator.characterToNfc(characterId)
|
||||
|
||||
val character = nfcGenerator.characterToNfc(characterId)
|
||||
Log.d("CharacterType", character.toString())
|
||||
return character
|
||||
}
|
||||
}
|
||||
@ -59,7 +59,7 @@ class ToNfcConverter(
|
||||
.userCharacterDao()
|
||||
.getVbData(characterId)
|
||||
|
||||
val paddedTransformationArray = generateTransformationHistory(characterId)
|
||||
val paddedTransformationArray = generateTransformationHistory(characterId, 9)
|
||||
|
||||
val watchSpecialMissions = generateSpecialMissionsArray(characterId)
|
||||
|
||||
@ -218,7 +218,8 @@ class ToNfcConverter(
|
||||
|
||||
|
||||
private suspend fun generateTransformationHistory(
|
||||
characterId: Long
|
||||
characterId: Long,
|
||||
length: Int = 8
|
||||
): Array<NfcCharacter.Transformation> {
|
||||
val transformationHistory = database
|
||||
.userCharacterDao()
|
||||
@ -242,7 +243,7 @@ class ToNfcConverter(
|
||||
)
|
||||
}.toTypedArray()
|
||||
|
||||
val paddedTransformationArray = padTransformationArray(transformationHistory)
|
||||
val paddedTransformationArray = padTransformationArray(transformationHistory, length)
|
||||
|
||||
return paddedTransformationArray
|
||||
}
|
||||
@ -250,13 +251,14 @@ class ToNfcConverter(
|
||||
|
||||
|
||||
private fun padTransformationArray(
|
||||
transformationArray: Array<NfcCharacter.Transformation>
|
||||
transformationArray: Array<NfcCharacter.Transformation>,
|
||||
length: Int
|
||||
): Array<NfcCharacter.Transformation> {
|
||||
if (transformationArray.size >= 8) {
|
||||
return transformationArray
|
||||
}
|
||||
|
||||
val paddedArray = Array(8) {
|
||||
val paddedArray = Array(length) {
|
||||
NfcCharacter.Transformation(
|
||||
toCharIndex = 255u,
|
||||
year = 65535u,
|
||||
|
||||
@ -2,6 +2,7 @@ package com.github.nacabaro.vbhelper.source
|
||||
|
||||
import com.github.nacabaro.vbhelper.database.AppDatabase
|
||||
import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData
|
||||
import com.github.nacabaro.vbhelper.domain.device_data.VBCharacterData
|
||||
import com.github.nacabaro.vbhelper.dtos.CharacterDtos
|
||||
|
||||
class StorageRepository (
|
||||
@ -23,6 +24,10 @@ class StorageRepository (
|
||||
return db.userCharacterDao().getTransformationHistory(characterId)
|
||||
}
|
||||
|
||||
suspend fun getCharacterVbData(id: Long): VBCharacterData {
|
||||
return db.userCharacterDao().getVbData(id)
|
||||
}
|
||||
|
||||
suspend fun getActiveCharacter(): CharacterDtos.CharacterWithSprites? {
|
||||
return db.userCharacterDao().getActiveCharacter()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user