mirror of
https://github.com/nacabaro/vbhelper.git
synced 2026-01-28 00:15:32 +00:00
Fixed bug syncing watch adventure missions progress with the app
This commit is contained in:
parent
0b3ce486cb
commit
73c393df64
@ -1,17 +1,28 @@
|
|||||||
package com.github.nacabaro.vbhelper.daos
|
package com.github.nacabaro.vbhelper.daos
|
||||||
|
|
||||||
import androidx.room.Dao
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Insert
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import androidx.room.Upsert
|
|
||||||
import com.github.nacabaro.vbhelper.domain.card.CardProgress
|
import com.github.nacabaro.vbhelper.domain.card.CardProgress
|
||||||
|
import com.github.nacabaro.vbhelper.dtos.CharacterDtos
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface CardProgressDao {
|
interface CardProgressDao {
|
||||||
@Upsert
|
@Query("""
|
||||||
fun updateDimProgress(vararg cardProgresses: CardProgress)
|
UPDATE CardProgress
|
||||||
|
SET
|
||||||
|
currentStage = :currentStage,
|
||||||
|
unlocked = :unlocked
|
||||||
|
WHERE cardId = :cardId AND
|
||||||
|
currentStage < :currentStage
|
||||||
|
""")
|
||||||
|
fun updateCardProgress(currentStage: Int, cardId: Long, unlocked: Boolean)
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"SELECT currentStage FROM CardProgress WHERE cardId = :cardId"
|
"SELECT currentStage FROM CardProgress WHERE cardId = :cardId"
|
||||||
)
|
)
|
||||||
fun getCardProgress(cardId: Long): Int
|
fun getCardProgress(cardId: Long): Int
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
fun insertCardProgress(cardProgress: CardProgress)
|
||||||
}
|
}
|
||||||
@ -24,10 +24,12 @@ interface CharacterDao {
|
|||||||
d.cardId as cardId,
|
d.cardId as cardId,
|
||||||
c.charaIndex as charId,
|
c.charaIndex as charId,
|
||||||
c.stage as stage,
|
c.stage as stage,
|
||||||
c.attribute as attribute
|
c.attribute as attribute,
|
||||||
|
cp.currentStage as currentStage
|
||||||
FROM CardCharacter c
|
FROM CardCharacter c
|
||||||
JOIN UserCharacter uc ON c.id = uc.charId
|
JOIN UserCharacter uc ON c.id = uc.charId
|
||||||
JOIN Card d ON c.cardId = d.id
|
JOIN Card d ON c.cardId = d.id
|
||||||
|
JOIN CardProgress cp ON d.id = cp.cardId
|
||||||
WHERE c.id = :charId
|
WHERE c.id = :charId
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|||||||
@ -38,7 +38,8 @@ object CharacterDtos {
|
|||||||
val cardId: Long,
|
val cardId: Long,
|
||||||
val charId: Int,
|
val charId: Int,
|
||||||
val stage: Int,
|
val stage: Int,
|
||||||
val attribute: NfcCharacter.Attribute
|
val attribute: NfcCharacter.Attribute,
|
||||||
|
val currentStage: Int
|
||||||
)
|
)
|
||||||
|
|
||||||
data class TransformationHistory(
|
data class TransformationHistory(
|
||||||
|
|||||||
@ -7,8 +7,11 @@ import androidx.compose.foundation.verticalScroll
|
|||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.github.nacabaro.vbhelper.components.TopBanner
|
import com.github.nacabaro.vbhelper.components.TopBanner
|
||||||
@ -23,7 +26,7 @@ fun CardAdventureScreen(
|
|||||||
cardId: Long
|
cardId: Long
|
||||||
) {
|
) {
|
||||||
val cardAdventureMissions = remember { mutableStateOf(emptyList<CardDtos.CardAdventureWithSprites>()) }
|
val cardAdventureMissions = remember { mutableStateOf(emptyList<CardDtos.CardAdventureWithSprites>()) }
|
||||||
var currentCardAdventure = remember { 0 }
|
var currentCardAdventure by remember { mutableIntStateOf(0) }
|
||||||
|
|
||||||
LaunchedEffect(cardId) {
|
LaunchedEffect(cardId) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
@ -55,7 +58,7 @@ fun CardAdventureScreen(
|
|||||||
cardAdventureMissions.value.mapIndexed { index, it ->
|
cardAdventureMissions.value.mapIndexed { index, it ->
|
||||||
CardAdventureEntry(
|
CardAdventureEntry(
|
||||||
cardAdventureEntry = it,
|
cardAdventureEntry = it,
|
||||||
obscure = index > currentCardAdventure
|
obscure = index > currentCardAdventure - 1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -152,15 +152,13 @@ class FromNfcConverter (
|
|||||||
nfcCharacter: NfcCharacter,
|
nfcCharacter: NfcCharacter,
|
||||||
cardData: Card
|
cardData: Card
|
||||||
) {
|
) {
|
||||||
val currentCardProgress = CardProgress(
|
|
||||||
cardId = cardData.id,
|
|
||||||
currentStage = nfcCharacter.nextAdventureMissionStage.toInt(),
|
|
||||||
unlocked = nfcCharacter.nextAdventureMissionStage.toInt() > cardData.stageCount
|
|
||||||
)
|
|
||||||
|
|
||||||
database
|
database
|
||||||
.cardProgressDao()
|
.cardProgressDao()
|
||||||
.updateDimProgress(currentCardProgress)
|
.updateCardProgress(
|
||||||
|
currentStage = nfcCharacter.nextAdventureMissionStage.toInt(),
|
||||||
|
cardId = cardData.id,
|
||||||
|
unlocked = nfcCharacter.nextAdventureMissionStage.toInt() > cardData.stageCount,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -38,14 +38,10 @@ class ToNfcConverter(
|
|||||||
.characterDao()
|
.characterDao()
|
||||||
.getCharacterInfo(userCharacter.charId)
|
.getCharacterInfo(userCharacter.charId)
|
||||||
|
|
||||||
val currentCardStage = database
|
|
||||||
.cardProgressDao()
|
|
||||||
.getCardProgress(characterInfo.cardId)
|
|
||||||
|
|
||||||
return if (userCharacter.characterType == DeviceType.BEDevice)
|
return if (userCharacter.characterType == DeviceType.BEDevice)
|
||||||
nfcToBENfc(characterId, characterInfo, currentCardStage, userCharacter)
|
nfcToBENfc(characterId, characterInfo, userCharacter)
|
||||||
else
|
else
|
||||||
nfcToVBNfc(characterId, characterInfo, currentCardStage, userCharacter)
|
nfcToVBNfc(characterId, characterInfo, userCharacter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -53,7 +49,6 @@ class ToNfcConverter(
|
|||||||
private suspend fun nfcToVBNfc(
|
private suspend fun nfcToVBNfc(
|
||||||
characterId: Long,
|
characterId: Long,
|
||||||
characterInfo: CharacterDtos.CardCharacterInfo,
|
characterInfo: CharacterDtos.CardCharacterInfo,
|
||||||
currentCardStage: Int,
|
|
||||||
userCharacter: UserCharacter
|
userCharacter: UserCharacter
|
||||||
): VBNfcCharacter {
|
): VBNfcCharacter {
|
||||||
val vbData = database
|
val vbData = database
|
||||||
@ -70,7 +65,7 @@ class ToNfcConverter(
|
|||||||
stage = characterInfo.stage.toByte(),
|
stage = characterInfo.stage.toByte(),
|
||||||
attribute = characterInfo.attribute,
|
attribute = characterInfo.attribute,
|
||||||
ageInDays = userCharacter.ageInDays.toByte(),
|
ageInDays = userCharacter.ageInDays.toByte(),
|
||||||
nextAdventureMissionStage = currentCardStage.toByte(),
|
nextAdventureMissionStage = characterInfo.currentStage.toByte(),
|
||||||
mood = userCharacter.mood.toByte(),
|
mood = userCharacter.mood.toByte(),
|
||||||
vitalPoints = userCharacter.vitalPoints.toUShort(),
|
vitalPoints = userCharacter.vitalPoints.toUShort(),
|
||||||
transformationCountdownInMinutes = userCharacter.transformationCountdown.toUShort(),
|
transformationCountdownInMinutes = userCharacter.transformationCountdown.toUShort(),
|
||||||
@ -173,7 +168,6 @@ class ToNfcConverter(
|
|||||||
private suspend fun nfcToBENfc(
|
private suspend fun nfcToBENfc(
|
||||||
characterId: Long,
|
characterId: Long,
|
||||||
characterInfo: CharacterDtos.CardCharacterInfo,
|
characterInfo: CharacterDtos.CardCharacterInfo,
|
||||||
currentCardStage: Int,
|
|
||||||
userCharacter: UserCharacter
|
userCharacter: UserCharacter
|
||||||
): BENfcCharacter {
|
): BENfcCharacter {
|
||||||
val beData = database
|
val beData = database
|
||||||
@ -188,7 +182,7 @@ class ToNfcConverter(
|
|||||||
stage = characterInfo.stage.toByte(),
|
stage = characterInfo.stage.toByte(),
|
||||||
attribute = characterInfo.attribute,
|
attribute = characterInfo.attribute,
|
||||||
ageInDays = userCharacter.ageInDays.toByte(),
|
ageInDays = userCharacter.ageInDays.toByte(),
|
||||||
nextAdventureMissionStage = currentCardStage.toByte(),
|
nextAdventureMissionStage = characterInfo.currentStage.toByte(),
|
||||||
mood = userCharacter.mood.toByte(),
|
mood = userCharacter.mood.toByte(),
|
||||||
vitalPoints = userCharacter.vitalPoints.toUShort(),
|
vitalPoints = userCharacter.vitalPoints.toUShort(),
|
||||||
itemEffectMentalStateValue = beData.itemEffectMentalStateValue.toByte(),
|
itemEffectMentalStateValue = beData.itemEffectMentalStateValue.toByte(),
|
||||||
|
|||||||
@ -336,15 +336,15 @@ class SettingsScreenControllerImpl(
|
|||||||
private fun updateCardProgress(
|
private fun updateCardProgress(
|
||||||
cardId: Long,
|
cardId: Long,
|
||||||
) {
|
) {
|
||||||
val cardProgress = CardProgress(
|
|
||||||
cardId = cardId,
|
|
||||||
currentStage = 0,
|
|
||||||
unlocked = false
|
|
||||||
)
|
|
||||||
|
|
||||||
database
|
database
|
||||||
.cardProgressDao()
|
.cardProgressDao()
|
||||||
.updateDimProgress(cardProgress)
|
.insertCardProgress(
|
||||||
|
CardProgress(
|
||||||
|
cardId = cardId,
|
||||||
|
currentStage = 1,
|
||||||
|
unlocked = false
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun importCard(uri: Uri) {
|
private fun importCard(uri: Uri) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user