Update the Alteration dialog to track equipment alterations.

This commit is contained in:
Thomas Andres Gomez 2025-05-09 15:44:39 +02:00
parent 5b633de981
commit 3b9503243a
4 changed files with 18 additions and 7 deletions

View file

@ -159,13 +159,13 @@ class AlterationRepository(
} }
fun activeAlterations( fun activeAlterations(
characterSheetId: String, characterSheetId: String?,
): List<Alteration> { ): List<Alteration> {
return activeAlterationsFlow.value[characterSheetId] ?: emptyList() return activeAlterationsFlow.value[characterSheetId] ?: emptyList()
} }
fun activeAlterationsFlow( fun activeAlterationsFlow(
characterSheetId: String, characterSheetId: String?,
): Flow<List<Alteration>> { ): Flow<List<Alteration>> {
return activeAlterationsFlow.map { it[characterSheetId] ?: emptyList() } return activeAlterationsFlow.map { it[characterSheetId] ?: emptyList() }
} }

View file

@ -17,6 +17,7 @@ import androidx.compose.runtime.Stable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.pixelized.desktop.lwa.ui.screen.gamemaster.common.tag.GMTag import com.pixelized.desktop.lwa.ui.screen.gamemaster.common.tag.GMTag
@ -28,6 +29,7 @@ data class AlterationToggleItemUio(
val id: String, val id: String,
val label: String, val label: String,
val tags: List<GMTagUio>, val tags: List<GMTagUio>,
val enable: Boolean,
val active: Boolean, val active: Boolean,
) )
@ -47,10 +49,11 @@ fun AlterationToggleItem(
Row( Row(
modifier = Modifier modifier = Modifier
.clip(shape = MaterialTheme.lwa.shapes.gameMaster) .clip(shape = MaterialTheme.lwa.shapes.gameMaster)
.clickable(onClick = onAlteration) .clickable(enabled = alteration.enable, onClick = onAlteration)
.background(color = MaterialTheme.lwa.colorScheme.elevated.base1dp) .background(color = MaterialTheme.lwa.colorScheme.elevated.base1dp)
.minimumInteractiveComponentSize() .minimumInteractiveComponentSize()
.padding(paddingValues = padding) .padding(paddingValues = padding)
.graphicsLayer { this.alpha = if (alteration.enable) 1f else 0.5f }
.then(other = modifier), .then(other = modifier),
horizontalArrangement = Arrangement.spacedBy(space = 8.dp), horizontalArrangement = Arrangement.spacedBy(space = 8.dp),
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,

View file

@ -33,6 +33,7 @@ class CharacterSheetAlterationDialogFactory(
fun convertToDialogUio( fun convertToDialogUio(
characterSheet: CharacterSheet?, characterSheet: CharacterSheet?,
alterations: List<Alteration>, alterations: List<Alteration>,
activeAlterations: List<Alteration>,
tagMap: Map<String, Tag>, tagMap: Map<String, Tag>,
filter: LwaTextFieldUio, filter: LwaTextFieldUio,
tags: StateFlow<List<GMTagUio>>, tags: StateFlow<List<GMTagUio>>,
@ -46,6 +47,8 @@ class CharacterSheetAlterationDialogFactory(
filter = filter, filter = filter,
tags = tags, tags = tags,
alterations = alterations.map { alteration -> alterations = alterations.map { alteration ->
val isActive = activeAlterations.contains(alteration)
val isPersonal = characterSheet.alterations.contains(alteration.id)
AlterationToggleItemUio( AlterationToggleItemUio(
id = alteration.id, id = alteration.id,
label = alteration.metadata.name, label = alteration.metadata.name,
@ -53,7 +56,8 @@ class CharacterSheetAlterationDialogFactory(
tags = alteration.tags.mapNotNull { tagMap[it] }, tags = alteration.tags.mapNotNull { tagMap[it] },
selectedTagId = selectedTagId selectedTagId = selectedTagId
), ),
active = characterSheet.alterations.contains(alteration.id), enable = isPersonal || isActive.not(), // disable alteration coming from equipment
active = isActive,
) )
}, },
) )

View file

@ -11,7 +11,9 @@ import com.pixelized.desktop.lwa.ui.composable.textfield.createLwaTextFieldFlow
import com.pixelized.desktop.lwa.ui.screen.gamemaster.common.tag.GMTagFactory import com.pixelized.desktop.lwa.ui.screen.gamemaster.common.tag.GMTagFactory
import com.pixelized.desktop.lwa.ui.screen.gamemaster.common.tag.GMTagUio import com.pixelized.desktop.lwa.ui.screen.gamemaster.common.tag.GMTagUio
import com.pixelized.desktop.lwa.utils.extention.unAccent import com.pixelized.desktop.lwa.utils.extention.unAccent
import com.pixelized.shared.lwa.model.alteration.Alteration
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.SharedFlow
@ -43,7 +45,7 @@ class CharacterSheetAlterationDialogViewModel(
) )
private val filter = _filter.createLwaTextField() private val filter = _filter.createLwaTextField()
private val selectedAlterationsFlow = combine( private val filteredAlterationsFlow: Flow<List<Alteration>> = combine(
alterationRepository.alterationFlow.map { it.values }, alterationRepository.alterationFlow.map { it.values },
_filter.valueFlow.map { it.unAccent() }, _filter.valueFlow.map { it.unAccent() },
selectedTagIdFlow, selectedTagIdFlow,
@ -72,14 +74,16 @@ class CharacterSheetAlterationDialogViewModel(
.flatMapLatest { characterSheetId -> .flatMapLatest { characterSheetId ->
combine( combine(
characterSheetRepository.characterDetailFlow(characterSheetId = characterSheetId), characterSheetRepository.characterDetailFlow(characterSheetId = characterSheetId),
alterationRepository.activeAlterationsFlow(characterSheetId = characterSheetId),
tagRepository.alterationsTagFlow(), tagRepository.alterationsTagFlow(),
selectedAlterationsFlow, filteredAlterationsFlow,
selectedTagIdFlow, selectedTagIdFlow,
) { characterSheet, tagMap, alterations, selectedTagId -> ) { characterSheet, activeAlterations, tagMap, alterations, selectedTagId ->
dialogFactory.convertToDialogUio( dialogFactory.convertToDialogUio(
characterSheet = characterSheet, characterSheet = characterSheet,
tagMap = tagMap, tagMap = tagMap,
alterations = alterations, alterations = alterations,
activeAlterations = activeAlterations,
filter = filter, filter = filter,
tags = tags, tags = tags,
selectedTagId = selectedTagId, selectedTagId = selectedTagId,