Fix an missing used status on skill that id change.
This commit is contained in:
parent
560d7653a7
commit
a909855fd5
4 changed files with 32 additions and 22 deletions
|
|
@ -4,6 +4,7 @@ import com.pixelized.desktop.lwa.ui.composable.tooltip.BasicTooltipUio
|
|||
import com.pixelized.desktop.lwa.ui.screen.campaign.player.ribbon.common.CharacterRibbonAlterationUio
|
||||
import com.pixelized.desktop.lwa.ui.screen.campaign.player.ribbon.common.CharacterRibbonPortraitUio
|
||||
import com.pixelized.desktop.lwa.ui.screen.campaign.player.ribbon.common.CharacterRibbonUio
|
||||
import com.pixelized.desktop.lwa.utils.extention.foldInto
|
||||
import com.pixelized.shared.lwa.model.AlteredCharacterSheetFactory
|
||||
import com.pixelized.shared.lwa.model.alteration.Alteration
|
||||
import com.pixelized.shared.lwa.model.alteration.FieldAlteration
|
||||
|
|
@ -47,7 +48,7 @@ class CharacterRibbonFactory(
|
|||
)
|
||||
},
|
||||
),
|
||||
status = takeIf { enableCharacterStats }?.let {
|
||||
status = takeIf { enableCharacterStatus }?.let {
|
||||
alterations.map { alteration ->
|
||||
CharacterRibbonAlterationUio(
|
||||
icon = alteration.metadata.icon ?: DEFAULT_ICON,
|
||||
|
|
@ -56,13 +57,8 @@ class CharacterRibbonFactory(
|
|||
description = alteration.metadata.description,
|
||||
),
|
||||
)
|
||||
}.fold(
|
||||
initial = mutableListOf<MutableList<CharacterRibbonAlterationUio>>(),
|
||||
operation = { acc, item ->
|
||||
if (acc.isEmpty() || acc.last().size == 5) acc.add(mutableListOf())
|
||||
acc.last().add(item)
|
||||
acc
|
||||
}
|
||||
}.foldInto(
|
||||
size = 5,
|
||||
)
|
||||
} ?: emptyList(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -153,9 +153,6 @@ class GMCharacterEditFactory(
|
|||
commonSkills = form.commonSkills.map { editedSkill ->
|
||||
val skillId: String = editedSkill.id.unpack()
|
||||
?: error("Missing skill id")
|
||||
val currentSkill = sheet?.commonSkills?.firstOrNull {
|
||||
it.id == skillId
|
||||
}
|
||||
CharacterSheet.Skill(
|
||||
id = skillId,
|
||||
label = editedSkill.label.unpack()
|
||||
|
|
@ -167,15 +164,12 @@ class GMCharacterEditFactory(
|
|||
bonus = editedSkill.bonus.unpack(),
|
||||
level = editedSkill.level.unpack() ?: 1,
|
||||
occupation = editedSkill.occupation.checked.value,
|
||||
used = currentSkill?.used ?: false,
|
||||
used = editedSkill.used,
|
||||
)
|
||||
},
|
||||
specialSkills = form.specialSkills.map { editedSkill ->
|
||||
val skillId: String = editedSkill.id.unpack()
|
||||
?: error("Missing skill id")
|
||||
val currentSkill = sheet?.commonSkills?.firstOrNull {
|
||||
it.id == skillId
|
||||
}
|
||||
CharacterSheet.Skill(
|
||||
id = skillId,
|
||||
label = editedSkill.label.unpack()
|
||||
|
|
@ -185,15 +179,13 @@ class GMCharacterEditFactory(
|
|||
bonus = editedSkill.bonus.unpack(),
|
||||
level = editedSkill.level.unpack() ?: 1,
|
||||
occupation = editedSkill.occupation.checked.value,
|
||||
used = currentSkill?.used ?: false,
|
||||
used = editedSkill.used,
|
||||
)
|
||||
},
|
||||
magicSkills = form.magicSkills.map { editedSkill ->
|
||||
val skillId: String = editedSkill.id.unpack()
|
||||
?: error("Missing skill id")
|
||||
val currentSkill = sheet?.commonSkills?.firstOrNull {
|
||||
it.id == skillId
|
||||
}
|
||||
|
||||
CharacterSheet.Skill(
|
||||
id = skillId,
|
||||
label = editedSkill.label.unpack()
|
||||
|
|
@ -203,7 +195,7 @@ class GMCharacterEditFactory(
|
|||
bonus = editedSkill.bonus.unpack(),
|
||||
level = editedSkill.level.unpack() ?: 1,
|
||||
occupation = editedSkill.occupation.checked.value,
|
||||
used = currentSkill?.used ?: false,
|
||||
used = editedSkill.used,
|
||||
)
|
||||
},
|
||||
actions = form.actions.map {
|
||||
|
|
@ -392,7 +384,10 @@ class GMCharacterEditFactory(
|
|||
checkForError = { it.isNotBlank() && it.toIntOrNull() == null },
|
||||
),
|
||||
level = levelFlow.createLwaTextField(
|
||||
checkForError = { it.toIntOrNull() == null },
|
||||
checkForError = {
|
||||
val value = it.toIntOrNull()
|
||||
value == null || value < 1
|
||||
},
|
||||
),
|
||||
occupation = MutableStateFlow(skill.occupation).let { flow ->
|
||||
LwaCheckBoxUio(
|
||||
|
|
@ -407,6 +402,7 @@ class GMCharacterEditFactory(
|
|||
},
|
||||
)
|
||||
},
|
||||
used = skill.used,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -458,7 +454,10 @@ class GMCharacterEditFactory(
|
|||
checkForError = { it.isNotBlank() && it.toIntOrNull() == null },
|
||||
),
|
||||
level = levelFlow.createLwaTextField(
|
||||
checkForError = { it.toIntOrNull() == null },
|
||||
checkForError = {
|
||||
val value = it.toIntOrNull()
|
||||
value == null || value < 1
|
||||
},
|
||||
),
|
||||
occupation = LwaCheckBoxUio(
|
||||
enable = true,
|
||||
|
|
@ -471,6 +470,7 @@ class GMCharacterEditFactory(
|
|||
occupationFlow.value = it
|
||||
},
|
||||
),
|
||||
used = skill?.used ?: false
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ data class GMSkillFieldUio(
|
|||
val bonus: LwaTextFieldUio,
|
||||
val level: LwaTextFieldUio,
|
||||
val occupation: LwaCheckBoxUio,
|
||||
val used: Boolean,
|
||||
)
|
||||
|
||||
@Stable
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
package com.pixelized.desktop.lwa.utils.extention
|
||||
|
||||
fun <T> List<T>.foldInto(size: Int): List<List<T>> = fold(
|
||||
initial = mutableListOf<MutableList<T>>(),
|
||||
operation = { acc, item ->
|
||||
if (acc.isEmpty() || acc.last().size == size) {
|
||||
acc.add(mutableListOf())
|
||||
}
|
||||
acc.also {
|
||||
it.last().add(item)
|
||||
}
|
||||
}
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue