Renaming terms and other bits and bobs

- Changed adventure database so that the original intended time is also stored with the final time. This will come useful once the algorithm for determining which object to give is made.
This commit is contained in:
Nacho 2025-01-26 01:40:32 +01:00
parent 409474b5d1
commit e17f6c23e4
7 changed files with 54 additions and 31 deletions

View File

@ -8,10 +8,10 @@ import com.github.nacabaro.vbhelper.dtos.CharacterDtos
@Dao
interface AdventureDao {
@Query("""
INSERT INTO Adventure (characterId, finishesAdventure)
VALUES (:characterId, strftime('%s', 'now') + :timeInSeconds)
INSERT INTO Adventure (characterId, originalDuration, finishesAdventure)
VALUES (:characterId, :originalDuration, strftime('%s', 'now') + :timeInSeconds)
""")
fun insertNewAdventure(characterId: Long, timeInSeconds: Long)
fun insertNewAdventure(characterId: Long, originalDuration: Long, timeInSeconds: Long)
@Query("""
SELECT COUNT(*) FROM Adventure
@ -25,7 +25,8 @@ interface AdventureDao {
c.spritesWidth AS spriteWidth,
c.spritesHeight AS spriteHeight,
d.isBEm as isBemCard,
a.finishesAdventure AS timeLeft
a.finishesAdventure AS finishesAdventure,
a.originalDuration AS originalTimeInMinutes
FROM UserCharacter uc
JOIN Character c ON uc.charId = c.id
JOIN Card d ON c.dimId = d.id

View File

@ -17,5 +17,6 @@ import com.github.nacabaro.vbhelper.domain.device_data.UserCharacter
)
data class Adventure(
@PrimaryKey val characterId: Long,
val originalDuration: Long,
val finishesAdventure: Long
)

View File

@ -79,6 +79,7 @@ object CharacterDtos {
val spriteWidth: Int,
val spriteHeight: Int,
val isBemCard: Boolean,
val timeLeft: Long
val finishesAdventure: Long,
val originalTimeInMinutes: Long
)
}

View File

@ -1,9 +1,13 @@
package com.github.nacabaro.vbhelper.screens.adventureScreen
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
@ -12,6 +16,7 @@ import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.NavController
@ -71,29 +76,41 @@ fun AdventureScreen(
)
}
) { contentPadding ->
LazyColumn(
modifier = Modifier
.padding(top = contentPadding.calculateTopPadding())
) {
items(characterList.value) {
AdventureEntry(
icon = BitmapData(
bitmap = it.spriteIdle,
width = it.spriteWidth,
height = it.spriteHeight
),
timeLeft = it.timeLeft - currentTime,
onClick = {
if (it.timeLeft < currentTime) {
storageScreenController
.getItemFromAdventure(it.id) { adventureResult ->
obtainedItem = adventureResult
}
} else {
cancelAdventureDialog = it
if (characterList.value.isEmpty()) {
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.padding(top = contentPadding.calculateTopPadding())
.fillMaxSize()
) {
Text(text = "Nothing to see here")
}
} else {
LazyColumn(
modifier = Modifier
.padding(top = contentPadding.calculateTopPadding())
) {
items(characterList.value) {
AdventureEntry(
icon = BitmapData(
bitmap = it.spriteIdle,
width = it.spriteWidth,
height = it.spriteHeight
),
timeLeft = it.finishesAdventure - currentTime,
onClick = {
if (it.finishesAdventure < currentTime) {
storageScreenController
.getItemFromAdventure(it.id) { adventureResult ->
obtainedItem = adventureResult
}
} else {
cancelAdventureDialog = it
}
}
}
)
)
}
}
}
}

View File

@ -17,7 +17,7 @@ class AdventureScreenControllerImpl(
private val database = application.container.db
override fun sendCharacterToAdventure(characterId: Long, timeInMinutes: Long) {
val timeInSeconds = timeInMinutes * 60
val finishesAdventureAt = timeInMinutes * 60
componentActivity.lifecycleScope.launch(Dispatchers.IO) {
val characterData = database
.userCharacterDao()
@ -31,7 +31,7 @@ class AdventureScreenControllerImpl(
database
.adventureDao()
.insertNewAdventure(characterId, timeInSeconds)
.insertNewAdventure(characterId, timeInMinutes, finishesAdventureAt)
}
}

View File

@ -20,7 +20,7 @@ class HomeScreenControllerImpl(
.getAdventureCharacters()
val finishedAdventureCharacters = adventureCharacters.filter { character ->
character.timeLeft <= currentTime
character.finishesAdventure <= currentTime
}
onCompletion(finishedAdventureCharacters.isNotEmpty())

View File

@ -4,6 +4,7 @@ import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.lifecycle.lifecycleScope
import com.github.nacabaro.vbhelper.di.VBHelper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class StorageScreenControllerImpl(
@ -13,8 +14,10 @@ class StorageScreenControllerImpl(
private val database = application.container.db
override fun setActive(characterId: Long, onCompletion: () -> Unit) {
componentActivity.lifecycleScope.launch {
componentActivity.lifecycleScope.launch(Dispatchers.IO) {
database.userCharacterDao().clearActiveCharacter()
database.userCharacterDao().setActiveCharacter(characterId)
componentActivity.runOnUiThread {
Toast.makeText(
componentActivity,