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.CharacterRibbonAlterationUio
 | 
				
			||||||
import com.pixelized.desktop.lwa.ui.screen.campaign.player.ribbon.common.CharacterRibbonPortraitUio
 | 
					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.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.AlteredCharacterSheetFactory
 | 
				
			||||||
import com.pixelized.shared.lwa.model.alteration.Alteration
 | 
					import com.pixelized.shared.lwa.model.alteration.Alteration
 | 
				
			||||||
import com.pixelized.shared.lwa.model.alteration.FieldAlteration
 | 
					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 ->
 | 
					                alterations.map { alteration ->
 | 
				
			||||||
                    CharacterRibbonAlterationUio(
 | 
					                    CharacterRibbonAlterationUio(
 | 
				
			||||||
                        icon = alteration.metadata.icon ?: DEFAULT_ICON,
 | 
					                        icon = alteration.metadata.icon ?: DEFAULT_ICON,
 | 
				
			||||||
| 
						 | 
					@ -56,13 +57,8 @@ class CharacterRibbonFactory(
 | 
				
			||||||
                            description = alteration.metadata.description,
 | 
					                            description = alteration.metadata.description,
 | 
				
			||||||
                        ),
 | 
					                        ),
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
                }.fold(
 | 
					                }.foldInto(
 | 
				
			||||||
                    initial = mutableListOf<MutableList<CharacterRibbonAlterationUio>>(),
 | 
					                    size = 5,
 | 
				
			||||||
                    operation = { acc, item ->
 | 
					 | 
				
			||||||
                        if (acc.isEmpty() || acc.last().size == 5) acc.add(mutableListOf())
 | 
					 | 
				
			||||||
                        acc.last().add(item)
 | 
					 | 
				
			||||||
                        acc
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            } ?: emptyList(),
 | 
					            } ?: emptyList(),
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -153,9 +153,6 @@ class GMCharacterEditFactory(
 | 
				
			||||||
            commonSkills = form.commonSkills.map { editedSkill ->
 | 
					            commonSkills = form.commonSkills.map { editedSkill ->
 | 
				
			||||||
                val skillId: String = editedSkill.id.unpack()
 | 
					                val skillId: String = editedSkill.id.unpack()
 | 
				
			||||||
                    ?: error("Missing skill id")
 | 
					                    ?: error("Missing skill id")
 | 
				
			||||||
                val currentSkill = sheet?.commonSkills?.firstOrNull {
 | 
					 | 
				
			||||||
                    it.id == skillId
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                CharacterSheet.Skill(
 | 
					                CharacterSheet.Skill(
 | 
				
			||||||
                    id = skillId,
 | 
					                    id = skillId,
 | 
				
			||||||
                    label = editedSkill.label.unpack()
 | 
					                    label = editedSkill.label.unpack()
 | 
				
			||||||
| 
						 | 
					@ -167,15 +164,12 @@ class GMCharacterEditFactory(
 | 
				
			||||||
                    bonus = editedSkill.bonus.unpack(),
 | 
					                    bonus = editedSkill.bonus.unpack(),
 | 
				
			||||||
                    level = editedSkill.level.unpack() ?: 1,
 | 
					                    level = editedSkill.level.unpack() ?: 1,
 | 
				
			||||||
                    occupation = editedSkill.occupation.checked.value,
 | 
					                    occupation = editedSkill.occupation.checked.value,
 | 
				
			||||||
                    used = currentSkill?.used ?: false,
 | 
					                    used = editedSkill.used,
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            specialSkills = form.specialSkills.map { editedSkill ->
 | 
					            specialSkills = form.specialSkills.map { editedSkill ->
 | 
				
			||||||
                val skillId: String = editedSkill.id.unpack()
 | 
					                val skillId: String = editedSkill.id.unpack()
 | 
				
			||||||
                    ?: error("Missing skill id")
 | 
					                    ?: error("Missing skill id")
 | 
				
			||||||
                val currentSkill = sheet?.commonSkills?.firstOrNull {
 | 
					 | 
				
			||||||
                    it.id == skillId
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                CharacterSheet.Skill(
 | 
					                CharacterSheet.Skill(
 | 
				
			||||||
                    id = skillId,
 | 
					                    id = skillId,
 | 
				
			||||||
                    label = editedSkill.label.unpack()
 | 
					                    label = editedSkill.label.unpack()
 | 
				
			||||||
| 
						 | 
					@ -185,15 +179,13 @@ class GMCharacterEditFactory(
 | 
				
			||||||
                    bonus = editedSkill.bonus.unpack(),
 | 
					                    bonus = editedSkill.bonus.unpack(),
 | 
				
			||||||
                    level = editedSkill.level.unpack() ?: 1,
 | 
					                    level = editedSkill.level.unpack() ?: 1,
 | 
				
			||||||
                    occupation = editedSkill.occupation.checked.value,
 | 
					                    occupation = editedSkill.occupation.checked.value,
 | 
				
			||||||
                    used = currentSkill?.used ?: false,
 | 
					                    used = editedSkill.used,
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            magicSkills = form.magicSkills.map { editedSkill ->
 | 
					            magicSkills = form.magicSkills.map { editedSkill ->
 | 
				
			||||||
                val skillId: String = editedSkill.id.unpack()
 | 
					                val skillId: String = editedSkill.id.unpack()
 | 
				
			||||||
                    ?: error("Missing skill id")
 | 
					                    ?: error("Missing skill id")
 | 
				
			||||||
                val currentSkill = sheet?.commonSkills?.firstOrNull {
 | 
					
 | 
				
			||||||
                    it.id == skillId
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                CharacterSheet.Skill(
 | 
					                CharacterSheet.Skill(
 | 
				
			||||||
                    id = skillId,
 | 
					                    id = skillId,
 | 
				
			||||||
                    label = editedSkill.label.unpack()
 | 
					                    label = editedSkill.label.unpack()
 | 
				
			||||||
| 
						 | 
					@ -203,7 +195,7 @@ class GMCharacterEditFactory(
 | 
				
			||||||
                    bonus = editedSkill.bonus.unpack(),
 | 
					                    bonus = editedSkill.bonus.unpack(),
 | 
				
			||||||
                    level = editedSkill.level.unpack() ?: 1,
 | 
					                    level = editedSkill.level.unpack() ?: 1,
 | 
				
			||||||
                    occupation = editedSkill.occupation.checked.value,
 | 
					                    occupation = editedSkill.occupation.checked.value,
 | 
				
			||||||
                    used = currentSkill?.used ?: false,
 | 
					                    used = editedSkill.used,
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            actions = form.actions.map {
 | 
					            actions = form.actions.map {
 | 
				
			||||||
| 
						 | 
					@ -392,7 +384,10 @@ class GMCharacterEditFactory(
 | 
				
			||||||
                checkForError = { it.isNotBlank() && it.toIntOrNull() == null },
 | 
					                checkForError = { it.isNotBlank() && it.toIntOrNull() == null },
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
            level = levelFlow.createLwaTextField(
 | 
					            level = levelFlow.createLwaTextField(
 | 
				
			||||||
                checkForError = { it.toIntOrNull() == null },
 | 
					                checkForError = {
 | 
				
			||||||
 | 
					                    val value = it.toIntOrNull()
 | 
				
			||||||
 | 
					                    value == null || value < 1
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
            occupation = MutableStateFlow(skill.occupation).let { flow ->
 | 
					            occupation = MutableStateFlow(skill.occupation).let { flow ->
 | 
				
			||||||
                LwaCheckBoxUio(
 | 
					                LwaCheckBoxUio(
 | 
				
			||||||
| 
						 | 
					@ -407,6 +402,7 @@ class GMCharacterEditFactory(
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					            used = skill.used,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -458,7 +454,10 @@ class GMCharacterEditFactory(
 | 
				
			||||||
                checkForError = { it.isNotBlank() && it.toIntOrNull() == null },
 | 
					                checkForError = { it.isNotBlank() && it.toIntOrNull() == null },
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
            level = levelFlow.createLwaTextField(
 | 
					            level = levelFlow.createLwaTextField(
 | 
				
			||||||
                checkForError = { it.toIntOrNull() == null },
 | 
					                checkForError = {
 | 
				
			||||||
 | 
					                    val value = it.toIntOrNull()
 | 
				
			||||||
 | 
					                    value == null || value < 1
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
            occupation = LwaCheckBoxUio(
 | 
					            occupation = LwaCheckBoxUio(
 | 
				
			||||||
                enable = true,
 | 
					                enable = true,
 | 
				
			||||||
| 
						 | 
					@ -471,6 +470,7 @@ class GMCharacterEditFactory(
 | 
				
			||||||
                    occupationFlow.value = it
 | 
					                    occupationFlow.value = it
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
 | 
					            used = skill?.used ?: false
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,6 +43,7 @@ data class GMSkillFieldUio(
 | 
				
			||||||
    val bonus: LwaTextFieldUio,
 | 
					    val bonus: LwaTextFieldUio,
 | 
				
			||||||
    val level: LwaTextFieldUio,
 | 
					    val level: LwaTextFieldUio,
 | 
				
			||||||
    val occupation: LwaCheckBoxUio,
 | 
					    val occupation: LwaCheckBoxUio,
 | 
				
			||||||
 | 
					    val used: Boolean,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Stable
 | 
					@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