Skip to content

Commit

Permalink
Drop use of legacy armour in an app
Browse files Browse the repository at this point in the history
  • Loading branch information
fmasa committed Jul 7, 2022
1 parent f8af29a commit 5a9ce1d
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 294 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ import cz.frantisekmasa.wfrp_master.common.core.PartyScreenModel
import cz.frantisekmasa.wfrp_master.common.core.cache.CharacterRepositoryIdentityMap
import cz.frantisekmasa.wfrp_master.common.core.cache.PartyRepositoryIdentityMap
import cz.frantisekmasa.wfrp_master.common.core.domain.character.CharacterAvatarChanger
import cz.frantisekmasa.wfrp_master.common.core.domain.character.CharacterFeatureRepository
import cz.frantisekmasa.wfrp_master.common.core.domain.character.CharacterItem
import cz.frantisekmasa.wfrp_master.common.core.domain.character.CharacterItemRepository
import cz.frantisekmasa.wfrp_master.common.core.domain.character.CharacterRepository
import cz.frantisekmasa.wfrp_master.common.core.domain.character.Feature
import cz.frantisekmasa.wfrp_master.common.core.domain.compendium.Compendium
import cz.frantisekmasa.wfrp_master.common.core.domain.compendium.FirestoreCompendium
import cz.frantisekmasa.wfrp_master.common.core.domain.identifiers.CharacterId
Expand All @@ -38,11 +36,9 @@ import cz.frantisekmasa.wfrp_master.common.core.domain.religion.MiracleRepositor
import cz.frantisekmasa.wfrp_master.common.core.domain.skills.SkillRepository
import cz.frantisekmasa.wfrp_master.common.core.domain.spells.SpellRepository
import cz.frantisekmasa.wfrp_master.common.core.domain.talents.TalentRepository
import cz.frantisekmasa.wfrp_master.common.core.domain.trappings.Armour
import cz.frantisekmasa.wfrp_master.common.core.domain.trappings.InventoryItemRepository
import cz.frantisekmasa.wfrp_master.common.core.firebase.Schema
import cz.frantisekmasa.wfrp_master.common.core.firebase.functions.CloudFunctionCharacterAvatarChanger
import cz.frantisekmasa.wfrp_master.common.core.firebase.repositories.FirestoreCharacterFeatureRepository
import cz.frantisekmasa.wfrp_master.common.core.firebase.repositories.FirestoreCharacterItemRepository
import cz.frantisekmasa.wfrp_master.common.core.firebase.repositories.FirestoreCharacterRepository
import cz.frantisekmasa.wfrp_master.common.core.firebase.repositories.FirestoreEncounterRepository
Expand Down Expand Up @@ -76,7 +72,6 @@ import kotlin.random.Random
import cz.frantisekmasa.wfrp_master.common.core.firebase.serializationAggregateMapper as mapper



val appModule = DI.Module("Common") {
import(platformModule)

Expand Down Expand Up @@ -131,25 +126,16 @@ val appModule = DI.Module("Common") {

bindSingleton<CharacterAvatarChanger> { CloudFunctionCharacterAvatarChanger(instance()) }

bindSingleton<CharacterFeatureRepository<Armour>> {
FirestoreCharacterFeatureRepository(
Feature.ARMOR,
instance(),
Armour(),
mapper(),
)
}

bindFactory { characterId: CharacterId ->
TrappingsScreenModel(characterId, instance(), instance(), instance())
TrappingsScreenModel(characterId, instance(), instance())
}

/**
* ViewModels
*/

bindFactory { characterId: CharacterId ->
CharacterCombatScreenModel(characterId, instance(), instance(), instance())
CharacterCombatScreenModel(characterId, instance(), instance())
}
bindFactory { characterId: CharacterId -> CharacteristicsScreenModel(characterId, instance()) }
bindFactory { characterId: CharacterId ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.runtime.Immutable
import cafe.adriel.voyager.core.model.ScreenModel
import cz.frantisekmasa.wfrp_master.common.core.domain.Damage
import cz.frantisekmasa.wfrp_master.common.core.domain.HitLocation
import cz.frantisekmasa.wfrp_master.common.core.domain.character.CharacterFeatureRepository
import cz.frantisekmasa.wfrp_master.common.core.domain.character.CharacterRepository
import cz.frantisekmasa.wfrp_master.common.core.domain.identifiers.CharacterId
import cz.frantisekmasa.wfrp_master.common.core.domain.trappings.Armour
Expand All @@ -22,7 +21,6 @@ class CharacterCombatScreenModel(
characterId: CharacterId,
trappingRepository: InventoryItemRepository,
characterRepository: CharacterRepository,
armorRepository: CharacterFeatureRepository<Armour>,
) : ScreenModel {
private val trappingsFlow = trappingRepository.findAllForCharacter(characterId)
private val characterFlow = characterRepository.getLive(characterId)
Expand Down Expand Up @@ -50,13 +48,7 @@ class CharacterCombatScreenModel(
.toList()
}

private val legacyArmourFlow = armorRepository
.getLive(characterId)
.right()

val armour: Flow<Armour> = legacyArmourFlow.combine(trappingsFlow) { armour, items ->
armour + Armour.fromItems(items)
}
val armour: Flow<Armour> = trappingsFlow.map { items -> Armour.fromItems(items) }

val armourPieces: Flow<Map<HitLocation, List<WornArmourPiece>>> = trappingsFlow.map { trappings ->
val locations = mutableMapOf<HitLocation, MutableList<WornArmourPiece>>()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import cz.frantisekmasa.wfrp_master.common.core.ui.dialogs.DialogState
import cz.frantisekmasa.wfrp_master.common.core.ui.flow.collectWithLifecycle
import cz.frantisekmasa.wfrp_master.common.core.ui.primitives.EmptyUI
import cz.frantisekmasa.wfrp_master.common.core.ui.primitives.Spacing
import cz.frantisekmasa.wfrp_master.common.core.ui.primitives.UserTip
import cz.frantisekmasa.wfrp_master.common.core.ui.primitives.UserTipCard
import cz.frantisekmasa.wfrp_master.common.core.ui.scaffolding.TopPanel
import cz.frantisekmasa.wfrp_master.common.localization.LocalStrings
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -82,9 +84,7 @@ fun TrappingsScreen(
}
}

screenModel.armor.collectWithLifecycle(null).value?.let { armor ->
ArmourCard(armor, onChange = { screenModel.updateArmor(it) })
}
UserTipCard(UserTip.ARMOUR_TRAPPINGS, Modifier.padding(horizontal = 8.dp))

var inventoryItemDialogState: DialogState<InventoryItem?> by remember {
mutableStateOf(DialogState.Closed())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package cz.frantisekmasa.wfrp_master.common.character.trappings

import androidx.compose.runtime.Immutable
import cafe.adriel.voyager.core.model.ScreenModel
import cafe.adriel.voyager.core.model.coroutineScope
import cz.frantisekmasa.wfrp_master.common.core.domain.Money
import cz.frantisekmasa.wfrp_master.common.core.domain.character.CharacterFeatureRepository
import cz.frantisekmasa.wfrp_master.common.core.domain.character.CharacterRepository
import cz.frantisekmasa.wfrp_master.common.core.domain.character.NotEnoughMoney
import cz.frantisekmasa.wfrp_master.common.core.domain.identifiers.CharacterId
import cz.frantisekmasa.wfrp_master.common.core.domain.trappings.Armour
import cz.frantisekmasa.wfrp_master.common.core.domain.trappings.Encumbrance
import cz.frantisekmasa.wfrp_master.common.core.domain.trappings.InventoryItem
import cz.frantisekmasa.wfrp_master.common.core.domain.trappings.InventoryItemRepository
Expand All @@ -17,15 +14,13 @@ import cz.frantisekmasa.wfrp_master.common.core.shared.IO
import cz.frantisekmasa.wfrp_master.common.core.utils.right
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch


class TrappingsScreenModel(
private val characterId: CharacterId,
private val inventoryItems: InventoryItemRepository,
private val armorRepository: CharacterFeatureRepository<Armour>,
private val characters: CharacterRepository
) : ScreenModel {

Expand All @@ -38,23 +33,6 @@ class TrappingsScreenModel(
val totalEncumbrance: Flow<Encumbrance?> = inventory
.map { items -> items.map { it.effectiveEncumbrance }.sum() }

val armor: Flow<EquippedArmour> =
armorRepository
.getLive(characterId)
.right()
.combine(inventory) { armour, items ->
EquippedArmour(
armourFromItems = Armour.fromItems(items),
legacyArmour = armour,
)
}

@Immutable
data class EquippedArmour(
val armourFromItems: Armour,
val legacyArmour: Armour,
)

val money: Flow<Money> = character.map { it.money }

suspend fun addMoney(amount: Money) {
Expand All @@ -80,8 +58,4 @@ class TrappingsScreenModel(
fun removeInventoryItem(inventoryItem: InventoryItem) = coroutineScope.launch(Dispatchers.IO) {
inventoryItems.remove(characterId, inventoryItem.id)
}

fun updateArmor(armor: Armour) = coroutineScope.launch(Dispatchers.IO) {
armorRepository.save(characterId, armor)
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5a9ce1d

Please sign in to comment.