Add alteration support for diminished status.
This commit is contained in:
parent
17b7b06ec8
commit
51a477bb58
5 changed files with 66 additions and 29 deletions
|
|
@ -23,6 +23,7 @@ import androidx.compose.runtime.State
|
|||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
|
|
@ -45,6 +46,7 @@ data class CharacterSheetDiminishedDialogUio(
|
|||
val label: String,
|
||||
val value: () -> TextFieldValue,
|
||||
val onValueChange: (TextFieldValue) -> Unit,
|
||||
val additional: String?,
|
||||
)
|
||||
|
||||
@Composable
|
||||
|
|
@ -76,6 +78,14 @@ private fun CharacterSheetDiminishedContent(
|
|||
val typography = MaterialTheme.typography
|
||||
val colors = MaterialTheme.colors
|
||||
|
||||
val valueTypography = remember {
|
||||
typography.h5.copy(
|
||||
color = colors.primary,
|
||||
textAlign = TextAlign.Center,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
LaunchedEffect(Unit) {
|
||||
focusRequester.requestFocus()
|
||||
|
|
@ -107,24 +117,32 @@ private fun CharacterSheetDiminishedContent(
|
|||
style = MaterialTheme.typography.caption,
|
||||
text = dialog.label,
|
||||
)
|
||||
BasicTextField(
|
||||
modifier = Modifier
|
||||
.focusRequester(focusRequester = focusRequester)
|
||||
.width(width = 120.dp),
|
||||
textStyle = remember {
|
||||
typography.h5.copy(
|
||||
color = colors.primary,
|
||||
textAlign = TextAlign.Center,
|
||||
fontWeight = FontWeight.Bold
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(
|
||||
space = 8.dp,
|
||||
alignment = Alignment.CenterHorizontally
|
||||
)
|
||||
) {
|
||||
BasicTextField(
|
||||
modifier = Modifier
|
||||
.focusRequester(focusRequester = focusRequester)
|
||||
.width(width = 120.dp),
|
||||
textStyle = valueTypography,
|
||||
cursorBrush = SolidColor(MaterialTheme.colors.primary),
|
||||
singleLine = true,
|
||||
keyboardActions = KeyboardActions { onConfirm(dialog) },
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||
value = dialog.value(),
|
||||
onValueChange = dialog.onValueChange,
|
||||
)
|
||||
dialog.additional?.let {
|
||||
Text(
|
||||
modifier = Modifier.alpha(alpha = 0.66f),
|
||||
style = valueTypography,
|
||||
text = it
|
||||
)
|
||||
},
|
||||
cursorBrush = SolidColor(MaterialTheme.colors.primary),
|
||||
singleLine = true,
|
||||
keyboardActions = KeyboardActions { onConfirm(dialog) },
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||
value = dialog.value(),
|
||||
onValueChange = dialog.onValueChange,
|
||||
)
|
||||
}
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.padding(top = 4.dp)
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ import androidx.compose.ui.text.input.TextFieldValue
|
|||
import com.pixelized.desktop.lwa.repository.alteration.AlterationRepository
|
||||
import com.pixelized.desktop.lwa.repository.characterSheet.CharacterSheetRepository
|
||||
import com.pixelized.shared.lwa.model.AlteredCharacterSheetFactory
|
||||
import com.pixelized.shared.lwa.model.alteration.FieldAlteration
|
||||
import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet
|
||||
import com.pixelized.shared.lwa.utils.signLabel
|
||||
import lwacharactersheet.composeapp.generated.resources.Res
|
||||
import lwacharactersheet.composeapp.generated.resources.character_sheet__diminished__label
|
||||
import org.jetbrains.compose.resources.getString
|
||||
import kotlin.math.abs
|
||||
|
||||
class CharacterSheetDiminishedDialogFactory(
|
||||
private val characterSheetRepository: CharacterSheetRepository,
|
||||
|
|
@ -19,7 +20,7 @@ class CharacterSheetDiminishedDialogFactory(
|
|||
) {
|
||||
suspend fun convertToDialogUio(
|
||||
characterSheetId: String?,
|
||||
) : CharacterSheetDiminishedDialogUio? {
|
||||
): CharacterSheetDiminishedDialogUio? {
|
||||
|
||||
if (characterSheetId == null) return null
|
||||
|
||||
|
|
@ -29,21 +30,19 @@ class CharacterSheetDiminishedDialogFactory(
|
|||
|
||||
if (characterSheet == null) return null
|
||||
|
||||
val alterations: Map<String, List<FieldAlteration>> = alterationRepository.activeFieldAlterations(
|
||||
characterSheetId = characterSheetId,
|
||||
)
|
||||
|
||||
val alteredCharacterSheet = alteredCharacterSheetFactory.sheet(
|
||||
characterSheet = characterSheet,
|
||||
alterations = alterations,
|
||||
alterations = alterationRepository.activeFieldAlterations(
|
||||
characterSheetId = characterSheetId
|
||||
),
|
||||
)
|
||||
|
||||
val textFieldValue = mutableStateOf(
|
||||
TextFieldValue(
|
||||
text = "${alteredCharacterSheet.diminished}",
|
||||
text = "${characterSheet.diminished}",
|
||||
selection = TextRange(index = 0),
|
||||
)
|
||||
)
|
||||
|
||||
return CharacterSheetDiminishedDialogUio(
|
||||
characterSheetId = characterSheetId,
|
||||
label = getString(resource = Res.string.character_sheet__diminished__label),
|
||||
|
|
@ -54,6 +53,9 @@ class CharacterSheetDiminishedDialogFactory(
|
|||
else -> value
|
||||
}
|
||||
},
|
||||
additional = (alteredCharacterSheet.diminishedAlterations)
|
||||
.takeIf { it != 0 }
|
||||
?.let { "${it.signLabel}${abs(it)}" }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -21,11 +21,11 @@ import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet.Characterist
|
|||
import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet.CharacteristicId.REFLEX
|
||||
import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet.CharacteristicId.STR
|
||||
import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet.CharacteristicId.THUMBNAIL
|
||||
import com.pixelized.shared.lwa.model.inventory.Inventory
|
||||
import com.pixelized.shared.lwa.model.inventory.Inventory.Item
|
||||
import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet.StatusId.DIMINISHED
|
||||
import com.pixelized.shared.lwa.parser.expression.Expression
|
||||
import com.pixelized.shared.lwa.usecase.CharacterSheetUseCase
|
||||
import com.pixelized.shared.lwa.usecase.ExpressionUseCase
|
||||
import kotlin.math.max
|
||||
|
||||
class AlteredCharacterSheetFactory(
|
||||
private val sheetUseCase: CharacterSheetUseCase,
|
||||
|
|
@ -109,7 +109,10 @@ class AlteredCharacterSheet(
|
|||
get() = sheet.fatigue
|
||||
|
||||
val diminished: Int
|
||||
get() = sheet.diminished
|
||||
get() = max(0, sheet.diminished + diminishedAlterations)
|
||||
|
||||
val diminishedAlterations: Int
|
||||
get() = fieldAlterations[DIMINISHED].sum()
|
||||
|
||||
val alterations: List<String>
|
||||
get() = sheet.alterations
|
||||
|
|
|
|||
|
|
@ -56,6 +56,10 @@ data class CharacterSheet(
|
|||
val critical: String?,
|
||||
)
|
||||
|
||||
object StatusId {
|
||||
const val DIMINISHED = "DIMINISHED"
|
||||
}
|
||||
|
||||
object CharacteristicId {
|
||||
const val PORTRAIT = "PORTRAIT"
|
||||
const val THUMBNAIL = "THUMBNAIL"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.pixelized.shared.lwa.utils
|
||||
|
||||
import kotlin.math.sign
|
||||
|
||||
val Int.signLabel: Char
|
||||
get() = when (this.sign) {
|
||||
1 -> '+'
|
||||
-1 -> '-'
|
||||
else -> ' '
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue