From 2c6fc19a2c8781dd2a4740f8dfe091421e96d541 Mon Sep 17 00:00:00 2001 From: Thomas Andres Gomez Date: Sun, 17 Dec 2023 15:25:26 +0100 Subject: [PATCH] Change the behavior of the dice --- .../rplexicon/business/DiceThrowUseCase.kt | 47 +++++++++++-------- .../parser/alteration/AlterationParser.kt | 2 +- .../rplexicon/ui/screens/rolls/RollOverlay.kt | 19 +++++++- .../ui/screens/rolls/RollOverlayViewModel.kt | 2 +- .../ui/screens/rolls/composable/ThrowsCard.kt | 2 +- .../rolls/factory/AlterationFactory.kt | 24 +++++----- 6 files changed, 61 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/com/pixelized/rplexicon/business/DiceThrowUseCase.kt b/app/src/main/java/com/pixelized/rplexicon/business/DiceThrowUseCase.kt index de02b49..1e70071 100644 --- a/app/src/main/java/com/pixelized/rplexicon/business/DiceThrowUseCase.kt +++ b/app/src/main/java/com/pixelized/rplexicon/business/DiceThrowUseCase.kt @@ -613,25 +613,25 @@ class DiceThrowUseCase @Inject constructor( ) } ?: emptyList() + // compute the final roll result + val rollResult = when (result.value) { + 1, 20 -> "${result.value}" + else -> "${allValue.sum()}" + } + // build the result. return DiceThrowResult( dice = RollDiceUio( isCriticalSuccess = result.value == 20, isCriticalFailure = result.value == 1, - result = "${result.value}", + result = rollResult, ), card = ThrowsCardUio( title = abilityTitleString.uppercase(), highlight = abilityLabelString.uppercase(), dice = R.drawable.ic_d20_24, roll = allValue.toLabel(), - result = "${ - when (result.value) { - 20 -> 20 - 1 -> 1 - else -> allValue.sum() - } - }", + result = rollResult, isCriticalSuccess = result.value == 20, isCriticalFailure = result.value == 1, details = listOf( @@ -718,13 +718,20 @@ class DiceThrowUseCase @Inject constructor( ) } ?: emptyList() + // compute the final roll result + val rollResult = when { + canMakeCriticalRoll && result.value == 20 -> "20" + canMakeCriticalRoll && result.value == 1 -> "1" + else -> "${allValue.sum()}" + } + // build the result. return DiceThrowResult( dice = RollDiceUio( icon = diceThrow?.faces?.icon ?: R.drawable.ic_d20_24, isCriticalSuccess = canMakeCriticalRoll && result.value == 20, isCriticalFailure = canMakeCriticalRoll && result.value == 1, - result = "${result.value}", + result = rollResult, ), card = ThrowsCardUio( title = titleString.uppercase(), @@ -733,13 +740,7 @@ class DiceThrowUseCase @Inject constructor( isCriticalSuccess = canMakeCriticalRoll && result.value == 20, isCriticalFailure = canMakeCriticalRoll && result.value == 1, roll = allValue.toLabel(), - result = "${ - when { - canMakeCriticalRoll && result.value == 20 -> 20 - canMakeCriticalRoll && result.value == 1 -> 1 - else -> allValue.sum() - } - }", + result = rollResult, details = listOf( ThrowsCardUio.Detail( title = action, @@ -799,18 +800,21 @@ class DiceThrowUseCase @Inject constructor( // fetch and build the associated characteristic val relatedStatBonus = spell?.effect.statBonus(name = spellName) + // compute the final roll result + val rollResult = "${allValue.sum()}" + // build the result. return DiceThrowResult( dice = RollDiceUio( icon = (spell?.effect?.faces ?: 4).icon, - result = "${result.value}", + result = rollResult, ), card = ThrowsCardUio( title = titleString.uppercase(), highlight = spellName, dice = (spell?.effect?.faces ?: 4).icon, roll = allValue.toLabel(), - result = "${allValue.sum()}", + result = rollResult, details = listOf( ThrowsCardUio.Detail( title = spellName, @@ -852,18 +856,21 @@ class DiceThrowUseCase @Inject constructor( // fetch and build the associated characteristic, proficiency or level val relatedStatBonus = skill?.effect.statBonus(name = skill?.name) + // compute the final roll result + val rollResult = "${allValue.sum()}" + // build the result. return DiceThrowResult( dice = RollDiceUio( icon = (skill?.effect?.faces ?: 4).icon, - result = "${result.value}", + result = rollResult, ), card = ThrowsCardUio( title = titleString.uppercase(), highlight = spellName, dice = (skill?.effect?.faces ?: 4).icon, roll = allValue.toLabel(), - result = "${allValue.sum()}", + result = rollResult, details = listOf( ThrowsCardUio.Detail( title = spellName, diff --git a/app/src/main/java/com/pixelized/rplexicon/data/parser/alteration/AlterationParser.kt b/app/src/main/java/com/pixelized/rplexicon/data/parser/alteration/AlterationParser.kt index 2b5ff34..aa27e44 100644 --- a/app/src/main/java/com/pixelized/rplexicon/data/parser/alteration/AlterationParser.kt +++ b/app/src/main/java/com/pixelized/rplexicon/data/parser/alteration/AlterationParser.kt @@ -121,6 +121,6 @@ class AlterationParser @Inject constructor( private val TARGET = column("Cible") private val SOURCE = column("Source") private val COLUMNS - get() = listOf(SOURCE, TARGET) + Property.values().map { column(it.key) } + get() = listOf(SOURCE, TARGET) + Property.entries.map { column(it.key) } } } \ No newline at end of file diff --git a/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/RollOverlay.kt b/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/RollOverlay.kt index 8e3a91c..2b8ca36 100644 --- a/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/RollOverlay.kt +++ b/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/RollOverlay.kt @@ -7,6 +7,7 @@ import androidx.compose.animation.AnimatedContent import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.ContentTransform import androidx.compose.animation.SizeTransform +import androidx.compose.animation.core.animateDpAsState import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.animation.slideInVertically @@ -48,6 +49,7 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.composed import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.stringResource @@ -58,6 +60,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.compose.ui.unit.Density +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog @@ -251,7 +254,7 @@ private fun RollOverlayContent( modifier = Modifier .align(alignment = Alignment.Center) .padding(horizontal = 16.dp) - .padding(bottom = 128.dp), + .detailPaddingBottom(showDetail = showDetail, bottom = 128.dp), dice = dice, onDice = onDice, ) @@ -300,6 +303,20 @@ private fun RollOverlayContent( ) } +private fun Modifier.detailPaddingBottom( + showDetail: State, + bottom: Dp = 128.dp, +): Modifier = composed { + val padding by animateDpAsState( + targetValue = when (showDetail.value) { + true -> bottom + else -> 0.dp + }, + label = "AnimationBottomPaddingDetail" + ) + this.then(other = Modifier.padding(bottom = padding)) +} + @Composable private fun AlterationDetailHandler( detail: State, diff --git a/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/RollOverlayViewModel.kt b/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/RollOverlayViewModel.kt index b8b7845..8c5460e 100644 --- a/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/RollOverlayViewModel.kt +++ b/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/RollOverlayViewModel.kt @@ -57,7 +57,7 @@ class RollOverlayViewModel @Inject constructor( private val _card = mutableStateOf(null) val card: State get() = _card - private val _showDetail = mutableStateOf(true) + private val _showDetail = mutableStateOf(false) val showDetail: State get() = _showDetail private val _alterationDetail = mutableStateOf(null) diff --git a/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/composable/ThrowsCard.kt b/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/composable/ThrowsCard.kt index 9cf1045..d6460a5 100644 --- a/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/composable/ThrowsCard.kt +++ b/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/composable/ThrowsCard.kt @@ -158,7 +158,7 @@ fun ThrowsCard( ) Text( modifier = Modifier.widthIn(min = resultWidth), - style = MaterialTheme.typography.displayMedium, + style = MaterialTheme.typography.displaySmall, textAlign = TextAlign.Center, color = when { throws.isCriticalSuccess -> MaterialTheme.colorScheme.primary diff --git a/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/factory/AlterationFactory.kt b/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/factory/AlterationFactory.kt index 36fee97..7e6e988 100644 --- a/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/factory/AlterationFactory.kt +++ b/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/factory/AlterationFactory.kt @@ -67,7 +67,7 @@ class AlterationFactory @Inject constructor( is DiceThrow.PhysicalMeleeAttack -> { val action = actionRepository.find( character = diceThrow.character, - action = diceThrow.weapon + action = diceThrow.weapon, ) listOf(Property.PHYSICAL_MELEE_ATTACK) + (action?.hit?.modifier ?: emptyList()) } @@ -75,7 +75,7 @@ class AlterationFactory @Inject constructor( is DiceThrow.PhysicalMeleeDamage -> { val action = actionRepository.find( character = diceThrow.character, - action = diceThrow.weapon + action = diceThrow.weapon, ) listOf(Property.PHYSICAL_MELEE_DAMAGE) + (action?.damage?.modifier ?: emptyList()) } @@ -83,17 +83,15 @@ class AlterationFactory @Inject constructor( is DiceThrow.PhysicalRangeAttack -> { val action = actionRepository.find( character = diceThrow.character, - action = diceThrow.weapon + action = diceThrow.weapon, ) listOf(Property.PHYSICAL_RANGE_ATTACK) + (action?.hit?.modifier ?: emptyList()) } - is DiceThrow.Object -> emptyList() - is DiceThrow.PhysicalRangeDamage -> { val action = actionRepository.find( character = diceThrow.character, - action = diceThrow.weapon + action = diceThrow.weapon, ) listOf(Property.PHYSICAL_RANGE_DAMAGE) + (action?.damage?.modifier ?: emptyList()) } @@ -101,7 +99,7 @@ class AlterationFactory @Inject constructor( is DiceThrow.SpellAttack -> { val spell = spellRepository.findAssignedSpell( character = diceThrow.character, - spell = diceThrow.spell + spell = diceThrow.spell, ) listOf(Property.SPELL_ATTACK) + (spell?.hit?.modifier ?: emptyList()) } @@ -109,7 +107,7 @@ class AlterationFactory @Inject constructor( is DiceThrow.SpellDamage -> { val spell = spellRepository.findAssignedSpell( character = diceThrow.character, - spell = diceThrow.spell + spell = diceThrow.spell, ) listOf(Property.SPELL_DAMAGE) + (spell?.effect?.modifier ?: emptyList()) } @@ -117,16 +115,20 @@ class AlterationFactory @Inject constructor( is DiceThrow.SpellEffect -> { val spell = spellRepository.findAssignedSpell( character = diceThrow.character, - spell = diceThrow.spell + spell = diceThrow.spell, ) spell?.effect?.modifier ?: emptyList() } is DiceThrow.Skill -> { - val skill = - skillRepository.find(character = diceThrow.character, skill = diceThrow.skill) + val skill = skillRepository.find( + character = diceThrow.character, + skill = diceThrow.skill, + ) listOf(Property.SKILL) + (skill?.effect?.modifier ?: emptyList()) } + + is DiceThrow.Object -> emptyList() } return alterationRepository