mirror of
https://github.com/nacabaro/vbhelper.git
synced 2026-01-28 00:15:32 +00:00
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:
parent
409474b5d1
commit
e17f6c23e4
@ -8,10 +8,10 @@ import com.github.nacabaro.vbhelper.dtos.CharacterDtos
|
|||||||
@Dao
|
@Dao
|
||||||
interface AdventureDao {
|
interface AdventureDao {
|
||||||
@Query("""
|
@Query("""
|
||||||
INSERT INTO Adventure (characterId, finishesAdventure)
|
INSERT INTO Adventure (characterId, originalDuration, finishesAdventure)
|
||||||
VALUES (:characterId, strftime('%s', 'now') + :timeInSeconds)
|
VALUES (:characterId, :originalDuration, strftime('%s', 'now') + :timeInSeconds)
|
||||||
""")
|
""")
|
||||||
fun insertNewAdventure(characterId: Long, timeInSeconds: Long)
|
fun insertNewAdventure(characterId: Long, originalDuration: Long, timeInSeconds: Long)
|
||||||
|
|
||||||
@Query("""
|
@Query("""
|
||||||
SELECT COUNT(*) FROM Adventure
|
SELECT COUNT(*) FROM Adventure
|
||||||
@ -25,7 +25,8 @@ interface AdventureDao {
|
|||||||
c.spritesWidth AS spriteWidth,
|
c.spritesWidth AS spriteWidth,
|
||||||
c.spritesHeight AS spriteHeight,
|
c.spritesHeight AS spriteHeight,
|
||||||
d.isBEm as isBemCard,
|
d.isBEm as isBemCard,
|
||||||
a.finishesAdventure AS timeLeft
|
a.finishesAdventure AS finishesAdventure,
|
||||||
|
a.originalDuration AS originalTimeInMinutes
|
||||||
FROM UserCharacter uc
|
FROM UserCharacter uc
|
||||||
JOIN Character c ON uc.charId = c.id
|
JOIN Character c ON uc.charId = c.id
|
||||||
JOIN Card d ON c.dimId = d.id
|
JOIN Card d ON c.dimId = d.id
|
||||||
|
|||||||
@ -17,5 +17,6 @@ import com.github.nacabaro.vbhelper.domain.device_data.UserCharacter
|
|||||||
)
|
)
|
||||||
data class Adventure(
|
data class Adventure(
|
||||||
@PrimaryKey val characterId: Long,
|
@PrimaryKey val characterId: Long,
|
||||||
|
val originalDuration: Long,
|
||||||
val finishesAdventure: Long
|
val finishesAdventure: Long
|
||||||
)
|
)
|
||||||
|
|||||||
@ -79,6 +79,7 @@ object CharacterDtos {
|
|||||||
val spriteWidth: Int,
|
val spriteWidth: Int,
|
||||||
val spriteHeight: Int,
|
val spriteHeight: Int,
|
||||||
val isBemCard: Boolean,
|
val isBemCard: Boolean,
|
||||||
val timeLeft: Long
|
val finishesAdventure: Long,
|
||||||
|
val originalTimeInMinutes: Long
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -1,9 +1,13 @@
|
|||||||
package com.github.nacabaro.vbhelper.screens.adventureScreen
|
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.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
@ -12,6 +16,7 @@ import androidx.compose.runtime.produceState
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
@ -71,6 +76,17 @@ fun AdventureScreen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
) { contentPadding ->
|
) { contentPadding ->
|
||||||
|
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(
|
LazyColumn(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(top = contentPadding.calculateTopPadding())
|
.padding(top = contentPadding.calculateTopPadding())
|
||||||
@ -82,9 +98,9 @@ fun AdventureScreen(
|
|||||||
width = it.spriteWidth,
|
width = it.spriteWidth,
|
||||||
height = it.spriteHeight
|
height = it.spriteHeight
|
||||||
),
|
),
|
||||||
timeLeft = it.timeLeft - currentTime,
|
timeLeft = it.finishesAdventure - currentTime,
|
||||||
onClick = {
|
onClick = {
|
||||||
if (it.timeLeft < currentTime) {
|
if (it.finishesAdventure < currentTime) {
|
||||||
storageScreenController
|
storageScreenController
|
||||||
.getItemFromAdventure(it.id) { adventureResult ->
|
.getItemFromAdventure(it.id) { adventureResult ->
|
||||||
obtainedItem = adventureResult
|
obtainedItem = adventureResult
|
||||||
@ -97,6 +113,7 @@ fun AdventureScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (obtainedItem != null) {
|
if (obtainedItem != null) {
|
||||||
ObtainedItemDialog(
|
ObtainedItemDialog(
|
||||||
|
|||||||
@ -17,7 +17,7 @@ class AdventureScreenControllerImpl(
|
|||||||
private val database = application.container.db
|
private val database = application.container.db
|
||||||
|
|
||||||
override fun sendCharacterToAdventure(characterId: Long, timeInMinutes: Long) {
|
override fun sendCharacterToAdventure(characterId: Long, timeInMinutes: Long) {
|
||||||
val timeInSeconds = timeInMinutes * 60
|
val finishesAdventureAt = timeInMinutes * 60
|
||||||
componentActivity.lifecycleScope.launch(Dispatchers.IO) {
|
componentActivity.lifecycleScope.launch(Dispatchers.IO) {
|
||||||
val characterData = database
|
val characterData = database
|
||||||
.userCharacterDao()
|
.userCharacterDao()
|
||||||
@ -31,7 +31,7 @@ class AdventureScreenControllerImpl(
|
|||||||
|
|
||||||
database
|
database
|
||||||
.adventureDao()
|
.adventureDao()
|
||||||
.insertNewAdventure(characterId, timeInSeconds)
|
.insertNewAdventure(characterId, timeInMinutes, finishesAdventureAt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@ class HomeScreenControllerImpl(
|
|||||||
.getAdventureCharacters()
|
.getAdventureCharacters()
|
||||||
|
|
||||||
val finishedAdventureCharacters = adventureCharacters.filter { character ->
|
val finishedAdventureCharacters = adventureCharacters.filter { character ->
|
||||||
character.timeLeft <= currentTime
|
character.finishesAdventure <= currentTime
|
||||||
}
|
}
|
||||||
|
|
||||||
onCompletion(finishedAdventureCharacters.isNotEmpty())
|
onCompletion(finishedAdventureCharacters.isNotEmpty())
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import android.widget.Toast
|
|||||||
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 kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class StorageScreenControllerImpl(
|
class StorageScreenControllerImpl(
|
||||||
@ -13,8 +14,10 @@ class StorageScreenControllerImpl(
|
|||||||
private val database = application.container.db
|
private val database = application.container.db
|
||||||
|
|
||||||
override fun setActive(characterId: Long, onCompletion: () -> Unit) {
|
override fun setActive(characterId: Long, onCompletion: () -> Unit) {
|
||||||
componentActivity.lifecycleScope.launch {
|
componentActivity.lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
database.userCharacterDao().clearActiveCharacter()
|
||||||
database.userCharacterDao().setActiveCharacter(characterId)
|
database.userCharacterDao().setActiveCharacter(characterId)
|
||||||
|
|
||||||
componentActivity.runOnUiThread {
|
componentActivity.runOnUiThread {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
componentActivity,
|
componentActivity,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user