Add inventory and equipment feature.
This commit is contained in:
parent
2be527abf9
commit
daea5fd6dc
74 changed files with 1609 additions and 574 deletions
|
|
@ -6,15 +6,17 @@ import androidx.compose.runtime.mutableStateOf
|
|||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.pixelized.rplexicon.repository.data.ActionRepository
|
||||
import com.pixelized.rplexicon.repository.data.AlterationRepository
|
||||
import com.pixelized.rplexicon.repository.data.CharacterSheetRepository
|
||||
import com.pixelized.rplexicon.repository.data.DescriptionRepository
|
||||
import com.pixelized.rplexicon.repository.data.LexiconRepository
|
||||
import com.pixelized.rplexicon.repository.data.LocationRepository
|
||||
import com.pixelized.rplexicon.repository.data.QuestRepository
|
||||
import com.pixelized.rplexicon.repository.data.SkillRepository
|
||||
import com.pixelized.rplexicon.repository.data.SpellRepository
|
||||
import com.pixelized.rplexicon.repository.data.character.ActionRepository
|
||||
import com.pixelized.rplexicon.repository.data.character.AlterationRepository
|
||||
import com.pixelized.rplexicon.repository.data.character.CharacterSheetRepository
|
||||
import com.pixelized.rplexicon.repository.data.character.DescriptionRepository
|
||||
import com.pixelized.rplexicon.repository.data.character.EquipmentRepository
|
||||
import com.pixelized.rplexicon.repository.data.character.InventoryRepository
|
||||
import com.pixelized.rplexicon.repository.data.lexicon.LexiconRepository
|
||||
import com.pixelized.rplexicon.repository.data.lexicon.LocationRepository
|
||||
import com.pixelized.rplexicon.repository.data.lexicon.QuestRepository
|
||||
import com.pixelized.rplexicon.repository.data.character.SkillRepository
|
||||
import com.pixelized.rplexicon.repository.data.character.SpellRepository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
|
|
@ -34,6 +36,8 @@ class LauncherViewModel @Inject constructor(
|
|||
spellRepository: SpellRepository,
|
||||
skillRepository: SkillRepository,
|
||||
descriptionRepository: DescriptionRepository,
|
||||
inventoryRepository: InventoryRepository,
|
||||
equipmentRepository: EquipmentRepository,
|
||||
) : ViewModel() {
|
||||
|
||||
private val _error = MutableSharedFlow<String>()
|
||||
|
|
@ -76,7 +80,7 @@ class LauncherViewModel @Inject constructor(
|
|||
_error.tryEmit("CharacterSheet fail to update")
|
||||
}
|
||||
}
|
||||
val descriptionSheet = async {
|
||||
val description = async {
|
||||
try {
|
||||
descriptionRepository.fetchDescription()
|
||||
} catch (exception: Exception) {
|
||||
|
|
@ -84,7 +88,23 @@ class LauncherViewModel @Inject constructor(
|
|||
_error.tryEmit("Skill/Spell description fail to update")
|
||||
}
|
||||
}
|
||||
awaitAll(lexicon, location, quest, characterSheet, descriptionSheet)
|
||||
val inventory = async {
|
||||
try {
|
||||
inventoryRepository.fetchInventory()
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.tryEmit("Inventories fail to update")
|
||||
}
|
||||
}
|
||||
val equipment = async {
|
||||
try {
|
||||
equipmentRepository.fetchEquipment()
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.tryEmit("Equipments fail to update")
|
||||
}
|
||||
}
|
||||
awaitAll(characterSheet)
|
||||
|
||||
val alteration = async {
|
||||
try {
|
||||
|
|
@ -96,7 +116,7 @@ class LauncherViewModel @Inject constructor(
|
|||
}
|
||||
val action = async {
|
||||
try {
|
||||
actionRepository.fetchActions()
|
||||
actionRepository.fetchActions(characters = characterSheetRepository.data.value)
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.tryEmit("Action fail to update")
|
||||
|
|
@ -118,7 +138,10 @@ class LauncherViewModel @Inject constructor(
|
|||
_error.tryEmit("Skill fail to update")
|
||||
}
|
||||
}
|
||||
awaitAll(alteration, action, spell, skill)
|
||||
awaitAll(
|
||||
lexicon, location, quest, description, inventory,
|
||||
equipment, alteration, action, spell, skill,
|
||||
)
|
||||
|
||||
isLoading = false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue