From da134247b17a2d9186cffe79d3372c30cffa4875 Mon Sep 17 00:00:00 2001 From: Christopher O'Grady Date: Wed, 19 Mar 2025 15:33:52 -0400 Subject: [PATCH] Remove duplicated stage and attribute from UserCharacter These fields are on the Character entity. --- .../nacabaro/vbhelper/daos/UserCharacterDao.kt | 12 ++++++++++++ .../nacabaro/vbhelper/domain/characters/Character.kt | 5 +++++ .../vbhelper/domain/device_data/UserCharacter.kt | 5 +++-- .../adventureScreen/AdventureScreenControllerImpl.kt | 2 +- .../screens/scanScreen/ScanScreenControllerImpl.kt | 2 -- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/daos/UserCharacterDao.kt b/app/src/main/java/com/github/nacabaro/vbhelper/daos/UserCharacterDao.kt index 6e8e33f..5d6c9c0 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/daos/UserCharacterDao.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/daos/UserCharacterDao.kt @@ -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 } \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Character.kt b/app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Character.kt index 3cb5b19..52f8010 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Character.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Character.kt @@ -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, diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/UserCharacter.kt b/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/UserCharacter.kt index 75007d7..8f2afb0 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/UserCharacter.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/UserCharacter.kt @@ -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, diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/adventureScreen/AdventureScreenControllerImpl.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/adventureScreen/AdventureScreenControllerImpl.kt index 7f01c9f..b775728 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/adventureScreen/AdventureScreenControllerImpl.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/adventureScreen/AdventureScreenControllerImpl.kt @@ -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() diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/scanScreen/ScanScreenControllerImpl.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/scanScreen/ScanScreenControllerImpl.kt index d7caf92..43638e9 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/scanScreen/ScanScreenControllerImpl.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/scanScreen/ScanScreenControllerImpl.kt @@ -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(),