Skip to content

Commit

Permalink
Improve registration form animations (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandregpereira authored Feb 7, 2024
1 parent 4c35865 commit 7241ff5
Show file tree
Hide file tree
Showing 24 changed files with 69 additions and 40 deletions.
1 change: 1 addition & 0 deletions domain/monster/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(project(":core:uuid"))
implementation(libs.koin.core)
implementation(libs.kotlin.coroutines.core)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package br.alexandregpereira.hunter.domain.model

import br.alexandregpereira.hunter.uuid.generateUUID
import kotlin.native.ObjCName

@ObjCName(name = "AbilityDescription", exact = true)
data class AbilityDescription(
val name: String,
val description: String
val description: String,
val index: String = "",
) {

companion object {
Expand All @@ -30,6 +32,7 @@ data class AbilityDescription(
name: String = "",
description: String = ""
) = AbilityDescription(
index = generateUUID(),
name = name,
description = description
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package br.alexandregpereira.hunter.domain.model

import br.alexandregpereira.hunter.uuid.generateUUID
import kotlin.native.ObjCName

@ObjCName(name = "Action", exact = true)
Expand All @@ -33,7 +34,7 @@ data class Action(
attackBonus: Int? = null,
abilityDescription: AbilityDescription = AbilityDescription.create()
) = Action(
id = "",
id = generateUUID(),
damageDices = damageDices,
attackBonus = attackBonus,
abilityDescription = abilityDescription
Expand All @@ -44,7 +45,8 @@ data class Action(
@ObjCName(name = "DamageDice", exact = true)
data class DamageDice(
val dice: String,
val damage: Damage
val damage: Damage,
val index: String = generateUUID(),
) {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package br.alexandregpereira.hunter.domain.model

import br.alexandregpereira.hunter.uuid.generateUUID
import kotlin.native.ObjCName

@ObjCName(name = "Condition", exact = true)
Expand All @@ -31,7 +32,7 @@ data class Condition(
type: ConditionType = ConditionType.BLINDED,
name: String = ""
) = Condition(
index = "",
index = generateUUID(),
type = type,
name = name
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package br.alexandregpereira.hunter.domain.model

import br.alexandregpereira.hunter.uuid.generateUUID
import kotlin.native.ObjCName

@ObjCName(name = "Damage", exact = true)
Expand All @@ -31,7 +32,7 @@ data class Damage(
type: DamageType = DamageType.ACID,
name: String = ""
) = Damage(
index = "",
index = generateUUID(),
type = type,
name = name
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package br.alexandregpereira.hunter.domain.model

import br.alexandregpereira.hunter.uuid.generateUUID
import kotlin.native.ObjCName

@ObjCName(name = "SavingThrow", exact = true)
Expand All @@ -31,7 +32,7 @@ data class SavingThrow(
type: AbilityScoreType = AbilityScoreType.STRENGTH,
): SavingThrow {
return SavingThrow(
index = "",
index = generateUUID(),
modifier = modifier,
type = type
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package br.alexandregpereira.hunter.domain.model

import br.alexandregpereira.hunter.uuid.generateUUID
import kotlin.native.ObjCName

@ObjCName(name = "Skill", exact = true)
Expand All @@ -31,7 +32,7 @@ data class Skill(
modifier: Int = 0,
name: String = "",
) = Skill(
index = "",
index = generateUUID(),
modifier = modifier,
name = name
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package br.alexandregpereira.hunter.domain.model

import br.alexandregpereira.hunter.uuid.generateUUID
import kotlin.native.ObjCName

@ObjCName(name = "Speed", exact = true)
Expand All @@ -27,7 +28,8 @@ data class Speed(
@ObjCName(name = "SpeedValue", exact = true)
data class SpeedValue(
val type: SpeedType,
val valueFormatted: String
val valueFormatted: String,
val index: String = "",
) {

companion object {
Expand All @@ -38,7 +40,8 @@ data class SpeedValue(
): SpeedValue {
return SpeedValue(
type = type,
valueFormatted = valueFormatted
valueFormatted = valueFormatted,
index = generateUUID()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package br.alexandregpereira.hunter.domain.monster.spell.model

import br.alexandregpereira.hunter.uuid.generateUUID
import kotlin.native.ObjCName

@ObjCName(name = "SpellPreview", exact = true)
Expand All @@ -33,7 +34,7 @@ data class SpellPreview(
level: Int = 0,
school: SchoolOfMagic = SchoolOfMagic.ABJURATION
) = SpellPreview(
index = "",
index = generateUUID(),
name = name,
level = level,
school = school,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package br.alexandregpereira.hunter.domain.monster.spell.model

import br.alexandregpereira.hunter.uuid.generateUUID
import kotlin.native.ObjCName

@ObjCName(name = "SpellUsage", exact = true)
data class SpellUsage(
val group: String,
val spells: List<SpellPreview>
val spells: List<SpellPreview>,
val index: String = generateUUID(),
) {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

package br.alexandregpereira.hunter.domain.monster.spell.model

import br.alexandregpereira.hunter.uuid.generateUUID
import kotlin.native.ObjCName

@ObjCName(name = "Spellcasting", exact = true)
data class Spellcasting(
val description: String,
val type: SpellcastingType,
val usages: List<SpellUsage>
val usages: List<SpellUsage>,
val index: String = generateUUID(),
) {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal fun List<ActionWithDamageDicesEntity>.toDomain(): List<Action> {
damageDices = it.damageDices.toDamageDiceDomain(),
attackBonus = it.action.attackBonus,
abilityDescription = AbilityDescription(
index = it.action.id,
name = it.action.name,
description = it.action.description
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal fun List<LegendaryActionWithDamageDicesEntity>.toDomain(): List<Action>
damageDices = it.damageDices.toDamageDiceDomain(),
attackBonus = it.action.attackBonus,
abilityDescription = AbilityDescription(
index = it.action.id,
name = it.action.name,
description = it.action.description
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ import br.alexandregpereira.hunter.domain.model.AbilityDescription

internal fun List<SpecialAbilityEntity>.toDomain(): List<AbilityDescription> {
return this.map {
AbilityDescription(name = it.name, description = it.description)
AbilityDescription(
name = it.name,
description = it.description,
index = "${it.monsterIndex}-${it.name}",
)
}
}

internal fun List<ReactionEntity>.toDomainReactionEntity(): List<AbilityDescription> {
return this.map {
AbilityDescription(name = it.name, description = it.description)
AbilityDescription(
name = it.name,
description = it.description,
index = "${it.monsterIndex}-${it.name}",
)
}
}

Expand All @@ -37,7 +45,7 @@ internal fun List<AbilityDescription>.toEntity(monsterIndex: String): List<Speci
SpecialAbilityEntity(
name = it.name,
description = it.description,
monsterIndex = monsterIndex
monsterIndex = monsterIndex,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ internal fun List<ActionDto>.toDomain(): List<Action> {
attackBonus = action.attackBonus,
abilityDescription = AbilityDescription(
name = action.name,
description = action.description
description = action.description,
index = "action-$uuid"
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal fun List<SpecialAbilityDto>.toDomain(): List<AbilityDescription> {
return this.mapIndexed { index, abilityDescription ->
AbilityDescription(
name = abilityDescription.name,
description = abilityDescription.desc
description = abilityDescription.desc,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal fun LazyListScope.MonsterAbilityDescriptionForm(
createNew = { AbilityDescription.create() },
onChanged = onChanged
) { index, abilityDescription ->
formItem(key = "$key-ability-description-name-$index") {
formItem(key = "$key-ability-description-name-${abilityDescription.index}") {
AppTextField(
text = abilityDescription.name,
label = stringResource(R.string.monster_registration_name),
Expand All @@ -36,7 +36,7 @@ internal fun LazyListScope.MonsterAbilityDescriptionForm(
)
}

formItem(key = "$key-ability-description-description-$index") {
formItem(key = "$key-ability-description-description-${abilityDescription.index}") {
AppTextField(
text = abilityDescription.description,
label = stringResource(R.string.monster_registration_description),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal fun LazyListScope.MonsterActionsForm(
onChanged = onChanged
) { actionIndex, action ->
val abilityDescription = action.abilityDescription
formItem(key = "$key-action-name-$actionIndex") {
formItem(key = "$key-action-name-${action.id}") {
AppTextField(
text = abilityDescription.name,
label = stringResource(R.string.monster_registration_name),
Expand All @@ -48,7 +48,7 @@ internal fun LazyListScope.MonsterActionsForm(
)
}

formItem(key = "$key-action-description-$actionIndex") {
formItem(key = "$key-action-description-${action.id}") {
AppTextField(
text = abilityDescription.description,
label = stringResource(R.string.monster_registration_description),
Expand All @@ -67,7 +67,7 @@ internal fun LazyListScope.MonsterActionsForm(
)
}

formItem(key = "$key-action-attackBonus-$actionIndex") {
formItem(key = "$key-action-attackBonus-${action.id}") {
AppTextField(
value = action.attackBonus ?: 0,
label = stringResource(R.string.monster_registration_attack_bonus),
Expand All @@ -77,7 +77,7 @@ internal fun LazyListScope.MonsterActionsForm(
)
}

val damageDiceKey = "$key-actions-damageDices-$actionIndex"
val damageDiceKey = "$key-actions-damageDices-${action.id}"
FormItems(
items = action.damageDices.toMutableList(),
addText = { stringResource(R.string.monster_registration_add_damage_dice) },
Expand All @@ -90,7 +90,7 @@ internal fun LazyListScope.MonsterActionsForm(
)
}
) { index, damageDice ->
formItem(key = "$damageDiceKey-damageDice-type-$index") {
formItem(key = "$damageDiceKey-damageDice-type-${damageDice.index}") {
PickerField(
value = damageDice.damage.type.toTypeState().getStringName(),
label = stringResource(R.string.monster_registration_damage_type),
Expand All @@ -105,7 +105,7 @@ internal fun LazyListScope.MonsterActionsForm(
)
}

formItem(key = "$damageDiceKey-damageDice-dice-$index") {
formItem(key = "$damageDiceKey-damageDice-dice-${damageDice.index}") {
AppTextField(
text = damageDice.dice,
label = stringResource(R.string.monster_registration_damage_dice),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal fun LazyListScope.MonsterConditionsForm(
createNew = { Condition.create() },
onChanged = onChanged
) { i, condition ->
formItem(key = "$key-name-$i") {
formItem(key = "$key-name-${condition.index}") {
val conditionTypeOptions = conditionTypes.map { stringResource(it.stringRes) }
PickerField(
value = stringResource(condition.type.toTypeState().stringRes),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal fun LazyListScope.MonsterDamagesForm(
createNew = { Damage.create() },
onChanged = onChanged
) { i, damage ->
formItem(key = "$key-name-$i") {
formItem(key = "$key-name-${damage.index}") {
val damageTypeOptions = damageTypes.map { stringResource(it.stringRes) }
if (i != 0 && damage.type == DamageType.OTHER) Spacer(modifier = Modifier.height(8.dp))

Expand All @@ -59,7 +59,7 @@ internal fun LazyListScope.MonsterDamagesForm(
)
}

formItem(key = "$key-name-other-$i") {
formItem(key = "$key-name-other-${damage.index}") {
if (damage.type == DamageType.OTHER) {
AppTextField(
text = damage.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal fun LazyListScope.MonsterProficiencyForm(
createNew = { Skill.create() },
onChanged = onChanged
) { i, proficiency ->
formItem(key = "$key-name-$i") {
formItem(key = "$key-name-${proficiency.index}") {
AppTextField(
text = proficiency.name,
label = stringResource(R.string.monster_registration_name),
Expand All @@ -36,7 +36,7 @@ internal fun LazyListScope.MonsterProficiencyForm(
)
}

formItem(key = "$key-modifier-$i") {
formItem(key = "$key-modifier-${proficiency.index}") {
AppTextField(
value = proficiency.modifier,
label = proficiency.name,
Expand Down
Loading

0 comments on commit 7241ff5

Please sign in to comment.