From 0f3d3b8300193823f260f6abb9bd546731911c87 Mon Sep 17 00:00:00 2001 From: Thomas Andres Gomez Date: Tue, 10 Oct 2023 09:48:31 +0200 Subject: [PATCH] Add Alteration display in the ProficiencyPage. --- .../repository/parser/DescriptionParser.kt | 6 +- .../factory/CharacterSheetUioFactory.kt | 85 ++++++++++--------- 2 files changed, 50 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/com/pixelized/rplexicon/repository/parser/DescriptionParser.kt b/app/src/main/java/com/pixelized/rplexicon/repository/parser/DescriptionParser.kt index e949086..db07a88 100644 --- a/app/src/main/java/com/pixelized/rplexicon/repository/parser/DescriptionParser.kt +++ b/app/src/main/java/com/pixelized/rplexicon/repository/parser/DescriptionParser.kt @@ -23,9 +23,9 @@ class DescriptionParser @Inject constructor() { } item is List<*> -> { - val name = item[structure.getValue(NAME)] as? String - val translate = item[structure.getValue(TRANSLATE)] as? String - val description = item[structure.getValue(DESCRIPTION)] as? String + val name = item.getOrNull(structure.getValue(NAME)) as? String + val translate = item.getOrNull(structure.getValue(TRANSLATE)) as? String + val description = item.getOrNull(structure.getValue(DESCRIPTION)) as? String if (name != null && translate != null && description != null) { values[name] = Description( diff --git a/app/src/main/java/com/pixelized/rplexicon/ui/screens/character/factory/CharacterSheetUioFactory.kt b/app/src/main/java/com/pixelized/rplexicon/ui/screens/character/factory/CharacterSheetUioFactory.kt index bc459f7..f07ee01 100644 --- a/app/src/main/java/com/pixelized/rplexicon/ui/screens/character/factory/CharacterSheetUioFactory.kt +++ b/app/src/main/java/com/pixelized/rplexicon/ui/screens/character/factory/CharacterSheetUioFactory.kt @@ -8,6 +8,7 @@ import com.pixelized.rplexicon.ui.screens.character.composable.character.LabelPo import com.pixelized.rplexicon.ui.screens.character.composable.character.ProficiencyUio import com.pixelized.rplexicon.ui.screens.character.composable.character.StatUio import com.pixelized.rplexicon.ui.screens.character.pages.proficiency.CharacterSheetUio +import com.pixelized.rplexicon.utilitary.extentions.local.sum import com.pixelized.rplexicon.utilitary.extentions.modifier import com.pixelized.rplexicon.utilitary.extentions.toLabel import javax.inject.Inject @@ -16,168 +17,176 @@ class CharacterSheetUioFactory @Inject constructor() { fun convert( sheet: CharacterSheet, - alterations: Map>, // TODO use this param to reflect on the character sheet + alterations: Map>, ): CharacterSheetUio { + val proficiency = (sheet.proficiency + alterations[Property.PROFICIENCY].sum) + val strength = sheet.strength + alterations[Property.STRENGTH].sum + val dexterity = sheet.dexterity + alterations[Property.DEXTERITY].sum + val constitution = sheet.constitution + alterations[Property.CONSTITUTION].sum + val intelligence = sheet.intelligence + alterations[Property.INTELLIGENCE].sum + val wisdom = sheet.wisdom + alterations[Property.WISDOM].sum + val charisma = sheet.charisma + alterations[Property.CHARISMA].sum + return CharacterSheetUio( initiative = LabelPointUio( label = R.string.character_sheet_title_initiative, - value = sheet.dexterity.modifier.toLabel(), + value = (dexterity.modifier + alterations[Property.INITIATIVE].sum).toLabel(), max = null, ), stats = listOf( StatUio( id = StatUio.ID.STRENGTH, - value = sheet.strength, - modifier = sheet.strength.modifier, + value = strength, + modifier = strength.modifier + alterations[Property.STRENGTH_THROW].sum, ), StatUio( id = StatUio.ID.DEXTERITY, - value = sheet.dexterity, - modifier = sheet.dexterity.modifier, + value = dexterity, + modifier = dexterity.modifier + alterations[Property.DEXTERITY_THROW].sum, ), StatUio( id = StatUio.ID.CONSTITUTION, - value = sheet.constitution, - modifier = sheet.constitution.modifier, + value = constitution, + modifier = constitution.modifier + alterations[Property.CONSTITUTION_THROW].sum, ), StatUio( id = StatUio.ID.INTELLIGENCE, - value = sheet.intelligence, - modifier = sheet.intelligence.modifier, + value = intelligence, + modifier = intelligence.modifier + alterations[Property.INTELLIGENCE_THROW].sum, ), StatUio( id = StatUio.ID.WISDOM, - value = sheet.wisdom, - modifier = sheet.wisdom.modifier, + value = wisdom, + modifier = wisdom.modifier + alterations[Property.WISDOM_THROW].sum, ), StatUio( id = StatUio.ID.CHARISMA, - value = sheet.charisma, - modifier = sheet.charisma.modifier, + value = charisma, + modifier = charisma.modifier + alterations[Property.CHARISMA_THROW].sum, ), ), savingThrows = listOf( ProficiencyUio( id = ProficiencyUio.ID.STRENGTH_SAVING_THROW, multiplier = sheet.strengthSavingThrows, - modifier = sheet.strength.modifier + sheet.strengthSavingThrows * sheet.proficiency, + modifier = strength.modifier + alterations[Property.STRENGTH_SAVING_THROW].sum + sheet.strengthSavingThrows * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.DEXTERITY_SAVING_THROW, multiplier = sheet.dexteritySavingThrows, - modifier = sheet.dexterity.modifier + sheet.dexteritySavingThrows * sheet.proficiency, + modifier = dexterity.modifier + alterations[Property.DEXTERITY_SAVING_THROW].sum + sheet.dexteritySavingThrows * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.CONSTITUTION_SAVING_THROW, multiplier = sheet.constitutionSavingThrows, - modifier = sheet.constitution.modifier + sheet.constitutionSavingThrows * sheet.proficiency, + modifier = constitution.modifier + alterations[Property.CONSTITUTION_SAVING_THROW].sum + sheet.constitutionSavingThrows * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.INTELLIGENCE_SAVING_THROW, multiplier = sheet.intelligenceSavingThrows, - modifier = sheet.intelligence.modifier + sheet.intelligenceSavingThrows * sheet.proficiency, + modifier = intelligence.modifier + alterations[Property.INTELLIGENCE_SAVING_THROW].sum + sheet.intelligenceSavingThrows * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.WISDOM_SAVING_THROW, multiplier = sheet.wisdomSavingThrows, - modifier = sheet.wisdom.modifier + sheet.wisdomSavingThrows * sheet.proficiency, + modifier = wisdom.modifier + alterations[Property.WISDOM_SAVING_THROW].sum + sheet.wisdomSavingThrows * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.CHARISMA_SAVING_THROW, multiplier = sheet.charismaSavingThrows, - modifier = sheet.charisma.modifier + sheet.charismaSavingThrows * sheet.proficiency, + modifier = charisma.modifier + alterations[Property.CHARISMA_SAVING_THROW].sum + sheet.charismaSavingThrows * proficiency, ), ), proficiencies = listOf( ProficiencyUio( id = ProficiencyUio.ID.ACROBATICS, multiplier = sheet.acrobatics, - modifier = sheet.dexterity.modifier + sheet.acrobatics * sheet.proficiency, + modifier = dexterity.modifier + alterations[Property.ACROBATICS].sum + sheet.acrobatics * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.ARCANA, multiplier = sheet.arcana, - modifier = sheet.intelligence.modifier + sheet.arcana * sheet.proficiency, + modifier = intelligence.modifier + alterations[Property.ARCANA].sum + sheet.arcana * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.ATHLETICS, multiplier = sheet.athletics, - modifier = sheet.strength.modifier + sheet.athletics * sheet.proficiency, + modifier = strength.modifier + alterations[Property.ATHLETICS].sum + sheet.athletics * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.STEALTH, multiplier = sheet.stealth, - modifier = sheet.dexterity.modifier + sheet.stealth * sheet.proficiency, + modifier = dexterity.modifier + alterations[Property.STEALTH].sum + sheet.stealth * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.ANIMAL_HANDLING, multiplier = sheet.animalHandling, - modifier = sheet.wisdom.modifier + sheet.animalHandling * sheet.proficiency, + modifier = wisdom.modifier + alterations[Property.ANIMAL_HANDLING].sum + sheet.animalHandling * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.SLEIGHT_OF_HAND, multiplier = sheet.sleightOfHand, - modifier = sheet.dexterity.modifier + sheet.sleightOfHand * sheet.proficiency, + modifier = dexterity.modifier + alterations[Property.SLEIGHT_OF_HAND].sum + sheet.sleightOfHand * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.HISTORY, multiplier = sheet.history, - modifier = sheet.intelligence.modifier + sheet.history * sheet.proficiency, + modifier = intelligence.modifier + alterations[Property.HISTORY].sum + sheet.history * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.INTIMIDATION, multiplier = sheet.intimidation, - modifier = sheet.charisma.modifier + sheet.intimidation * sheet.proficiency, + modifier = charisma.modifier + alterations[Property.INTIMIDATION].sum + sheet.intimidation * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.INSIGHT, multiplier = sheet.insight, - modifier = sheet.wisdom.modifier + sheet.insight * sheet.proficiency, + modifier = wisdom.modifier + alterations[Property.INSIGHT].sum + sheet.insight * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.INVESTIGATION, multiplier = sheet.investigation, - modifier = sheet.intelligence.modifier + sheet.investigation * sheet.proficiency, + modifier = intelligence.modifier + alterations[Property.INVESTIGATION].sum + sheet.investigation * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.MEDICINE, multiplier = sheet.medicine, - modifier = sheet.wisdom.modifier + sheet.medicine * sheet.proficiency, + modifier = wisdom.modifier + alterations[Property.MEDICINE].sum + sheet.medicine * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.NATURE, multiplier = sheet.nature, - modifier = sheet.intelligence.modifier + sheet.nature * sheet.proficiency, + modifier = intelligence.modifier + alterations[Property.NATURE].sum + sheet.nature * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.PERCEPTION, multiplier = sheet.perception, - modifier = sheet.wisdom.modifier + sheet.perception * sheet.proficiency, + modifier = wisdom.modifier + alterations[Property.PERCEPTION].sum + sheet.perception * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.PERSUASION, multiplier = sheet.persuasion, - modifier = sheet.charisma.modifier + sheet.persuasion * sheet.proficiency, + modifier = charisma.modifier + alterations[Property.PERSUASION].sum + sheet.persuasion * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.RELIGION, multiplier = sheet.religion, - modifier = sheet.intelligence.modifier + sheet.religion * sheet.proficiency, + modifier = intelligence.modifier + alterations[Property.RELIGION].sum + sheet.religion * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.PERFORMANCE, multiplier = sheet.performance, - modifier = sheet.charisma.modifier + sheet.performance * sheet.proficiency, + modifier = charisma.modifier + alterations[Property.PERFORMANCE].sum + sheet.performance * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.SURVIVAL, multiplier = sheet.survival, - modifier = sheet.wisdom.modifier + sheet.survival * sheet.proficiency, + modifier = wisdom.modifier + alterations[Property.SURVIVAL].sum + sheet.survival * proficiency, ), ProficiencyUio( id = ProficiencyUio.ID.DECEPTION, multiplier = sheet.deception, - modifier = sheet.charisma.modifier + sheet.deception * sheet.proficiency, + modifier = charisma.modifier + alterations[Property.DECEPTION].sum + sheet.deception * proficiency, ), ), )