Skip to content

Commit

Permalink
feat(character): add leveled congenital traits
Browse files Browse the repository at this point in the history
relates to #7
  • Loading branch information
Patrick Hoefer committed Dec 30, 2020
1 parent 7606e60 commit 1f0f0b8
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class TraitSelection {
}

interface RankedTrait : Trait
interface LeveledTrait : Trait

enum class LeveledCongenitalTrait(override val code: String, override val label: String) : LeveledTrait {
BEAUTY("beauty", "Beauty"),
INTELLECT("intellect", "Intellect"),
PHYSIQUE("physique", "Physique"),
}

enum class CongenitalTrait(override val code: String, override val label: String) : Trait {
MELANCHOLIC("depressed", "Melancholic"),
Expand Down Expand Up @@ -128,6 +135,15 @@ class TraitSelection {
}
}

@Composable
fun LeveledCongenitalTraits(selectionState: SnapshotStateMap<LeveledTrait, Int>) {
Row {
TraitIcon(LeveledCongenitalTrait.BEAUTY, selectionState)
TraitIcon(LeveledCongenitalTrait.INTELLECT, selectionState)
TraitIcon(LeveledCongenitalTrait.PHYSIQUE, selectionState)
}
}

@Composable
fun CongenitalTraits(
selectionState: SnapshotStateMap<Trait, Boolean>
Expand All @@ -142,6 +158,31 @@ class TraitSelection {
}
}

@Composable
private fun TraitIcon(
leveledTrait: LeveledTrait,
selectionState: SnapshotStateMap<LeveledTrait, Int>
) {
var level by remember { mutableStateOf(0) }
var selectionModifier by remember { mutableStateOf(Modifier.alpha(0.2F)) }

Box(
Modifier.clickable(
onClick = {
level = levelup(level)
selectionState[leveledTrait] = level
selectionModifier = if (level == 0) Modifier.alpha(0.2F) else Modifier.alpha(1F)
}
),
contentAlignment = Alignment.Center,
) {
Image(
modifier = selectionModifier.size(70.dp, 70.dp),
bitmap = traitImage(leveledTrait, level)
)
}
}

@Composable
private fun TraitIcon(
rankedTrait: RankedTrait,
Expand Down Expand Up @@ -171,6 +212,10 @@ class TraitSelection {
return if (rank < 4) rank.plus(1) else 0
}

private fun levelup(level: Int): Int {
return if (level < 6) level.plus(1) else 0
}

@Composable
private fun TraitIcon(
trait: Trait,
Expand Down Expand Up @@ -227,11 +272,21 @@ class TraitSelection {
return imageFromResource(rankedIconPath(rankedTrait.code, theRank))
}

private fun traitImage(leveledTrait: LeveledTrait, level: Int): ImageBitmap {
val theLevel = if (level == 0) 1 else level
return imageFromResource(leveledIconPath(leveledTrait.code, theLevel))
}

private fun iconPath(traitCode: String): String {
return "$traitIconPath/trait_$traitCode.png"
}

private fun rankedIconPath(traitCode: String, rank: Int): String {
return "$traitIconPath/trait_${traitCode}_$rank.png"
}

private fun leveledIconPath(traitCode: String, level: Int): String {
return "$traitIconPath/trait_${traitCode}_$level.png"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fun CharacterCreateView() {
val personalityTraitSelectionState = remember { mutableStateMapOf<TraitSelection.Trait, Boolean>() }
val congenitalTraitSelectionState = remember { mutableStateMapOf<TraitSelection.Trait, Boolean>() }
val educationalTraitSelectionState = remember { mutableStateMapOf<TraitSelection.RankedTrait, Int>() }
val leveledCongenitalTraitSelectionState = remember { mutableStateMapOf<TraitSelection.LeveledTrait, Int>() }

Column(
modifier = Modifier.padding(top = 15.dp, bottom = 7.dp).fillMaxSize(),
Expand Down Expand Up @@ -69,7 +70,7 @@ fun CharacterCreateView() {
Text("Congenital Traits")
traitSelection.CongenitalTraits(congenitalTraitSelectionState)
Text("Leveled Congenital Traits")
traitSelection.EducationalTraits(educationalTraitSelectionState)
traitSelection.LeveledCongenitalTraits(leveledCongenitalTraitSelectionState)
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1f0f0b8

Please sign in to comment.