Skip to content

Commit

Permalink
feat(character): add commander traits
Browse files Browse the repository at this point in the history
relates to #7
  • Loading branch information
Patrick Hoefer committed Dec 31, 2020
1 parent 689061f commit 5838115
Show file tree
Hide file tree
Showing 33 changed files with 82 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,35 @@ class TraitSelection {
val label: String
}

interface RankedTrait : Trait
interface LeveledTrait : Trait

enum class CommanderTrait(override val code: String, override val label: String) : LeveledTrait {
AGGRESSIVE("aggressive_attacker", "Aggressive Attacker"),
FLEXIBLE("flexible_leader", "Flexible Leader"),
FORDER("forder", "Forder"),
HOLY_WARRIOR("holy_warrior", "Holy Warrior"),
LOGISTICIAN("logistician", "Logistician"),
MILITARY_ENGINEER("military_engineer", "Military Engineer"),
ORGANIZER("organizer", "Organizer"),
REAVER("reaver", "Reaver"),
DEFENDER("unyielding_defender", "Unyielding Defender"),
CAUTIOUS_LEADER("cautious_leader", "Cautious Leader"),
RECKLESS("reckless", "Reckless"),
FOREST_FIGHTER("forest_fighter", "Forest Fighter"),
OPEN_TERRAIN("open_terrain_expert", "Open Terrain Expert"),
ROUGH_TERRAIN("rough_terrain_expert", "Rough Terrain Expert"),
DESERT_WARRIOR("desert_warrior", "Desert Warrior"),
JUNGLE_STALKER("jungle_stalker", "Jungle Stalker"),
}

enum class LeveledLifestyleTrait(override val code: String, override val label: String) : LeveledTrait {
BLADEMASTER("blademaster", "Blademaster"),
HUNTER("hunter", "Hunter"),
MYSTIC("mystic", "Mystic"),
REVELER("reveler", "Reveler"),
PHYSICIAN("physician", "Physician"),
}

enum class LifestyleTrait(override val code: String, override val label: String) : Trait {
AUGUST("august", "August"),
DIPLOMAT("diplomat", "Diplomat"),
Expand Down Expand Up @@ -93,7 +119,7 @@ class TraitSelection {
BLEEDER("bleeder", "Bleeder"),
}

enum class EducationalTrait(override val code: String, override val label: String) : RankedTrait {
enum class EducationalTrait(override val code: String, override val label: String) : LeveledTrait {
DIPLOMACY("diplomacy", "Naive Appeaser"),
INTRIGUE("intrigue", "Amateurish Plotter"),
MARTIAL("martial", "Misguided Warrior"),
Expand Down Expand Up @@ -140,7 +166,21 @@ class TraitSelection {
}

@Composable
fun LifestyleTrait(
fun CommanderTraits(
selectionState: SnapshotStateMap<Trait, Boolean>
) {
val chunks = enumValues<CommanderTrait>().toList().chunked(6)
chunks.forEach {
Row {
it.forEach {
TraitIcon(it, selectionState)
}
}
}
}

@Composable
fun LifestyleTraits(
selectionState: SnapshotStateMap<Trait, Boolean>
) {
val chunks = enumValues<LifestyleTrait>().toList().chunked(6)
Expand Down Expand Up @@ -169,23 +209,30 @@ class TraitSelection {

@Composable
fun EducationalTraits(
selectionState: SnapshotStateMap<RankedTrait, Int>
selectionState: SnapshotStateMap<LeveledTrait, Int>
) {
Row {
TraitIcon(EducationalTrait.DIPLOMACY, selectionState)
TraitIcon(EducationalTrait.INTRIGUE, selectionState)
TraitIcon(EducationalTrait.STEWARDSHIP, selectionState)
TraitIcon(EducationalTrait.MARTIAL, selectionState)
TraitIcon(EducationalTrait.PROWESS, selectionState)
enumValues<EducationalTrait>().forEach { trait ->
TraitIcon(trait, selectionState, 4)
}
}
}

@Composable
fun LeveledLifestyleTraits(selectionState: SnapshotStateMap<LeveledTrait, Int>) {
Row {
enumValues<LeveledLifestyleTrait>().forEach { trait ->
TraitIcon(trait, selectionState, 3)
}
}
}

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

Expand Down Expand Up @@ -218,15 +265,16 @@ class TraitSelection {
@Composable
private fun TraitIcon(
leveledTrait: LeveledTrait,
selectionState: SnapshotStateMap<LeveledTrait, Int>
selectionState: SnapshotStateMap<LeveledTrait, Int>,
maxLevel: Int = 4
) {
var level by remember { mutableStateOf(0) }
var selectionModifier by remember { mutableStateOf(Modifier.alpha(0.2F)) }

Box(
Modifier.clickable(
onClick = {
level = levelup(level)
level = levelup(level, maxLevel)
selectionState[leveledTrait] = level
selectionModifier = if (level == 0) Modifier.alpha(0.2F) else Modifier.alpha(1F)
}
Expand All @@ -240,37 +288,8 @@ class TraitSelection {
}
}

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

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

private fun rankUp(rank: Int): Int {
return if (rank < 4) rank.plus(1) else 0
}

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

@Composable
Expand Down Expand Up @@ -324,11 +343,6 @@ class TraitSelection {
return imageFromResource(iconPath(trait.code))
}

private fun traitImage(rankedTrait: RankedTrait, rank: Int): ImageBitmap {
val theRank = if (rank == 0) 1 else rank
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))
Expand All @@ -338,10 +352,6 @@ class TraitSelection {
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"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.github.xetra11.ck3workbench.module.character.view

import androidx.compose.foundation.HorizontalScrollbar
import androidx.compose.foundation.ScrollableColumn
import androidx.compose.foundation.ScrollbarStyle
import androidx.compose.foundation.VerticalScrollbar
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.defaultScrollbarStyle
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -21,7 +17,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.rememberScrollbarAdapter
import androidx.compose.foundation.shape.CutCornerShape
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.material.TextField
Expand All @@ -33,10 +28,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshots.SnapshotStateMap
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
Expand All @@ -53,13 +45,15 @@ import kotlinx.coroutines.launch
@Composable
fun CharacterFactoryView() {
val traitSelection = TraitSelection()

val personalityTraitSelectionState = remember { mutableStateMapOf<TraitSelection.Trait, Boolean>() }
val congenitalTraitSelectionState = remember { mutableStateMapOf<TraitSelection.Trait, Boolean>() }
val physicalTraitSelectionState = remember { mutableStateMapOf<TraitSelection.Trait, Boolean>() }
val lifestyleTraitSelectionState = remember { mutableStateMapOf<TraitSelection.Trait, Boolean>() }
val commanderTraitSelectionState = remember { mutableStateMapOf<TraitSelection.Trait, Boolean>() }

val educationalTraitSelectionState = remember { mutableStateMapOf<TraitSelection.RankedTrait, Int>() }

val educationalTraitSelectionState = remember { mutableStateMapOf<TraitSelection.LeveledTrait, Int>() }
val leveledLifestyleTraitSelectionState = remember { mutableStateMapOf<TraitSelection.LeveledTrait, Int>() }
val leveledCongenitalTraitSelectionState = remember { mutableStateMapOf<TraitSelection.LeveledTrait, Int>() }

Column(
Expand Down Expand Up @@ -115,21 +109,27 @@ fun CharacterFactoryView() {
TraitSection("Personality Traits") {
traitSelection.PersonalityTraits(congenitalTraitSelectionState)
}
TraitSection("Lifestyle Traits") {
traitSelection.LifestyleTrait(lifestyleTraitSelectionState)
TraitSection("Commander Traits") {
traitSelection.CommanderTraits(commanderTraitSelectionState)
}
TraitSection("Educational Traits") {
traitSelection.EducationalTraits(educationalTraitSelectionState)
}
TraitSection("Physical Traits") {
traitSelection.PhysicalTraits(physicalTraitSelectionState)
}
TraitSection("Lifestyle Traits") {
traitSelection.LifestyleTraits(lifestyleTraitSelectionState)
}
TraitSection("Leveled Lifestyle Traits") {
traitSelection.LeveledLifestyleTraits(leveledLifestyleTraitSelectionState)
}
TraitSection("Congenital Traits") {
traitSelection.CongenitalTraits(congenitalTraitSelectionState)
}
TraitSection("Leveled Congenital Traits") {
traitSelection.LeveledCongenitalTraits(leveledCongenitalTraitSelectionState)
}
TraitSection("Physical Traits") {
traitSelection.PhysicalTraits(physicalTraitSelectionState)
}

Spacer(Modifier.height(20.dp))
}
Expand Down Expand Up @@ -187,7 +187,7 @@ private fun TraitSection(
}
}
) {
ColumnScope.content()
content()
}
}

Expand Down Expand Up @@ -282,7 +282,7 @@ private fun CreateButton(
birth: MutableState<String>,
death: MutableState<String>,
personalityTraitSelectionState: SnapshotStateMap<TraitSelection.Trait, Boolean>,
educationalTraitSelectionState: SnapshotStateMap<TraitSelection.RankedTrait, Int>
educationalTraitSelectionState: SnapshotStateMap<TraitSelection.LeveledTrait, Int>
) {
Button(
onClick = {
Expand Down Expand Up @@ -319,7 +319,7 @@ private fun CreateButton(
private fun createNewCharacter(
characterValues: Map<String, String>,
personalityTraits: Map<TraitSelection.Trait, Boolean>,
educationalTraits: Map<TraitSelection.RankedTrait, Int>
educationalTraits: Map<TraitSelection.LeveledTrait, Int>
) {

val traits = mutableListOf<String>()
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.
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 5838115

Please sign in to comment.