mirror of
https://github.com/nacabaro/vbhelper.git
synced 2026-01-27 16:05:32 +00:00
Merge pull request #35 from nacabaro/vb/special_missions
Special missions
This commit is contained in:
commit
3c17e93d0f
Binary file not shown.
@ -5,11 +5,14 @@ import androidx.compose.foundation.Image
|
|||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.aspectRatio
|
import androidx.compose.foundation.layout.aspectRatio
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@ -28,6 +31,9 @@ import com.github.nacabaro.vbhelper.utils.getBitmap
|
|||||||
import androidx.compose.ui.graphics.Shape
|
import androidx.compose.ui.graphics.Shape
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import com.github.cfogrady.vbnfc.vb.SpecialMission
|
||||||
|
import com.github.nacabaro.vbhelper.R
|
||||||
|
import com.github.nacabaro.vbhelper.domain.device_data.SpecialMissions
|
||||||
import com.github.nacabaro.vbhelper.utils.getObscuredBitmap
|
import com.github.nacabaro.vbhelper.utils.getObscuredBitmap
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -114,4 +120,90 @@ fun ItemDisplay(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SpecialMissionsEntry(
|
||||||
|
specialMission: SpecialMissions,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
onClickCard: () -> Unit = { },
|
||||||
|
) {
|
||||||
|
val textValue = when (specialMission.missionType) {
|
||||||
|
SpecialMission.Type.NONE -> "No mission selected"
|
||||||
|
SpecialMission.Type.STEPS -> "Walk ${specialMission.goal} steps"
|
||||||
|
SpecialMission.Type.BATTLES -> "Battle ${specialMission.goal} times"
|
||||||
|
SpecialMission.Type.WINS -> "Win ${specialMission.goal} battles"
|
||||||
|
SpecialMission.Type.VITALS -> "Earn ${specialMission.goal} vitals"
|
||||||
|
}
|
||||||
|
|
||||||
|
val progress = if (specialMission.status == SpecialMission.Status.COMPLETED) {
|
||||||
|
specialMission.goal
|
||||||
|
} else {
|
||||||
|
specialMission.progress
|
||||||
|
}
|
||||||
|
|
||||||
|
val completion = when (specialMission.missionType) {
|
||||||
|
SpecialMission.Type.NONE -> ""
|
||||||
|
SpecialMission.Type.STEPS -> "Walked $progress steps"
|
||||||
|
SpecialMission.Type.BATTLES -> "Battled $progress times"
|
||||||
|
SpecialMission.Type.WINS -> "Won $progress battles"
|
||||||
|
SpecialMission.Type.VITALS -> "Earned $progress vitals"
|
||||||
|
}
|
||||||
|
|
||||||
|
val icon = when (specialMission.missionType) {
|
||||||
|
SpecialMission.Type.NONE -> R.drawable.baseline_free_24
|
||||||
|
SpecialMission.Type.STEPS -> R.drawable.baseline_agility_24
|
||||||
|
SpecialMission.Type.BATTLES -> R.drawable.baseline_swords_24
|
||||||
|
SpecialMission.Type.WINS -> R.drawable.baseline_trophy_24
|
||||||
|
SpecialMission.Type.VITALS -> R.drawable.baseline_vitals_24
|
||||||
|
}
|
||||||
|
|
||||||
|
val color = when (specialMission.status)
|
||||||
|
{
|
||||||
|
SpecialMission.Status.IN_PROGRESS -> MaterialTheme.colorScheme.secondary
|
||||||
|
SpecialMission.Status.COMPLETED -> MaterialTheme.colorScheme.primary
|
||||||
|
SpecialMission.Status.FAILED -> MaterialTheme.colorScheme.error
|
||||||
|
else -> MaterialTheme.colorScheme.surfaceContainerHighest
|
||||||
|
}
|
||||||
|
|
||||||
|
Card(
|
||||||
|
modifier = modifier,
|
||||||
|
shape = androidx.compose.material.MaterialTheme.shapes.small,
|
||||||
|
onClick = if (specialMission.status == SpecialMission.Status.COMPLETED) {
|
||||||
|
onClickCard
|
||||||
|
} else {
|
||||||
|
{ }
|
||||||
|
},
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = color
|
||||||
|
)
|
||||||
|
|
||||||
|
) {
|
||||||
|
Row (
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(16.dp)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(icon),
|
||||||
|
contentDescription = "Vitals",
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxHeight()
|
||||||
|
.padding(16.dp)
|
||||||
|
)
|
||||||
|
Column {
|
||||||
|
Text(
|
||||||
|
text = textValue,
|
||||||
|
fontFamily = MaterialTheme.typography.titleLarge.fontFamily,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = completion,
|
||||||
|
fontFamily = MaterialTheme.typography.titleSmall.fontFamily,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ interface ItemDao {
|
|||||||
WHERE Items.id = :itemId
|
WHERE Items.id = :itemId
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
fun getItem(itemId: Long): ItemDtos.ItemsWithQuantities
|
suspend fun getItem(itemId: Long): ItemDtos.ItemsWithQuantities
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"""
|
"""
|
||||||
@ -40,7 +40,7 @@ interface ItemDao {
|
|||||||
WHERE id = :itemId
|
WHERE id = :itemId
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
fun useItem(itemId: Long)
|
suspend fun useItem(itemId: Long)
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
package com.github.nacabaro.vbhelper.daos
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Query
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface SpecialMissionDao {
|
||||||
|
@Query("""
|
||||||
|
UPDATE SpecialMissions SET
|
||||||
|
missionType = "NONE",
|
||||||
|
status = "UNAVAILABLE"
|
||||||
|
WHERE id = :id
|
||||||
|
""")
|
||||||
|
suspend fun clearSpecialMission(id: Long)
|
||||||
|
}
|
||||||
@ -34,7 +34,7 @@ interface UserCharacterDao {
|
|||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun insertTransformationHistory(vararg transformationHistory: TransformationHistory)
|
fun insertTransformationHistory(vararg transformationHistory: TransformationHistory)
|
||||||
|
|
||||||
@Insert
|
@Upsert
|
||||||
fun insertSpecialMissions(vararg specialMissions: SpecialMissions)
|
fun insertSpecialMissions(vararg specialMissions: SpecialMissions)
|
||||||
|
|
||||||
@Query("""
|
@Query("""
|
||||||
@ -172,4 +172,54 @@ interface UserCharacterDao {
|
|||||||
|
|
||||||
@Query("""SELECT * FROM VitalsHistory WHERE charId = :charId ORDER BY id ASC""")
|
@Query("""SELECT * FROM VitalsHistory WHERE charId = :charId ORDER BY id ASC""")
|
||||||
suspend fun getVitalsHistory(charId: Long): List<VitalsHistory>
|
suspend fun getVitalsHistory(charId: Long): List<VitalsHistory>
|
||||||
|
|
||||||
|
@Query(
|
||||||
|
"""
|
||||||
|
SELECT
|
||||||
|
uc.*,
|
||||||
|
c.stage,
|
||||||
|
c.attribute,
|
||||||
|
s.spriteIdle1 AS spriteIdle,
|
||||||
|
s.spriteIdle2 AS spriteIdle2,
|
||||||
|
s.width AS spriteWidth,
|
||||||
|
s.height AS spriteHeight,
|
||||||
|
c.name as nameSprite,
|
||||||
|
c.nameWidth as nameSpriteWidth,
|
||||||
|
c.nameHeight as nameSpriteHeight,
|
||||||
|
d.isBEm as isBemCard,
|
||||||
|
a.characterId = uc.id as isInAdventure
|
||||||
|
FROM UserCharacter uc
|
||||||
|
JOIN Character c ON uc.charId = c.id
|
||||||
|
JOIN Card d ON d.id = c.dimId
|
||||||
|
JOIN Sprite s ON s.id = c.spriteId
|
||||||
|
LEFT JOIN Adventure a ON a.characterId = uc.id
|
||||||
|
WHERE d.isBEm = 1
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
suspend fun getBEBemCharacters(): List<CharacterDtos.CharacterWithSprites>
|
||||||
|
|
||||||
|
@Query(
|
||||||
|
"""
|
||||||
|
SELECT
|
||||||
|
uc.*,
|
||||||
|
c.stage,
|
||||||
|
c.attribute,
|
||||||
|
s.spriteIdle1 AS spriteIdle,
|
||||||
|
s.spriteIdle2 AS spriteIdle2,
|
||||||
|
s.width AS spriteWidth,
|
||||||
|
s.height AS spriteHeight,
|
||||||
|
c.name as nameSprite,
|
||||||
|
c.nameWidth as nameSpriteWidth,
|
||||||
|
c.nameHeight as nameSpriteHeight,
|
||||||
|
d.isBEm as isBemCard,
|
||||||
|
a.characterId = uc.id as isInAdventure
|
||||||
|
FROM UserCharacter uc
|
||||||
|
JOIN Character c ON uc.charId = c.id
|
||||||
|
JOIN Card d ON d.id = c.dimId
|
||||||
|
JOIN Sprite s ON s.id = c.spriteId
|
||||||
|
LEFT JOIN Adventure a ON a.characterId = uc.id
|
||||||
|
WHERE uc.characterType = "VBDevice"
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
suspend fun getVBDimCharacters(): List<CharacterDtos.CharacterWithSprites>
|
||||||
}
|
}
|
||||||
@ -8,6 +8,7 @@ import com.github.nacabaro.vbhelper.daos.DexDao
|
|||||||
import com.github.nacabaro.vbhelper.daos.CardDao
|
import com.github.nacabaro.vbhelper.daos.CardDao
|
||||||
import com.github.nacabaro.vbhelper.daos.CardProgressDao
|
import com.github.nacabaro.vbhelper.daos.CardProgressDao
|
||||||
import com.github.nacabaro.vbhelper.daos.ItemDao
|
import com.github.nacabaro.vbhelper.daos.ItemDao
|
||||||
|
import com.github.nacabaro.vbhelper.daos.SpecialMissionDao
|
||||||
import com.github.nacabaro.vbhelper.daos.SpriteDao
|
import com.github.nacabaro.vbhelper.daos.SpriteDao
|
||||||
import com.github.nacabaro.vbhelper.daos.UserCharacterDao
|
import com.github.nacabaro.vbhelper.daos.UserCharacterDao
|
||||||
import com.github.nacabaro.vbhelper.domain.characters.Character
|
import com.github.nacabaro.vbhelper.domain.characters.Character
|
||||||
@ -51,4 +52,5 @@ abstract class AppDatabase : RoomDatabase() {
|
|||||||
abstract fun itemDao(): ItemDao
|
abstract fun itemDao(): ItemDao
|
||||||
abstract fun adventureDao(): AdventureDao
|
abstract fun adventureDao(): AdventureDao
|
||||||
abstract fun spriteDao(): SpriteDao
|
abstract fun spriteDao(): SpriteDao
|
||||||
|
abstract fun specialMissionDao(): SpecialMissionDao
|
||||||
}
|
}
|
||||||
@ -3,6 +3,13 @@ package com.github.nacabaro.vbhelper.domain.items
|
|||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
enum class ItemType {
|
||||||
|
VBITEM,
|
||||||
|
BEITEM,
|
||||||
|
UNIVERSAL,
|
||||||
|
SPECIALMISSION
|
||||||
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
data class Items(
|
data class Items(
|
||||||
@PrimaryKey val id: Long,
|
@PrimaryKey val id: Long,
|
||||||
@ -11,5 +18,6 @@ data class Items(
|
|||||||
val itemIcon: Int,
|
val itemIcon: Int,
|
||||||
val itemLength: Int,
|
val itemLength: Int,
|
||||||
val price: Int,
|
val price: Int,
|
||||||
val quantity: Int
|
val quantity: Int,
|
||||||
|
val itemType: ItemType
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package com.github.nacabaro.vbhelper.dtos
|
package com.github.nacabaro.vbhelper.dtos
|
||||||
|
|
||||||
|
import com.github.nacabaro.vbhelper.domain.items.ItemType
|
||||||
|
|
||||||
|
|
||||||
object ItemDtos {
|
object ItemDtos {
|
||||||
data class ItemsWithQuantities(
|
data class ItemsWithQuantities(
|
||||||
@ -10,6 +12,7 @@ object ItemDtos {
|
|||||||
val itemLength: Int,
|
val itemLength: Int,
|
||||||
val price: Int,
|
val price: Int,
|
||||||
val quantity: Int,
|
val quantity: Int,
|
||||||
|
val itemType: ItemType
|
||||||
)
|
)
|
||||||
|
|
||||||
data class PurchasedItem(
|
data class PurchasedItem(
|
||||||
@ -18,6 +21,7 @@ object ItemDtos {
|
|||||||
val itemDescription: String,
|
val itemDescription: String,
|
||||||
val itemIcon: Int,
|
val itemIcon: Int,
|
||||||
val itemLength: Int,
|
val itemLength: Int,
|
||||||
val itemAmount: Int
|
val itemAmount: Int,
|
||||||
|
val itemType: ItemType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -94,7 +94,8 @@ class AdventureScreenControllerImpl(
|
|||||||
itemName = randomItem.name,
|
itemName = randomItem.name,
|
||||||
itemIcon = randomItem.itemIcon,
|
itemIcon = randomItem.itemIcon,
|
||||||
itemLength = randomItem.itemLength,
|
itemLength = randomItem.itemLength,
|
||||||
itemDescription = randomItem.description
|
itemDescription = randomItem.description,
|
||||||
|
itemType = randomItem.itemType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -28,9 +28,15 @@ import com.github.nacabaro.vbhelper.components.TopBanner
|
|||||||
import com.github.nacabaro.vbhelper.di.VBHelper
|
import com.github.nacabaro.vbhelper.di.VBHelper
|
||||||
import com.github.nacabaro.vbhelper.utils.DeviceType
|
import com.github.nacabaro.vbhelper.utils.DeviceType
|
||||||
import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData
|
import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData
|
||||||
|
import com.github.nacabaro.vbhelper.domain.device_data.SpecialMissions
|
||||||
import com.github.nacabaro.vbhelper.domain.device_data.VBCharacterData
|
import com.github.nacabaro.vbhelper.domain.device_data.VBCharacterData
|
||||||
import com.github.nacabaro.vbhelper.dtos.CharacterDtos
|
import com.github.nacabaro.vbhelper.dtos.CharacterDtos
|
||||||
|
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||||
import com.github.nacabaro.vbhelper.navigation.NavigationItems
|
import com.github.nacabaro.vbhelper.navigation.NavigationItems
|
||||||
|
import com.github.nacabaro.vbhelper.screens.homeScreens.screens.BEBEmHomeScreen
|
||||||
|
import com.github.nacabaro.vbhelper.screens.homeScreens.screens.BEDiMHomeScreen
|
||||||
|
import com.github.nacabaro.vbhelper.screens.homeScreens.screens.VBDiMHomeScreen
|
||||||
|
import com.github.nacabaro.vbhelper.screens.itemsScreen.ObtainedItemDialog
|
||||||
import com.github.nacabaro.vbhelper.source.StorageRepository
|
import com.github.nacabaro.vbhelper.source.StorageRepository
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@ -46,10 +52,12 @@ fun HomeScreen(
|
|||||||
val transformationHistory = remember { mutableStateOf<List<CharacterDtos.TransformationHistory>?>(null) }
|
val transformationHistory = remember { mutableStateOf<List<CharacterDtos.TransformationHistory>?>(null) }
|
||||||
val beData = remember { mutableStateOf<BECharacterData?>(null) }
|
val beData = remember { mutableStateOf<BECharacterData?>(null) }
|
||||||
val vbData = remember { mutableStateOf<VBCharacterData?>(null) }
|
val vbData = remember { mutableStateOf<VBCharacterData?>(null) }
|
||||||
|
val vbSpecialMissions = remember { mutableStateOf<List<SpecialMissions>>(emptyList()) }
|
||||||
var adventureMissionsFinished by rememberSaveable { mutableStateOf(false) }
|
var adventureMissionsFinished by rememberSaveable { mutableStateOf(false) }
|
||||||
var betaWarning by rememberSaveable { mutableStateOf(true) }
|
var betaWarning by rememberSaveable { mutableStateOf(true) }
|
||||||
|
var collectedItem by remember { mutableStateOf<ItemDtos.PurchasedItem?>(null) }
|
||||||
|
|
||||||
LaunchedEffect(storageRepository, activeMon) {
|
LaunchedEffect(storageRepository, activeMon, collectedItem) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
activeMon.value = storageRepository.getActiveCharacter()
|
activeMon.value = storageRepository.getActiveCharacter()
|
||||||
if (activeMon.value != null && activeMon.value!!.characterType == DeviceType.BEDevice) {
|
if (activeMon.value != null && activeMon.value!!.characterType == DeviceType.BEDevice) {
|
||||||
@ -57,6 +65,7 @@ fun HomeScreen(
|
|||||||
transformationHistory.value = storageRepository.getTransformationHistory(activeMon.value!!.id)
|
transformationHistory.value = storageRepository.getTransformationHistory(activeMon.value!!.id)
|
||||||
} else if (activeMon.value != null && activeMon.value!!.characterType == DeviceType.VBDevice) {
|
} else if (activeMon.value != null && activeMon.value!!.characterType == DeviceType.VBDevice) {
|
||||||
vbData.value = storageRepository.getCharacterVbData(activeMon.value!!.id)
|
vbData.value = storageRepository.getCharacterVbData(activeMon.value!!.id)
|
||||||
|
vbSpecialMissions.value = storageRepository.getSpecialMissions(activeMon.value!!.id)
|
||||||
transformationHistory.value = storageRepository.getTransformationHistory(activeMon.value!!.id)
|
transformationHistory.value = storageRepository.getTransformationHistory(activeMon.value!!.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,12 +123,26 @@ fun HomeScreen(
|
|||||||
activeMon = activeMon.value!!,
|
activeMon = activeMon.value!!,
|
||||||
vbData = vbData.value!!,
|
vbData = vbData.value!!,
|
||||||
transformationHistory = transformationHistory.value!!,
|
transformationHistory = transformationHistory.value!!,
|
||||||
contentPadding = contentPadding
|
contentPadding = contentPadding,
|
||||||
|
specialMissions = vbSpecialMissions.value,
|
||||||
|
homeScreenController = homeScreenController,
|
||||||
|
onClickCollect = { item ->
|
||||||
|
collectedItem = item
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (collectedItem != null) {
|
||||||
|
ObtainedItemDialog(
|
||||||
|
obtainedItem = collectedItem!!,
|
||||||
|
onClickDismiss = {
|
||||||
|
collectedItem = null
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (adventureMissionsFinished) {
|
if (adventureMissionsFinished) {
|
||||||
Dialog(
|
Dialog(
|
||||||
onDismissRequest = { adventureMissionsFinished = false },
|
onDismissRequest = { adventureMissionsFinished = false },
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
package com.github.nacabaro.vbhelper.screens.homeScreens
|
package com.github.nacabaro.vbhelper.screens.homeScreens
|
||||||
|
|
||||||
|
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||||
|
|
||||||
interface HomeScreenController {
|
interface HomeScreenController {
|
||||||
fun didAdventureMissionsFinish(onCompletion: (Boolean) -> Unit)
|
fun didAdventureMissionsFinish(onCompletion: (Boolean) -> Unit)
|
||||||
|
fun clearSpecialMission(missionId: Long, onCleared: (ItemDtos.PurchasedItem) -> Unit)
|
||||||
}
|
}
|
||||||
@ -3,8 +3,11 @@ package com.github.nacabaro.vbhelper.screens.homeScreens
|
|||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.github.nacabaro.vbhelper.di.VBHelper
|
import com.github.nacabaro.vbhelper.di.VBHelper
|
||||||
|
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
class HomeScreenControllerImpl(
|
class HomeScreenControllerImpl(
|
||||||
private val componentActivity: ComponentActivity,
|
private val componentActivity: ComponentActivity,
|
||||||
@ -26,4 +29,38 @@ class HomeScreenControllerImpl(
|
|||||||
onCompletion(finishedAdventureCharacters.isNotEmpty())
|
onCompletion(finishedAdventureCharacters.isNotEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun clearSpecialMission(missionId: Long, onCleared: (ItemDtos.PurchasedItem) -> Unit) {
|
||||||
|
componentActivity.lifecycleScope.launch {
|
||||||
|
database
|
||||||
|
.specialMissionDao()
|
||||||
|
.clearSpecialMission(missionId)
|
||||||
|
|
||||||
|
val randomItem = database
|
||||||
|
.itemDao()
|
||||||
|
.getAllItems()
|
||||||
|
.random()
|
||||||
|
|
||||||
|
val randomItemAmount = (Random.nextFloat() * 5).roundToInt()
|
||||||
|
|
||||||
|
database
|
||||||
|
.itemDao()
|
||||||
|
.purchaseItem(
|
||||||
|
itemId = randomItem.id,
|
||||||
|
itemAmount = randomItemAmount
|
||||||
|
)
|
||||||
|
|
||||||
|
val purchasedItem = ItemDtos.PurchasedItem(
|
||||||
|
itemId = randomItem.id,
|
||||||
|
itemName = randomItem.name,
|
||||||
|
itemDescription = randomItem.description,
|
||||||
|
itemIcon = randomItem.itemIcon,
|
||||||
|
itemLength = randomItem.itemLength,
|
||||||
|
itemAmount = randomItemAmount,
|
||||||
|
itemType = randomItem.itemType
|
||||||
|
)
|
||||||
|
|
||||||
|
onCleared(purchasedItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.github.nacabaro.vbhelper.screens.homeScreens
|
package com.github.nacabaro.vbhelper.screens.homeScreens.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.github.nacabaro.vbhelper.screens.homeScreens
|
package com.github.nacabaro.vbhelper.screens.homeScreens.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.github.nacabaro.vbhelper.screens.homeScreens
|
package com.github.nacabaro.vbhelper.screens.homeScreens.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
@ -8,15 +8,21 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
import com.github.nacabaro.vbhelper.R
|
import com.github.nacabaro.vbhelper.R
|
||||||
import com.github.nacabaro.vbhelper.components.CharacterEntry
|
import com.github.nacabaro.vbhelper.components.CharacterEntry
|
||||||
import com.github.nacabaro.vbhelper.components.ItemDisplay
|
import com.github.nacabaro.vbhelper.components.ItemDisplay
|
||||||
|
import com.github.nacabaro.vbhelper.components.SpecialMissionsEntry
|
||||||
import com.github.nacabaro.vbhelper.components.TransformationHistoryCard
|
import com.github.nacabaro.vbhelper.components.TransformationHistoryCard
|
||||||
|
import com.github.nacabaro.vbhelper.domain.device_data.SpecialMissions
|
||||||
import com.github.nacabaro.vbhelper.domain.device_data.VBCharacterData
|
import com.github.nacabaro.vbhelper.domain.device_data.VBCharacterData
|
||||||
import com.github.nacabaro.vbhelper.dtos.CharacterDtos
|
import com.github.nacabaro.vbhelper.dtos.CharacterDtos
|
||||||
|
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||||
|
import com.github.nacabaro.vbhelper.screens.homeScreens.HomeScreenControllerImpl
|
||||||
import com.github.nacabaro.vbhelper.utils.BitmapData
|
import com.github.nacabaro.vbhelper.utils.BitmapData
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
@ -24,8 +30,11 @@ import java.util.Locale
|
|||||||
fun VBDiMHomeScreen(
|
fun VBDiMHomeScreen(
|
||||||
activeMon: CharacterDtos.CharacterWithSprites,
|
activeMon: CharacterDtos.CharacterWithSprites,
|
||||||
vbData: VBCharacterData,
|
vbData: VBCharacterData,
|
||||||
|
specialMissions: List<SpecialMissions>,
|
||||||
|
homeScreenController: HomeScreenControllerImpl,
|
||||||
transformationHistory: List<CharacterDtos.TransformationHistory>,
|
transformationHistory: List<CharacterDtos.TransformationHistory>,
|
||||||
contentPadding: PaddingValues
|
contentPadding: PaddingValues,
|
||||||
|
onClickCollect: (ItemDtos.PurchasedItem) -> Unit
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -151,5 +160,30 @@ fun VBDiMHomeScreen(
|
|||||||
.padding(8.dp)
|
.padding(8.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Row (
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(16.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "Special missions",
|
||||||
|
fontSize = 24.sp
|
||||||
|
)
|
||||||
|
}
|
||||||
|
for (mission in specialMissions) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
SpecialMissionsEntry(
|
||||||
|
specialMission = mission,
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.padding(8.dp),
|
||||||
|
) {
|
||||||
|
homeScreenController
|
||||||
|
.clearSpecialMission(mission.id, onClickCollect)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -19,7 +19,9 @@ import androidx.navigation.NavController
|
|||||||
import com.github.nacabaro.vbhelper.components.CharacterEntry
|
import com.github.nacabaro.vbhelper.components.CharacterEntry
|
||||||
import com.github.nacabaro.vbhelper.components.TopBanner
|
import com.github.nacabaro.vbhelper.components.TopBanner
|
||||||
import com.github.nacabaro.vbhelper.di.VBHelper
|
import com.github.nacabaro.vbhelper.di.VBHelper
|
||||||
|
import com.github.nacabaro.vbhelper.domain.items.ItemType
|
||||||
import com.github.nacabaro.vbhelper.dtos.CharacterDtos
|
import com.github.nacabaro.vbhelper.dtos.CharacterDtos
|
||||||
|
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||||
import com.github.nacabaro.vbhelper.source.StorageRepository
|
import com.github.nacabaro.vbhelper.source.StorageRepository
|
||||||
import com.github.nacabaro.vbhelper.utils.BitmapData
|
import com.github.nacabaro.vbhelper.utils.BitmapData
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -39,10 +41,25 @@ fun ChooseCharacterScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var selectedCharacter by remember { mutableStateOf<Long?>(null) }
|
var selectedCharacter by remember { mutableStateOf<Long?>(null) }
|
||||||
|
var selectedItem by remember { mutableStateOf<ItemDtos.ItemsWithQuantities?>(null) }
|
||||||
|
|
||||||
LaunchedEffect(storageRepository) {
|
LaunchedEffect(storageRepository) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
characterList.value = storageRepository.getAllCharacters()
|
selectedItem = storageRepository.getItem(itemId)
|
||||||
|
when (selectedItem?.itemType) {
|
||||||
|
ItemType.BEITEM -> {
|
||||||
|
characterList.value = storageRepository.getBEBEmCharacters()
|
||||||
|
}
|
||||||
|
ItemType.VBITEM -> {
|
||||||
|
characterList.value = storageRepository.getVBCharacters()
|
||||||
|
}
|
||||||
|
ItemType.SPECIALMISSION-> {
|
||||||
|
characterList.value = storageRepository.getVBCharacters()
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
characterList.value = storageRepository.getAllCharacters()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,9 +2,12 @@ package com.github.nacabaro.vbhelper.screens.itemsScreen
|
|||||||
|
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import com.github.cfogrady.vbnfc.vb.SpecialMission
|
||||||
|
import com.github.nacabaro.vbhelper.domain.device_data.SpecialMissions
|
||||||
import com.github.nacabaro.vbhelper.database.AppDatabase
|
import com.github.nacabaro.vbhelper.database.AppDatabase
|
||||||
import com.github.nacabaro.vbhelper.di.VBHelper
|
import com.github.nacabaro.vbhelper.di.VBHelper
|
||||||
import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData
|
import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData
|
||||||
|
import com.github.nacabaro.vbhelper.domain.device_data.VBCharacterData
|
||||||
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||||
import com.github.nacabaro.vbhelper.utils.DeviceType
|
import com.github.nacabaro.vbhelper.utils.DeviceType
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -24,7 +27,15 @@ class ItemsScreenControllerImpl (
|
|||||||
AllTraining(5),
|
AllTraining(5),
|
||||||
EvoTimer(6),
|
EvoTimer(6),
|
||||||
LimitTimer(7),
|
LimitTimer(7),
|
||||||
Vitals(8)
|
Vitals(8),
|
||||||
|
Step8k(9),
|
||||||
|
Step4k(10),
|
||||||
|
Vitals1000(11),
|
||||||
|
Vitals250(12),
|
||||||
|
Battle20(13),
|
||||||
|
Battle5(14),
|
||||||
|
Win10(15),
|
||||||
|
Win4(16)
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -37,17 +48,20 @@ class ItemsScreenControllerImpl (
|
|||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val item = getItem(itemId)
|
val item = getItem(itemId)
|
||||||
val characterData = database.userCharacterDao().getCharacter(characterId)
|
val characterData = database.userCharacterDao().getCharacter(characterId)
|
||||||
val beCharacterData: BECharacterData
|
var beCharacterData: BECharacterData? = null
|
||||||
//var vbCharacterData: VBCharacterData
|
var vbCharacterData: VBCharacterData? = null
|
||||||
|
|
||||||
if (characterData.characterType == DeviceType.BEDevice) {
|
if (characterData.characterType == DeviceType.BEDevice) {
|
||||||
beCharacterData = database.userCharacterDao().getBeData(characterId)
|
beCharacterData = database.userCharacterDao().getBeData(characterId)
|
||||||
} else {
|
} else if (characterData.characterType == DeviceType.VBDevice) {
|
||||||
TODO("Not implemented")
|
vbCharacterData = database.userCharacterDao().getVbData(characterId)
|
||||||
//vbCharacterData = database.userCharacterDao().getVbData(characterId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.itemIcon in 1 .. 5 && characterData.characterType == DeviceType.BEDevice) {
|
if (
|
||||||
|
item.itemIcon in 1 .. 5 &&
|
||||||
|
characterData.characterType == DeviceType.BEDevice &&
|
||||||
|
beCharacterData != null
|
||||||
|
) {
|
||||||
beCharacterData.itemType = item.itemIcon
|
beCharacterData.itemType = item.itemIcon
|
||||||
beCharacterData.itemMultiplier = 3
|
beCharacterData.itemMultiplier = 3
|
||||||
beCharacterData.itemRemainingTime = item.itemLength
|
beCharacterData.itemRemainingTime = item.itemLength
|
||||||
@ -72,7 +86,11 @@ class ItemsScreenControllerImpl (
|
|||||||
.userCharacterDao()
|
.userCharacterDao()
|
||||||
.updateCharacter(characterData)
|
.updateCharacter(characterData)
|
||||||
|
|
||||||
} else if (item.itemIcon == ItemTypes.LimitTimer.id) {
|
} else if (
|
||||||
|
item.itemIcon == ItemTypes.LimitTimer.id &&
|
||||||
|
characterData.characterType == DeviceType.BEDevice &&
|
||||||
|
beCharacterData != null
|
||||||
|
) {
|
||||||
beCharacterData.remainingTrainingTimeInMinutes += item.itemLength
|
beCharacterData.remainingTrainingTimeInMinutes += item.itemLength
|
||||||
if (beCharacterData.remainingTrainingTimeInMinutes > 6000) {
|
if (beCharacterData.remainingTrainingTimeInMinutes > 6000) {
|
||||||
beCharacterData.remainingTrainingTimeInMinutes = 6000
|
beCharacterData.remainingTrainingTimeInMinutes = 6000
|
||||||
@ -93,6 +111,12 @@ class ItemsScreenControllerImpl (
|
|||||||
database
|
database
|
||||||
.userCharacterDao()
|
.userCharacterDao()
|
||||||
.updateCharacter(characterData)
|
.updateCharacter(characterData)
|
||||||
|
|
||||||
|
} else if (item.itemIcon in ItemTypes.Step8k.id .. ItemTypes.Win4.id &&
|
||||||
|
characterData.characterType == DeviceType.VBDevice &&
|
||||||
|
vbCharacterData != null
|
||||||
|
) {
|
||||||
|
applySpecialMission(item.itemIcon, item.itemLength, characterId)
|
||||||
}
|
}
|
||||||
|
|
||||||
consumeItem(item.id)
|
consumeItem(item.id)
|
||||||
@ -104,13 +128,72 @@ class ItemsScreenControllerImpl (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getItem(itemId: Long): ItemDtos.ItemsWithQuantities {
|
private suspend fun applySpecialMission(itemIcon: Int, itemLength: Int, characterId: Long) {
|
||||||
|
// Hello, it's me, naca! No! I don't like this, I'll see how I can improve it later on...
|
||||||
|
val specialMissionType = when (itemIcon) {
|
||||||
|
ItemTypes.Step8k.id -> SpecialMission.Type.STEPS
|
||||||
|
ItemTypes.Step4k.id -> SpecialMission.Type.STEPS
|
||||||
|
ItemTypes.Vitals1000.id -> SpecialMission.Type.VITALS
|
||||||
|
ItemTypes.Vitals250.id -> SpecialMission.Type.VITALS
|
||||||
|
ItemTypes.Battle20.id -> SpecialMission.Type.BATTLES
|
||||||
|
ItemTypes.Battle5.id -> SpecialMission.Type.BATTLES
|
||||||
|
ItemTypes.Win10.id -> SpecialMission.Type.WINS
|
||||||
|
ItemTypes.Win4.id -> SpecialMission.Type.WINS
|
||||||
|
else -> SpecialMission.Type.NONE
|
||||||
|
}
|
||||||
|
|
||||||
|
val specialMissionGoal = when (itemIcon) {
|
||||||
|
ItemTypes.Step8k.id -> 8000
|
||||||
|
ItemTypes.Step4k.id -> 4000
|
||||||
|
ItemTypes.Vitals1000.id -> 1000
|
||||||
|
ItemTypes.Vitals250.id -> 250
|
||||||
|
ItemTypes.Battle20.id -> 20
|
||||||
|
ItemTypes.Battle5.id -> 5
|
||||||
|
ItemTypes.Win10.id -> 10
|
||||||
|
ItemTypes.Win4.id -> 4
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
|
||||||
|
val availableSpecialMissions = database
|
||||||
|
.userCharacterDao()
|
||||||
|
.getSpecialMissions(characterId)
|
||||||
|
|
||||||
|
var firstUnavailableMissionSlot: Long = 0
|
||||||
|
var watchId = 0
|
||||||
|
|
||||||
|
for ((index, mission) in availableSpecialMissions.withIndex()) {
|
||||||
|
if (
|
||||||
|
mission.status == SpecialMission.Status.UNAVAILABLE
|
||||||
|
) {
|
||||||
|
firstUnavailableMissionSlot = mission.id
|
||||||
|
watchId = index + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val newSpecialMission = SpecialMissions(
|
||||||
|
id = firstUnavailableMissionSlot,
|
||||||
|
characterId = characterId,
|
||||||
|
missionType = specialMissionType,
|
||||||
|
goal = specialMissionGoal,
|
||||||
|
timeLimitInMinutes = itemLength,
|
||||||
|
watchId = watchId,
|
||||||
|
status = SpecialMission.Status.AVAILABLE,
|
||||||
|
progress = 0,
|
||||||
|
timeElapsedInMinutes = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
database
|
||||||
|
.userCharacterDao()
|
||||||
|
.insertSpecialMissions(newSpecialMission)
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun getItem(itemId: Long): ItemDtos.ItemsWithQuantities {
|
||||||
return database
|
return database
|
||||||
.itemDao()
|
.itemDao()
|
||||||
.getItem(itemId)
|
.getItem(itemId)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun consumeItem(itemId: Long) {
|
private suspend fun consumeItem(itemId: Long) {
|
||||||
database
|
database
|
||||||
.itemDao()
|
.itemDao()
|
||||||
.useItem(itemId)
|
.useItem(itemId)
|
||||||
|
|||||||
@ -2,8 +2,10 @@ package com.github.nacabaro.vbhelper.source
|
|||||||
|
|
||||||
import com.github.nacabaro.vbhelper.database.AppDatabase
|
import com.github.nacabaro.vbhelper.database.AppDatabase
|
||||||
import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData
|
import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData
|
||||||
|
import com.github.nacabaro.vbhelper.domain.device_data.SpecialMissions
|
||||||
import com.github.nacabaro.vbhelper.domain.device_data.VBCharacterData
|
import com.github.nacabaro.vbhelper.domain.device_data.VBCharacterData
|
||||||
import com.github.nacabaro.vbhelper.dtos.CharacterDtos
|
import com.github.nacabaro.vbhelper.dtos.CharacterDtos
|
||||||
|
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||||
|
|
||||||
class StorageRepository (
|
class StorageRepository (
|
||||||
private val db: AppDatabase
|
private val db: AppDatabase
|
||||||
@ -28,6 +30,14 @@ class StorageRepository (
|
|||||||
return db.userCharacterDao().getVbData(id)
|
return db.userCharacterDao().getVbData(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getSpecialMissions(id: Long): List<SpecialMissions> {
|
||||||
|
return db.userCharacterDao().getSpecialMissions(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getItem(id: Long): ItemDtos.ItemsWithQuantities {
|
||||||
|
return db.itemDao().getItem(id)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun getActiveCharacter(): CharacterDtos.CharacterWithSprites? {
|
suspend fun getActiveCharacter(): CharacterDtos.CharacterWithSprites? {
|
||||||
return db.userCharacterDao().getActiveCharacter()
|
return db.userCharacterDao().getActiveCharacter()
|
||||||
}
|
}
|
||||||
@ -39,4 +49,12 @@ class StorageRepository (
|
|||||||
suspend fun getAdventureCharacters(): List<CharacterDtos.AdventureCharacterWithSprites> {
|
suspend fun getAdventureCharacters(): List<CharacterDtos.AdventureCharacterWithSprites> {
|
||||||
return db.adventureDao().getAdventureCharacters()
|
return db.adventureDao().getAdventureCharacters()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getBEBEmCharacters(): List<CharacterDtos.CharacterWithSprites> {
|
||||||
|
return db.userCharacterDao().getBEBemCharacters()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getVBCharacters(): List<CharacterDtos.CharacterWithSprites> {
|
||||||
|
return db.userCharacterDao().getVBDimCharacters()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user