Simplify the UI for the warlock.
This commit is contained in:
parent
60c11e6192
commit
73428d4341
4 changed files with 87 additions and 27 deletions
|
|
@ -52,7 +52,8 @@ class SpellBookUseCase @Inject constructor(
|
|||
val spellList = entry.value.map {
|
||||
factory.toSpellUio(
|
||||
assignedSpell = it,
|
||||
characterSheet = character
|
||||
characterSheet = character,
|
||||
warlockSpellLevel = firstSpellSlot,
|
||||
)
|
||||
}
|
||||
header to spellList
|
||||
|
|
@ -77,7 +78,8 @@ class SpellBookUseCase @Inject constructor(
|
|||
val spellList = entry.value.map {
|
||||
factory.toSpellUio(
|
||||
assignedSpell = it,
|
||||
characterSheet = character
|
||||
characterSheet = character,
|
||||
warlockSpellLevel = null,
|
||||
)
|
||||
}
|
||||
header to spellList
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ data class SpellUio(
|
|||
val hit: Dice?,
|
||||
val effect: Dice?,
|
||||
val changeWithLevel: Boolean,
|
||||
val isWarlock: Boolean,
|
||||
val ritual: Boolean,
|
||||
) {
|
||||
class Dice(
|
||||
|
|
@ -180,25 +181,35 @@ fun Spell(
|
|||
)
|
||||
}
|
||||
spell.effect?.let { dice ->
|
||||
if (spell.changeWithLevel) {
|
||||
OutlinedButton(
|
||||
modifier = Modifier.padding(end = 8.dp),
|
||||
border = BorderStroke(
|
||||
width = 1.dp,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
),
|
||||
onClick = { onCast(spell.name) },
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.character_sheet_action_spell_cast),
|
||||
when {
|
||||
spell.changeWithLevel && spell.isWarlock.not() -> {
|
||||
OutlinedButton(
|
||||
modifier = Modifier.padding(end = 8.dp),
|
||||
border = BorderStroke(
|
||||
width = 1.dp,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
),
|
||||
onClick = { onCast(spell.name) },
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.character_sheet_action_spell_cast),
|
||||
)
|
||||
}
|
||||
}
|
||||
spell.changeWithLevel && spell.isWarlock -> {
|
||||
DiceButton(
|
||||
icon = dice.icon,
|
||||
text = dice.label,
|
||||
onClick = { onCast(spell.name) },
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
DiceButton(
|
||||
icon = dice.icon,
|
||||
text = dice.label,
|
||||
onClick = { spell.name.let(onEffect) }
|
||||
)
|
||||
}
|
||||
} else {
|
||||
DiceButton(
|
||||
icon = dice.icon,
|
||||
text = dice.label,
|
||||
onClick = { spell.name.let(onEffect) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -244,6 +255,7 @@ private class SpellPreviewProvider : PreviewParameterProvider<SpellUio> {
|
|||
label = "1d10",
|
||||
),
|
||||
changeWithLevel = false,
|
||||
isWarlock = false,
|
||||
ritual = false,
|
||||
),
|
||||
SpellUio(
|
||||
|
|
@ -260,6 +272,7 @@ private class SpellPreviewProvider : PreviewParameterProvider<SpellUio> {
|
|||
label = "1d4",
|
||||
),
|
||||
changeWithLevel = false,
|
||||
isWarlock = false,
|
||||
ritual = false,
|
||||
),
|
||||
SpellUio(
|
||||
|
|
@ -276,6 +289,24 @@ private class SpellPreviewProvider : PreviewParameterProvider<SpellUio> {
|
|||
label = "1d8+3",
|
||||
),
|
||||
changeWithLevel = true,
|
||||
isWarlock = false,
|
||||
ritual = true,
|
||||
),
|
||||
SpellUio(
|
||||
icon = null,
|
||||
school = Spell.School.EVOCATION,
|
||||
name = "Soins",
|
||||
translated = "Cure Wounds",
|
||||
castingTime = "1 action",
|
||||
range = "contact",
|
||||
duration = "instantanée",
|
||||
hit = null,
|
||||
effect = SpellUio.Dice(
|
||||
icon = R.drawable.ic_d8_24,
|
||||
label = "1d8+3",
|
||||
),
|
||||
changeWithLevel = true,
|
||||
isWarlock = true,
|
||||
ritual = true,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ fun rememberSpellListStatePreview(): State<List<Pair<SpellHeaderUio, List<SpellU
|
|||
label = "1d10",
|
||||
),
|
||||
changeWithLevel = false,
|
||||
isWarlock = false,
|
||||
ritual = true,
|
||||
),
|
||||
SpellUio(
|
||||
|
|
@ -55,6 +56,7 @@ fun rememberSpellListStatePreview(): State<List<Pair<SpellHeaderUio, List<SpellU
|
|||
label = "1d4",
|
||||
),
|
||||
changeWithLevel = false,
|
||||
isWarlock = false,
|
||||
ritual = false,
|
||||
),
|
||||
),
|
||||
|
|
@ -76,6 +78,7 @@ fun rememberSpellListStatePreview(): State<List<Pair<SpellHeaderUio, List<SpellU
|
|||
label = "1d8+3",
|
||||
),
|
||||
changeWithLevel = true,
|
||||
isWarlock = false,
|
||||
ritual = false,
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,22 +1,24 @@
|
|||
package com.pixelized.rplexicon.ui.screens.character.factory
|
||||
|
||||
import androidx.core.net.toUri
|
||||
import androidx.compose.animation.core.spring
|
||||
import com.pixelized.rplexicon.data.model.AssignedSpell
|
||||
import com.pixelized.rplexicon.data.model.CharacterSheet
|
||||
import com.pixelized.rplexicon.data.model.Property
|
||||
import com.pixelized.rplexicon.data.repository.character.DescriptionRepository
|
||||
import com.pixelized.rplexicon.ui.screens.character.composable.actions.SpellUio
|
||||
import com.pixelized.rplexicon.utilitary.extentions.icon
|
||||
import com.pixelized.rplexicon.utilitary.extentions.local.icon
|
||||
import com.pixelized.rplexicon.utilitary.extentions.modifier
|
||||
import com.pixelized.rplexicon.utilitary.extentions.uri
|
||||
import javax.inject.Inject
|
||||
|
||||
class SpellUioFactory @Inject constructor(
|
||||
private val descriptionRepository: DescriptionRepository,
|
||||
) {
|
||||
|
||||
fun toSpellUio(assignedSpell: AssignedSpell, characterSheet: CharacterSheet): SpellUio {
|
||||
fun toSpellUio(
|
||||
assignedSpell: AssignedSpell,
|
||||
characterSheet: CharacterSheet,
|
||||
warlockSpellLevel: Int?,
|
||||
): SpellUio {
|
||||
val hit = assignedSpell.hit?.let { dice ->
|
||||
val modifier = dice.modifier.sumOf {
|
||||
when (it) {
|
||||
|
|
@ -44,11 +46,32 @@ class SpellUioFactory @Inject constructor(
|
|||
Property.CHARISMA -> characterSheet.charisma.modifier
|
||||
else -> 0
|
||||
}
|
||||
} + dice.flat
|
||||
|
||||
val level = assignedSpell.level
|
||||
val delta = warlockSpellLevel?.minus(assignedSpell.spell.level) ?: 0
|
||||
if (warlockSpellLevel == null || level == null || delta <= 0) {
|
||||
// default case of non warlock character of the spell don't scale
|
||||
SpellUio.Dice(
|
||||
icon = dice.faces.icon,
|
||||
label = "${dice.amount}d${dice.faces}${if (modifier > 0) "+$modifier" else ""}",
|
||||
)
|
||||
} else {
|
||||
// warlock character, upscale the spell to warlock spell level
|
||||
if (dice.faces == level.faces) {
|
||||
val upscaleModifier = modifier + level.flat * delta
|
||||
SpellUio.Dice(
|
||||
icon = dice.faces.icon,
|
||||
label = "${dice.amount + level.amount * delta}d${dice.faces}${if (upscaleModifier > 0) "+$upscaleModifier" else ""}",
|
||||
)
|
||||
} else {
|
||||
SpellUio.Dice(
|
||||
icon = dice.faces.icon,
|
||||
label = "${dice.amount}d${dice.faces}${modifier.takeIf { it > 0 }?.let { "+$it" } ?: ""} + " +
|
||||
"${level.amount}d${level.faces * delta}${(level.flat * delta).takeIf { it > 0 }?.let { "+$it" } ?: ""}",
|
||||
)
|
||||
}
|
||||
}
|
||||
SpellUio.Dice(
|
||||
icon = dice.faces.icon,
|
||||
label = "${dice.amount}d${dice.faces}${if (modifier > 0) "+$modifier" else ""}",
|
||||
)
|
||||
}
|
||||
return SpellUio(
|
||||
icon = assignedSpell.spell.icon,
|
||||
|
|
@ -61,6 +84,7 @@ class SpellUioFactory @Inject constructor(
|
|||
hit = hit,
|
||||
effect = effect,
|
||||
changeWithLevel = assignedSpell.level != null,
|
||||
isWarlock = warlockSpellLevel != null,
|
||||
ritual = assignedSpell.spell.ritual,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue