Skip to content

Commit

Permalink
Merge branch 'feat/skill-fixes' into 'master'
Browse files Browse the repository at this point in the history
Character item fixes

See merge request fmasa/wfrp-master!202
  • Loading branch information
fmasa committed Apr 6, 2021
2 parents 5db3748 + 2d608c0 commit 28c7ceb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class FirestoreInventoryItemRepository(
private val parties = firestore.collection(COLLECTION_PARTIES)

override fun findAllForCharacter(characterId: CharacterId) = queryFlow(
inventoryItems(characterId),
inventoryItems(characterId).orderBy("name"),
mapper,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class FirestoreSkillRepository(
private val mapper: AggregateMapper<Skill>
) : SkillRepository {
override fun forCharacter(characterId: CharacterId): Flow<List<Skill>> =
queryFlow(skillsCollection(characterId), mapper)
queryFlow(skillsCollection(characterId).orderBy("name"), mapper)

override suspend fun findByCompendiumId(
characterId: CharacterId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class FirestoreSpellRepository(
private val mapper: AggregateMapper<Spell>
) : SpellRepository {
override fun findAllForCharacter(characterId: CharacterId) = queryFlow(
spellsCollection(characterId),
spellsCollection(characterId).orderBy("name"),
mapper,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class FirestoreTalentRepository(
private val mapper: AggregateMapper<Talent>
) : TalentRepository {
override fun findAllForCharacter(characterId: CharacterId) = queryFlow(
talentsCollection(characterId),
talentsCollection(characterId).orderBy("name"),
mapper,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ fun AddSkillDialog(viewModel: SkillsViewModel, onDismissRequest: () -> Unit) {
ChoosingCompendiumSkill ->
CompendiumSkillChooser(
viewModel = viewModel,
onSkillSelected = { state = FillingInAdvances(it.id) },
onSkillSelected = { state = FillingInAdvances(it.id, it.advanced) },
onCustomSkillRequest = { state = FillingInCustomSkill },
onDismissRequest = onDismissRequest,
)
is FillingInAdvances ->
AdvancesForm(
compendiumSkillId = currentState.compendiumSkillId,
viewModel = viewModel,
isAdvanced = currentState.isAdvanced,
onDismissRequest = onDismissRequest,
)
is FillingInCustomSkill -> NonCompendiumSkillForm(
Expand All @@ -45,7 +46,10 @@ fun AddSkillDialog(viewModel: SkillsViewModel, onDismissRequest: () -> Unit) {
private sealed class AddSkillDialogState : Parcelable

@Parcelize
private class FillingInAdvances(val compendiumSkillId: UUID) : AddSkillDialogState()
private class FillingInAdvances(
val compendiumSkillId: UUID,
val isAdvanced: Boolean,
) : AddSkillDialogState()

@Parcelize
private object ChoosingCompendiumSkill : AddSkillDialogState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import java.util.*
internal fun AdvancesForm(
compendiumSkillId: UUID,
viewModel: SkillsViewModel,
isAdvanced: Boolean,
onDismissRequest: () -> Unit,
) {
var saving by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -97,11 +98,14 @@ internal fun AdvancesForm(
text = stringResource(R.string.label_advances),
modifier = Modifier.weight(1f),
)

val minAdvances = if (isAdvanced) 1 else 0

NumberPicker(
value = advances,
onIncrement = { advances++ },
onDecrement = {
if (advances > 1) {
if (advances > minAdvances) {
advances--
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ fun SkillDetail(
}
) {
Column(Modifier.verticalScroll(rememberScrollState())) {
AdvancesBar(skill.advances, onAdvancesChange)
AdvancesBar(
advances = skill.advances,
minAdvances = if (skill.advanced) 1 else 0,
onAdvancesChange = onAdvancesChange,
)

Column(Modifier.padding(Spacing.bodyPadding)) {
SingleLineTextValue(
Expand All @@ -59,7 +63,11 @@ fun SkillDetail(
}

@Composable
private fun AdvancesBar(advances: Int, onAdvancesChange: (advances: Int) -> Unit) {
private fun AdvancesBar(
advances: Int,
minAdvances: Int,
onAdvancesChange: (advances: Int) -> Unit
) {
SubheadBar {
Row(
Modifier.fillMaxWidth(),
Expand All @@ -71,7 +79,7 @@ private fun AdvancesBar(advances: Int, onAdvancesChange: (advances: Int) -> Unit
value = advances,
onIncrement = { onAdvancesChange(advances + 1) },
onDecrement = {
if (advances > 1) {
if (advances > minAdvances) {
onAdvancesChange(advances - 1)
}
}
Expand Down

0 comments on commit 28c7ceb

Please sign in to comment.