Change the behavior of the dice
This commit is contained in:
parent
bb0e10c1ad
commit
2c6fc19a2c
6 changed files with 61 additions and 35 deletions
|
|
@ -613,25 +613,25 @@ class DiceThrowUseCase @Inject constructor(
|
||||||
)
|
)
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
|
|
||||||
|
// compute the final roll result
|
||||||
|
val rollResult = when (result.value) {
|
||||||
|
1, 20 -> "${result.value}"
|
||||||
|
else -> "${allValue.sum()}"
|
||||||
|
}
|
||||||
|
|
||||||
// build the result.
|
// build the result.
|
||||||
return DiceThrowResult(
|
return DiceThrowResult(
|
||||||
dice = RollDiceUio(
|
dice = RollDiceUio(
|
||||||
isCriticalSuccess = result.value == 20,
|
isCriticalSuccess = result.value == 20,
|
||||||
isCriticalFailure = result.value == 1,
|
isCriticalFailure = result.value == 1,
|
||||||
result = "${result.value}",
|
result = rollResult,
|
||||||
),
|
),
|
||||||
card = ThrowsCardUio(
|
card = ThrowsCardUio(
|
||||||
title = abilityTitleString.uppercase(),
|
title = abilityTitleString.uppercase(),
|
||||||
highlight = abilityLabelString.uppercase(),
|
highlight = abilityLabelString.uppercase(),
|
||||||
dice = R.drawable.ic_d20_24,
|
dice = R.drawable.ic_d20_24,
|
||||||
roll = allValue.toLabel(),
|
roll = allValue.toLabel(),
|
||||||
result = "${
|
result = rollResult,
|
||||||
when (result.value) {
|
|
||||||
20 -> 20
|
|
||||||
1 -> 1
|
|
||||||
else -> allValue.sum()
|
|
||||||
}
|
|
||||||
}",
|
|
||||||
isCriticalSuccess = result.value == 20,
|
isCriticalSuccess = result.value == 20,
|
||||||
isCriticalFailure = result.value == 1,
|
isCriticalFailure = result.value == 1,
|
||||||
details = listOf(
|
details = listOf(
|
||||||
|
|
@ -718,13 +718,20 @@ class DiceThrowUseCase @Inject constructor(
|
||||||
)
|
)
|
||||||
} ?: emptyList()
|
} ?: 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.
|
// build the result.
|
||||||
return DiceThrowResult(
|
return DiceThrowResult(
|
||||||
dice = RollDiceUio(
|
dice = RollDiceUio(
|
||||||
icon = diceThrow?.faces?.icon ?: R.drawable.ic_d20_24,
|
icon = diceThrow?.faces?.icon ?: R.drawable.ic_d20_24,
|
||||||
isCriticalSuccess = canMakeCriticalRoll && result.value == 20,
|
isCriticalSuccess = canMakeCriticalRoll && result.value == 20,
|
||||||
isCriticalFailure = canMakeCriticalRoll && result.value == 1,
|
isCriticalFailure = canMakeCriticalRoll && result.value == 1,
|
||||||
result = "${result.value}",
|
result = rollResult,
|
||||||
),
|
),
|
||||||
card = ThrowsCardUio(
|
card = ThrowsCardUio(
|
||||||
title = titleString.uppercase(),
|
title = titleString.uppercase(),
|
||||||
|
|
@ -733,13 +740,7 @@ class DiceThrowUseCase @Inject constructor(
|
||||||
isCriticalSuccess = canMakeCriticalRoll && result.value == 20,
|
isCriticalSuccess = canMakeCriticalRoll && result.value == 20,
|
||||||
isCriticalFailure = canMakeCriticalRoll && result.value == 1,
|
isCriticalFailure = canMakeCriticalRoll && result.value == 1,
|
||||||
roll = allValue.toLabel(),
|
roll = allValue.toLabel(),
|
||||||
result = "${
|
result = rollResult,
|
||||||
when {
|
|
||||||
canMakeCriticalRoll && result.value == 20 -> 20
|
|
||||||
canMakeCriticalRoll && result.value == 1 -> 1
|
|
||||||
else -> allValue.sum()
|
|
||||||
}
|
|
||||||
}",
|
|
||||||
details = listOf(
|
details = listOf(
|
||||||
ThrowsCardUio.Detail(
|
ThrowsCardUio.Detail(
|
||||||
title = action,
|
title = action,
|
||||||
|
|
@ -799,18 +800,21 @@ class DiceThrowUseCase @Inject constructor(
|
||||||
// fetch and build the associated characteristic
|
// fetch and build the associated characteristic
|
||||||
val relatedStatBonus = spell?.effect.statBonus(name = spellName)
|
val relatedStatBonus = spell?.effect.statBonus(name = spellName)
|
||||||
|
|
||||||
|
// compute the final roll result
|
||||||
|
val rollResult = "${allValue.sum()}"
|
||||||
|
|
||||||
// build the result.
|
// build the result.
|
||||||
return DiceThrowResult(
|
return DiceThrowResult(
|
||||||
dice = RollDiceUio(
|
dice = RollDiceUio(
|
||||||
icon = (spell?.effect?.faces ?: 4).icon,
|
icon = (spell?.effect?.faces ?: 4).icon,
|
||||||
result = "${result.value}",
|
result = rollResult,
|
||||||
),
|
),
|
||||||
card = ThrowsCardUio(
|
card = ThrowsCardUio(
|
||||||
title = titleString.uppercase(),
|
title = titleString.uppercase(),
|
||||||
highlight = spellName,
|
highlight = spellName,
|
||||||
dice = (spell?.effect?.faces ?: 4).icon,
|
dice = (spell?.effect?.faces ?: 4).icon,
|
||||||
roll = allValue.toLabel(),
|
roll = allValue.toLabel(),
|
||||||
result = "${allValue.sum()}",
|
result = rollResult,
|
||||||
details = listOf(
|
details = listOf(
|
||||||
ThrowsCardUio.Detail(
|
ThrowsCardUio.Detail(
|
||||||
title = spellName,
|
title = spellName,
|
||||||
|
|
@ -852,18 +856,21 @@ class DiceThrowUseCase @Inject constructor(
|
||||||
// fetch and build the associated characteristic, proficiency or level
|
// fetch and build the associated characteristic, proficiency or level
|
||||||
val relatedStatBonus = skill?.effect.statBonus(name = skill?.name)
|
val relatedStatBonus = skill?.effect.statBonus(name = skill?.name)
|
||||||
|
|
||||||
|
// compute the final roll result
|
||||||
|
val rollResult = "${allValue.sum()}"
|
||||||
|
|
||||||
// build the result.
|
// build the result.
|
||||||
return DiceThrowResult(
|
return DiceThrowResult(
|
||||||
dice = RollDiceUio(
|
dice = RollDiceUio(
|
||||||
icon = (skill?.effect?.faces ?: 4).icon,
|
icon = (skill?.effect?.faces ?: 4).icon,
|
||||||
result = "${result.value}",
|
result = rollResult,
|
||||||
),
|
),
|
||||||
card = ThrowsCardUio(
|
card = ThrowsCardUio(
|
||||||
title = titleString.uppercase(),
|
title = titleString.uppercase(),
|
||||||
highlight = spellName,
|
highlight = spellName,
|
||||||
dice = (skill?.effect?.faces ?: 4).icon,
|
dice = (skill?.effect?.faces ?: 4).icon,
|
||||||
roll = allValue.toLabel(),
|
roll = allValue.toLabel(),
|
||||||
result = "${allValue.sum()}",
|
result = rollResult,
|
||||||
details = listOf(
|
details = listOf(
|
||||||
ThrowsCardUio.Detail(
|
ThrowsCardUio.Detail(
|
||||||
title = spellName,
|
title = spellName,
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,6 @@ class AlterationParser @Inject constructor(
|
||||||
private val TARGET = column("Cible")
|
private val TARGET = column("Cible")
|
||||||
private val SOURCE = column("Source")
|
private val SOURCE = column("Source")
|
||||||
private val COLUMNS
|
private val COLUMNS
|
||||||
get() = listOf(SOURCE, TARGET) + Property.values().map { column(it.key) }
|
get() = listOf(SOURCE, TARGET) + Property.entries.map { column(it.key) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ import androidx.compose.animation.AnimatedContent
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.ContentTransform
|
import androidx.compose.animation.ContentTransform
|
||||||
import androidx.compose.animation.SizeTransform
|
import androidx.compose.animation.SizeTransform
|
||||||
|
import androidx.compose.animation.core.animateDpAsState
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
import androidx.compose.animation.fadeOut
|
import androidx.compose.animation.fadeOut
|
||||||
import androidx.compose.animation.slideInVertically
|
import androidx.compose.animation.slideInVertically
|
||||||
|
|
@ -48,6 +49,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.composed
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.res.stringResource
|
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.PreviewParameter
|
||||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||||
import androidx.compose.ui.unit.Density
|
import androidx.compose.ui.unit.Density
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.LayoutDirection
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.Dialog
|
import androidx.compose.ui.window.Dialog
|
||||||
|
|
@ -251,7 +254,7 @@ private fun RollOverlayContent(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(alignment = Alignment.Center)
|
.align(alignment = Alignment.Center)
|
||||||
.padding(horizontal = 16.dp)
|
.padding(horizontal = 16.dp)
|
||||||
.padding(bottom = 128.dp),
|
.detailPaddingBottom(showDetail = showDetail, bottom = 128.dp),
|
||||||
dice = dice,
|
dice = dice,
|
||||||
onDice = onDice,
|
onDice = onDice,
|
||||||
)
|
)
|
||||||
|
|
@ -300,6 +303,20 @@ private fun RollOverlayContent(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Modifier.detailPaddingBottom(
|
||||||
|
showDetail: State<Boolean>,
|
||||||
|
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
|
@Composable
|
||||||
private fun AlterationDetailHandler(
|
private fun AlterationDetailHandler(
|
||||||
detail: State<AlterationDetailUio?>,
|
detail: State<AlterationDetailUio?>,
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ class RollOverlayViewModel @Inject constructor(
|
||||||
private val _card = mutableStateOf<ThrowsCardUio?>(null)
|
private val _card = mutableStateOf<ThrowsCardUio?>(null)
|
||||||
val card: State<ThrowsCardUio?> get() = _card
|
val card: State<ThrowsCardUio?> get() = _card
|
||||||
|
|
||||||
private val _showDetail = mutableStateOf(true)
|
private val _showDetail = mutableStateOf(false)
|
||||||
val showDetail: State<Boolean> get() = _showDetail
|
val showDetail: State<Boolean> get() = _showDetail
|
||||||
|
|
||||||
private val _alterationDetail = mutableStateOf<AlterationDetailUio?>(null)
|
private val _alterationDetail = mutableStateOf<AlterationDetailUio?>(null)
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ fun ThrowsCard(
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
modifier = Modifier.widthIn(min = resultWidth),
|
modifier = Modifier.widthIn(min = resultWidth),
|
||||||
style = MaterialTheme.typography.displayMedium,
|
style = MaterialTheme.typography.displaySmall,
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
color = when {
|
color = when {
|
||||||
throws.isCriticalSuccess -> MaterialTheme.colorScheme.primary
|
throws.isCriticalSuccess -> MaterialTheme.colorScheme.primary
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ class AlterationFactory @Inject constructor(
|
||||||
is DiceThrow.PhysicalMeleeAttack -> {
|
is DiceThrow.PhysicalMeleeAttack -> {
|
||||||
val action = actionRepository.find(
|
val action = actionRepository.find(
|
||||||
character = diceThrow.character,
|
character = diceThrow.character,
|
||||||
action = diceThrow.weapon
|
action = diceThrow.weapon,
|
||||||
)
|
)
|
||||||
listOf(Property.PHYSICAL_MELEE_ATTACK) + (action?.hit?.modifier ?: emptyList())
|
listOf(Property.PHYSICAL_MELEE_ATTACK) + (action?.hit?.modifier ?: emptyList())
|
||||||
}
|
}
|
||||||
|
|
@ -75,7 +75,7 @@ class AlterationFactory @Inject constructor(
|
||||||
is DiceThrow.PhysicalMeleeDamage -> {
|
is DiceThrow.PhysicalMeleeDamage -> {
|
||||||
val action = actionRepository.find(
|
val action = actionRepository.find(
|
||||||
character = diceThrow.character,
|
character = diceThrow.character,
|
||||||
action = diceThrow.weapon
|
action = diceThrow.weapon,
|
||||||
)
|
)
|
||||||
listOf(Property.PHYSICAL_MELEE_DAMAGE) + (action?.damage?.modifier ?: emptyList())
|
listOf(Property.PHYSICAL_MELEE_DAMAGE) + (action?.damage?.modifier ?: emptyList())
|
||||||
}
|
}
|
||||||
|
|
@ -83,17 +83,15 @@ class AlterationFactory @Inject constructor(
|
||||||
is DiceThrow.PhysicalRangeAttack -> {
|
is DiceThrow.PhysicalRangeAttack -> {
|
||||||
val action = actionRepository.find(
|
val action = actionRepository.find(
|
||||||
character = diceThrow.character,
|
character = diceThrow.character,
|
||||||
action = diceThrow.weapon
|
action = diceThrow.weapon,
|
||||||
)
|
)
|
||||||
listOf(Property.PHYSICAL_RANGE_ATTACK) + (action?.hit?.modifier ?: emptyList())
|
listOf(Property.PHYSICAL_RANGE_ATTACK) + (action?.hit?.modifier ?: emptyList())
|
||||||
}
|
}
|
||||||
|
|
||||||
is DiceThrow.Object -> emptyList()
|
|
||||||
|
|
||||||
is DiceThrow.PhysicalRangeDamage -> {
|
is DiceThrow.PhysicalRangeDamage -> {
|
||||||
val action = actionRepository.find(
|
val action = actionRepository.find(
|
||||||
character = diceThrow.character,
|
character = diceThrow.character,
|
||||||
action = diceThrow.weapon
|
action = diceThrow.weapon,
|
||||||
)
|
)
|
||||||
listOf(Property.PHYSICAL_RANGE_DAMAGE) + (action?.damage?.modifier ?: emptyList())
|
listOf(Property.PHYSICAL_RANGE_DAMAGE) + (action?.damage?.modifier ?: emptyList())
|
||||||
}
|
}
|
||||||
|
|
@ -101,7 +99,7 @@ class AlterationFactory @Inject constructor(
|
||||||
is DiceThrow.SpellAttack -> {
|
is DiceThrow.SpellAttack -> {
|
||||||
val spell = spellRepository.findAssignedSpell(
|
val spell = spellRepository.findAssignedSpell(
|
||||||
character = diceThrow.character,
|
character = diceThrow.character,
|
||||||
spell = diceThrow.spell
|
spell = diceThrow.spell,
|
||||||
)
|
)
|
||||||
listOf(Property.SPELL_ATTACK) + (spell?.hit?.modifier ?: emptyList())
|
listOf(Property.SPELL_ATTACK) + (spell?.hit?.modifier ?: emptyList())
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +107,7 @@ class AlterationFactory @Inject constructor(
|
||||||
is DiceThrow.SpellDamage -> {
|
is DiceThrow.SpellDamage -> {
|
||||||
val spell = spellRepository.findAssignedSpell(
|
val spell = spellRepository.findAssignedSpell(
|
||||||
character = diceThrow.character,
|
character = diceThrow.character,
|
||||||
spell = diceThrow.spell
|
spell = diceThrow.spell,
|
||||||
)
|
)
|
||||||
listOf(Property.SPELL_DAMAGE) + (spell?.effect?.modifier ?: emptyList())
|
listOf(Property.SPELL_DAMAGE) + (spell?.effect?.modifier ?: emptyList())
|
||||||
}
|
}
|
||||||
|
|
@ -117,16 +115,20 @@ class AlterationFactory @Inject constructor(
|
||||||
is DiceThrow.SpellEffect -> {
|
is DiceThrow.SpellEffect -> {
|
||||||
val spell = spellRepository.findAssignedSpell(
|
val spell = spellRepository.findAssignedSpell(
|
||||||
character = diceThrow.character,
|
character = diceThrow.character,
|
||||||
spell = diceThrow.spell
|
spell = diceThrow.spell,
|
||||||
)
|
)
|
||||||
spell?.effect?.modifier ?: emptyList()
|
spell?.effect?.modifier ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
is DiceThrow.Skill -> {
|
is DiceThrow.Skill -> {
|
||||||
val skill =
|
val skill = skillRepository.find(
|
||||||
skillRepository.find(character = diceThrow.character, skill = diceThrow.skill)
|
character = diceThrow.character,
|
||||||
|
skill = diceThrow.skill,
|
||||||
|
)
|
||||||
listOf(Property.SKILL) + (skill?.effect?.modifier ?: emptyList())
|
listOf(Property.SKILL) + (skill?.effect?.modifier ?: emptyList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is DiceThrow.Object -> emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
return alterationRepository
|
return alterationRepository
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue