Merge pull request #26 from cfogrady/RemoveDuplicatedData

Remove duplicated stage and attribute from UserCharacter
This commit is contained in:
nacabaro 2025-03-22 00:34:07 +01:00 committed by GitHub
commit a4f3b701e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Upsert
import com.github.nacabaro.vbhelper.domain.characters.Character
import com.github.nacabaro.vbhelper.domain.device_data.UserCharacter
import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData
import com.github.nacabaro.vbhelper.domain.device_data.TransformationHistory
@ -116,4 +117,15 @@ interface UserCharacterDao {
@Query("UPDATE UserCharacter SET isActive = 1 WHERE id = :id")
fun setActiveCharacter(id: Long)
@Query(
"""
SELECT c.*
FROM Character c
join UserCharacter uc on c.id = uc.charId
where uc.id = :charId
LIMIT 1
"""
)
suspend fun getCharacterInfo(charId: Long): Character
}

View File

@ -14,6 +14,11 @@ import androidx.room.ForeignKey
)
]
)
/*
* Character represents a character on a DIM card. There should only be one of these per dimId
* and monIndex.
* TODO: Customs will mean this should be unique per cardName and monIndex
*/
data class Character (
@PrimaryKey(autoGenerate = true) val id: Long = 0,
val dimId: Long,

View File

@ -17,11 +17,12 @@ import com.github.nacabaro.vbhelper.domain.characters.Character
)
]
)
/**
* UserCharacter represents and instance of a character. The charId should map to a Character
*/
data class UserCharacter (
@PrimaryKey(autoGenerate = true) val id: Long = 0,
var charId: Long,
var stage: Int,
var attribute: NfcCharacter.Attribute,
var ageInDays: Int,
var nextAdventureMissionStage: Int, // next adventure mission stage on the character's dim
var mood: Int,

View File

@ -72,7 +72,7 @@ class AdventureScreenControllerImpl(
private suspend fun generateItem(characterId: Long): ItemDtos.PurchasedItem {
val character = database
.userCharacterDao()
.getCharacter(characterId)
.getCharacterInfo(characterId)
val randomItem = database
.itemDao()

View File

@ -167,8 +167,6 @@ class ScanScreenControllerImpl(
val characterData = UserCharacter(
charId = cardCharData.id,
stage = nfcCharacter.stage.toInt(),
attribute = nfcCharacter.attribute,
ageInDays = nfcCharacter.ageInDays.toInt(),
nextAdventureMissionStage = nfcCharacter.nextAdventureMissionStage.toInt(),
mood = nfcCharacter.mood.toInt(),