diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/campaign/CampaignScreen.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/campaign/CampaignScreen.kt index 3596b4d..db91e06 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/campaign/CampaignScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/campaign/CampaignScreen.kt @@ -104,7 +104,9 @@ fun CampaignScreen( PlayerRibbon( modifier = Modifier.fillMaxHeight(), onCharacter = { - playerDetailViewModel.showCharacter(characterSheetId = it) + scope.launch { + playerDetailViewModel.showCharacter(characterSheetId = it) + } }, onLevelUp = { screen.navigateToLevelScreen(characterSheetId = it) @@ -128,7 +130,9 @@ fun CampaignScreen( NpcRibbon( modifier = Modifier.fillMaxHeight(), onCharacter = { - npcDetailViewModel.showCharacter(characterSheetId = it) + scope.launch { + npcDetailViewModel.showCharacter(characterSheetId = it) + } }, onLevelUp = { diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/campaign/player/detail/CharacterDetailViewModel.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/campaign/player/detail/CharacterDetailViewModel.kt index db132db..3e1e59b 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/campaign/player/detail/CharacterDetailViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/campaign/player/detail/CharacterDetailViewModel.kt @@ -3,7 +3,6 @@ package com.pixelized.desktop.lwa.ui.screen.campaign.player.detail import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.pixelized.desktop.lwa.repository.alteration.AlterationRepository -import com.pixelized.desktop.lwa.repository.campaign.CampaignRepository import com.pixelized.desktop.lwa.repository.characterSheet.CharacterSheetRepository import com.pixelized.desktop.lwa.repository.network.NetworkRepository import com.pixelized.shared.lwa.protocol.websocket.CharacterSheetEvent @@ -13,6 +12,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.launch class CharacterDetailViewModel( private val characterSheetRepository: CharacterSheetRepository, @@ -65,7 +65,12 @@ class CharacterDetailViewModel( initialValue = empty(), ) - fun showCharacter(characterSheetId: String) { + suspend fun showCharacter( + characterSheetId: String, + ) { + if (characterSheetRepository.characterDetail(characterSheetId = characterSheetId) == null) { + characterSheetRepository.updateCharacterSheet(characterSheetId = characterSheetId) + } displayedCharacterId.value = characterSheetId } diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/character/list/GMCharacterPage.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/character/list/GMCharacterPage.kt index 33a75be..8d59e70 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/character/list/GMCharacterPage.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/character/list/GMCharacterPage.kt @@ -78,7 +78,9 @@ fun GMCharacterPage( onTag = viewModel::onTag, onCharacterAction = viewModel::onCharacterAction, onCharacterSheetDetail = { characterSheetId -> - characterDetailViewModel.showCharacter(characterSheetId = characterSheetId) + scope.launch { + characterDetailViewModel.showCharacter(characterSheetId = characterSheetId) + } }, onCharacterSheetEdit = { characterSheetId -> scope.launch {