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.runtime.remember
|
||||||
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.alpha
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.graphics.SolidColor
|
import androidx.compose.ui.graphics.SolidColor
|
||||||
|
|
@ -45,6 +46,7 @@ data class CharacterSheetDiminishedDialogUio(
|
||||||
val label: String,
|
val label: String,
|
||||||
val value: () -> TextFieldValue,
|
val value: () -> TextFieldValue,
|
||||||
val onValueChange: (TextFieldValue) -> Unit,
|
val onValueChange: (TextFieldValue) -> Unit,
|
||||||
|
val additional: String?,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
@ -76,6 +78,14 @@ private fun CharacterSheetDiminishedContent(
|
||||||
val typography = MaterialTheme.typography
|
val typography = MaterialTheme.typography
|
||||||
val colors = MaterialTheme.colors
|
val colors = MaterialTheme.colors
|
||||||
|
|
||||||
|
val valueTypography = remember {
|
||||||
|
typography.h5.copy(
|
||||||
|
color = colors.primary,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
fontWeight = FontWeight.Bold
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val focusRequester = remember { FocusRequester() }
|
val focusRequester = remember { FocusRequester() }
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
focusRequester.requestFocus()
|
focusRequester.requestFocus()
|
||||||
|
|
@ -107,24 +117,32 @@ private fun CharacterSheetDiminishedContent(
|
||||||
style = MaterialTheme.typography.caption,
|
style = MaterialTheme.typography.caption,
|
||||||
text = dialog.label,
|
text = dialog.label,
|
||||||
)
|
)
|
||||||
BasicTextField(
|
Row(
|
||||||
modifier = Modifier
|
horizontalArrangement = Arrangement.spacedBy(
|
||||||
.focusRequester(focusRequester = focusRequester)
|
space = 8.dp,
|
||||||
.width(width = 120.dp),
|
alignment = Alignment.CenterHorizontally
|
||||||
textStyle = remember {
|
)
|
||||||
typography.h5.copy(
|
) {
|
||||||
color = colors.primary,
|
BasicTextField(
|
||||||
textAlign = TextAlign.Center,
|
modifier = Modifier
|
||||||
fontWeight = FontWeight.Bold
|
.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(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(top = 4.dp)
|
.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.alteration.AlterationRepository
|
||||||
import com.pixelized.desktop.lwa.repository.characterSheet.CharacterSheetRepository
|
import com.pixelized.desktop.lwa.repository.characterSheet.CharacterSheetRepository
|
||||||
import com.pixelized.shared.lwa.model.AlteredCharacterSheetFactory
|
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.model.characterSheet.CharacterSheet
|
||||||
|
import com.pixelized.shared.lwa.utils.signLabel
|
||||||
import lwacharactersheet.composeapp.generated.resources.Res
|
import lwacharactersheet.composeapp.generated.resources.Res
|
||||||
import lwacharactersheet.composeapp.generated.resources.character_sheet__diminished__label
|
import lwacharactersheet.composeapp.generated.resources.character_sheet__diminished__label
|
||||||
import org.jetbrains.compose.resources.getString
|
import org.jetbrains.compose.resources.getString
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
class CharacterSheetDiminishedDialogFactory(
|
class CharacterSheetDiminishedDialogFactory(
|
||||||
private val characterSheetRepository: CharacterSheetRepository,
|
private val characterSheetRepository: CharacterSheetRepository,
|
||||||
|
|
@ -19,7 +20,7 @@ class CharacterSheetDiminishedDialogFactory(
|
||||||
) {
|
) {
|
||||||
suspend fun convertToDialogUio(
|
suspend fun convertToDialogUio(
|
||||||
characterSheetId: String?,
|
characterSheetId: String?,
|
||||||
) : CharacterSheetDiminishedDialogUio? {
|
): CharacterSheetDiminishedDialogUio? {
|
||||||
|
|
||||||
if (characterSheetId == null) return null
|
if (characterSheetId == null) return null
|
||||||
|
|
||||||
|
|
@ -29,21 +30,19 @@ class CharacterSheetDiminishedDialogFactory(
|
||||||
|
|
||||||
if (characterSheet == null) return null
|
if (characterSheet == null) return null
|
||||||
|
|
||||||
val alterations: Map<String, List<FieldAlteration>> = alterationRepository.activeFieldAlterations(
|
|
||||||
characterSheetId = characterSheetId,
|
|
||||||
)
|
|
||||||
|
|
||||||
val alteredCharacterSheet = alteredCharacterSheetFactory.sheet(
|
val alteredCharacterSheet = alteredCharacterSheetFactory.sheet(
|
||||||
characterSheet = characterSheet,
|
characterSheet = characterSheet,
|
||||||
alterations = alterations,
|
alterations = alterationRepository.activeFieldAlterations(
|
||||||
|
characterSheetId = characterSheetId
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
val textFieldValue = mutableStateOf(
|
val textFieldValue = mutableStateOf(
|
||||||
TextFieldValue(
|
TextFieldValue(
|
||||||
text = "${alteredCharacterSheet.diminished}",
|
text = "${characterSheet.diminished}",
|
||||||
selection = TextRange(index = 0),
|
selection = TextRange(index = 0),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return CharacterSheetDiminishedDialogUio(
|
return CharacterSheetDiminishedDialogUio(
|
||||||
characterSheetId = characterSheetId,
|
characterSheetId = characterSheetId,
|
||||||
label = getString(resource = Res.string.character_sheet__diminished__label),
|
label = getString(resource = Res.string.character_sheet__diminished__label),
|
||||||
|
|
@ -54,6 +53,9 @@ class CharacterSheetDiminishedDialogFactory(
|
||||||
else -> value
|
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.REFLEX
|
||||||
import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet.CharacteristicId.STR
|
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.characterSheet.CharacterSheet.CharacteristicId.THUMBNAIL
|
||||||
import com.pixelized.shared.lwa.model.inventory.Inventory
|
import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet.StatusId.DIMINISHED
|
||||||
import com.pixelized.shared.lwa.model.inventory.Inventory.Item
|
|
||||||
import com.pixelized.shared.lwa.parser.expression.Expression
|
import com.pixelized.shared.lwa.parser.expression.Expression
|
||||||
import com.pixelized.shared.lwa.usecase.CharacterSheetUseCase
|
import com.pixelized.shared.lwa.usecase.CharacterSheetUseCase
|
||||||
import com.pixelized.shared.lwa.usecase.ExpressionUseCase
|
import com.pixelized.shared.lwa.usecase.ExpressionUseCase
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
class AlteredCharacterSheetFactory(
|
class AlteredCharacterSheetFactory(
|
||||||
private val sheetUseCase: CharacterSheetUseCase,
|
private val sheetUseCase: CharacterSheetUseCase,
|
||||||
|
|
@ -109,7 +109,10 @@ class AlteredCharacterSheet(
|
||||||
get() = sheet.fatigue
|
get() = sheet.fatigue
|
||||||
|
|
||||||
val diminished: Int
|
val diminished: Int
|
||||||
get() = sheet.diminished
|
get() = max(0, sheet.diminished + diminishedAlterations)
|
||||||
|
|
||||||
|
val diminishedAlterations: Int
|
||||||
|
get() = fieldAlterations[DIMINISHED].sum()
|
||||||
|
|
||||||
val alterations: List<String>
|
val alterations: List<String>
|
||||||
get() = sheet.alterations
|
get() = sheet.alterations
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,10 @@ data class CharacterSheet(
|
||||||
val critical: String?,
|
val critical: String?,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
object StatusId {
|
||||||
|
const val DIMINISHED = "DIMINISHED"
|
||||||
|
}
|
||||||
|
|
||||||
object CharacteristicId {
|
object CharacteristicId {
|
||||||
const val PORTRAIT = "PORTRAIT"
|
const val PORTRAIT = "PORTRAIT"
|
||||||
const val THUMBNAIL = "THUMBNAIL"
|
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