M app/src/main/java/com/github/nacabaro/vbhelper/daos/CardProgressDao.kt => app/src/main/java/com/github/nacabaro/vbhelper/daos/CardProgressDao.kt +14 -3
@@ 1,17 1,28 @@
package com.github.nacabaro.vbhelper.daos
import androidx.room.Dao
+import androidx.room.Insert
import androidx.room.Query
-import androidx.room.Upsert
import com.github.nacabaro.vbhelper.domain.card.CardProgress
+import com.github.nacabaro.vbhelper.dtos.CharacterDtos
@Dao
interface CardProgressDao {
- @Upsert
- fun updateDimProgress(vararg cardProgresses: CardProgress)
+ @Query("""
+ UPDATE CardProgress
+ SET
+ currentStage = :currentStage,
+ unlocked = :unlocked
+ WHERE cardId = :cardId AND
+ currentStage < :currentStage
+ """)
+ fun updateCardProgress(currentStage: Int, cardId: Long, unlocked: Boolean)
@Query(
"SELECT currentStage FROM CardProgress WHERE cardId = :cardId"
)
fun getCardProgress(cardId: Long): Int
+
+ @Insert
+ fun insertCardProgress(cardProgress: CardProgress)
}=
\ No newline at end of file
M app/src/main/java/com/github/nacabaro/vbhelper/daos/CharacterDao.kt => app/src/main/java/com/github/nacabaro/vbhelper/daos/CharacterDao.kt +3 -1
@@ 24,10 24,12 @@ interface CharacterDao {
d.cardId as cardId,
c.charaIndex as charId,
c.stage as stage,
- c.attribute as attribute
+ c.attribute as attribute,
+ cp.currentStage as currentStage
FROM CardCharacter c
JOIN UserCharacter uc ON c.id = uc.charId
JOIN Card d ON c.cardId = d.id
+ JOIN CardProgress cp ON d.id = cp.cardId
WHERE c.id = :charId
"""
)
M app/src/main/java/com/github/nacabaro/vbhelper/dtos/CharacterDtos.kt => app/src/main/java/com/github/nacabaro/vbhelper/dtos/CharacterDtos.kt +2 -1
@@ 38,7 38,8 @@ object CharacterDtos {
val cardId: Long,
val charId: Int,
val stage: Int,
- val attribute: NfcCharacter.Attribute
+ val attribute: NfcCharacter.Attribute,
+ val currentStage: Int
)
data class TransformationHistory(
M app/src/main/java/com/github/nacabaro/vbhelper/screens/cardScreen/CardAdventureScreen.kt => app/src/main/java/com/github/nacabaro/vbhelper/screens/cardScreen/CardAdventureScreen.kt +5 -2
@@ 7,8 7,11 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.navigation.NavController
import com.github.nacabaro.vbhelper.components.TopBanner
@@ 23,7 26,7 @@ fun CardAdventureScreen(
cardId: Long
) {
val cardAdventureMissions = remember { mutableStateOf(emptyList<CardDtos.CardAdventureWithSprites>()) }
- var currentCardAdventure = remember { 0 }
+ var currentCardAdventure by remember { mutableIntStateOf(0) }
LaunchedEffect(cardId) {
withContext(Dispatchers.IO) {
@@ 55,7 58,7 @@ fun CardAdventureScreen(
cardAdventureMissions.value.mapIndexed { index, it ->
CardAdventureEntry(
cardAdventureEntry = it,
- obscure = index > currentCardAdventure
+ obscure = index > currentCardAdventure - 1
)
}
}
M app/src/main/java/com/github/nacabaro/vbhelper/screens/scanScreen/converters/FromNfcConverter.kt => app/src/main/java/com/github/nacabaro/vbhelper/screens/scanScreen/converters/FromNfcConverter.kt +5 -7
@@ 152,15 152,13 @@ class FromNfcConverter (
nfcCharacter: NfcCharacter,
cardData: Card
) {
- val currentCardProgress = CardProgress(
- cardId = cardData.id,
- currentStage = nfcCharacter.nextAdventureMissionStage.toInt(),
- unlocked = nfcCharacter.nextAdventureMissionStage.toInt() > cardData.stageCount
- )
-
database
.cardProgressDao()
- .updateDimProgress(currentCardProgress)
+ .updateCardProgress(
+ currentStage = nfcCharacter.nextAdventureMissionStage.toInt(),
+ cardId = cardData.id,
+ unlocked = nfcCharacter.nextAdventureMissionStage.toInt() > cardData.stageCount,
+ )
}
M app/src/main/java/com/github/nacabaro/vbhelper/screens/scanScreen/converters/ToNfcConverter.kt => app/src/main/java/com/github/nacabaro/vbhelper/screens/scanScreen/converters/ToNfcConverter.kt +4 -10
@@ 38,14 38,10 @@ class ToNfcConverter(
.characterDao()
.getCharacterInfo(userCharacter.charId)
- val currentCardStage = database
- .cardProgressDao()
- .getCardProgress(characterInfo.cardId)
-
return if (userCharacter.characterType == DeviceType.BEDevice)
- nfcToBENfc(characterId, characterInfo, currentCardStage, userCharacter)
+ nfcToBENfc(characterId, characterInfo, userCharacter)
else
- nfcToVBNfc(characterId, characterInfo, currentCardStage, userCharacter)
+ nfcToVBNfc(characterId, characterInfo, userCharacter)
}
@@ 53,7 49,6 @@ class ToNfcConverter(
private suspend fun nfcToVBNfc(
characterId: Long,
characterInfo: CharacterDtos.CardCharacterInfo,
- currentCardStage: Int,
userCharacter: UserCharacter
): VBNfcCharacter {
val vbData = database
@@ 70,7 65,7 @@ class ToNfcConverter(
stage = characterInfo.stage.toByte(),
attribute = characterInfo.attribute,
ageInDays = userCharacter.ageInDays.toByte(),
- nextAdventureMissionStage = currentCardStage.toByte(),
+ nextAdventureMissionStage = characterInfo.currentStage.toByte(),
mood = userCharacter.mood.toByte(),
vitalPoints = userCharacter.vitalPoints.toUShort(),
transformationCountdownInMinutes = userCharacter.transformationCountdown.toUShort(),
@@ 173,7 168,6 @@ class ToNfcConverter(
private suspend fun nfcToBENfc(
characterId: Long,
characterInfo: CharacterDtos.CardCharacterInfo,
- currentCardStage: Int,
userCharacter: UserCharacter
): BENfcCharacter {
val beData = database
@@ 188,7 182,7 @@ class ToNfcConverter(
stage = characterInfo.stage.toByte(),
attribute = characterInfo.attribute,
ageInDays = userCharacter.ageInDays.toByte(),
- nextAdventureMissionStage = currentCardStage.toByte(),
+ nextAdventureMissionStage = characterInfo.currentStage.toByte(),
mood = userCharacter.mood.toByte(),
vitalPoints = userCharacter.vitalPoints.toUShort(),
itemEffectMentalStateValue = beData.itemEffectMentalStateValue.toByte(),
M app/src/main/java/com/github/nacabaro/vbhelper/screens/settingsScreen/SettingsScreenControllerImpl.kt => app/src/main/java/com/github/nacabaro/vbhelper/screens/settingsScreen/SettingsScreenControllerImpl.kt +7 -7
@@ 336,15 336,15 @@ class SettingsScreenControllerImpl(
private fun updateCardProgress(
cardId: Long,
) {
- val cardProgress = CardProgress(
- cardId = cardId,
- currentStage = 0,
- unlocked = false
- )
-
database
.cardProgressDao()
- .updateDimProgress(cardProgress)
+ .insertCardProgress(
+ CardProgress(
+ cardId = cardId,
+ currentStage = 1,
+ unlocked = false
+ )
+ )
}
private fun importCard(uri: Uri) {