Refactor icon to Attacks
This commit is contained in:
		
							parent
							
								
									73428d4341
								
							
						
					
					
						commit
						3b075a05e4
					
				
					 5 changed files with 27 additions and 17 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,9 @@
 | 
			
		|||
package com.pixelized.rplexicon.data.model
 | 
			
		||||
 | 
			
		||||
import android.net.Uri
 | 
			
		||||
 | 
			
		||||
data class Attack(
 | 
			
		||||
    val icon: Uri?,
 | 
			
		||||
    val title: String,
 | 
			
		||||
    val type: Type,
 | 
			
		||||
    val range: String?,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,6 +29,7 @@ class AttackParser @Inject constructor(
 | 
			
		|||
                    val title = row.parse(column = NAME)
 | 
			
		||||
                    if (characterSheet != null && title != null) {
 | 
			
		||||
                        val attack = Attack(
 | 
			
		||||
                            icon = row.parseUri(column = ICON),
 | 
			
		||||
                            title = title,
 | 
			
		||||
                            type = parseType(value = row.parse(column = TYPE)),
 | 
			
		||||
                            range = row.parse(column = RANGE),
 | 
			
		||||
| 
						 | 
				
			
			@ -62,6 +63,7 @@ class AttackParser @Inject constructor(
 | 
			
		|||
        private val HIT = column("Touché")
 | 
			
		||||
        private val DAMAGE = column("Dommage")
 | 
			
		||||
        private val ALTERATION = column("Altérations")
 | 
			
		||||
        private val COLUMNS get() = listOf(CHARACTER, NAME, TYPE, RANGE, HIT, DAMAGE, ALTERATION)
 | 
			
		||||
        private val ICON = column("Icone")
 | 
			
		||||
        private val COLUMNS get() = listOf(CHARACTER, NAME, TYPE, RANGE, HIT, DAMAGE, ALTERATION, ICON)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -2,6 +2,7 @@ package com.pixelized.rplexicon.ui.screens.character.composable.actions
 | 
			
		|||
 | 
			
		||||
import android.content.res.Configuration.UI_MODE_NIGHT_NO
 | 
			
		||||
import android.content.res.Configuration.UI_MODE_NIGHT_YES
 | 
			
		||||
import android.net.Uri
 | 
			
		||||
import androidx.annotation.DrawableRes
 | 
			
		||||
import androidx.annotation.StringRes
 | 
			
		||||
import androidx.compose.foundation.layout.Arrangement
 | 
			
		||||
| 
						 | 
				
			
			@ -10,8 +11,8 @@ import androidx.compose.foundation.layout.PaddingValues
 | 
			
		|||
import androidx.compose.foundation.layout.Row
 | 
			
		||||
import androidx.compose.foundation.layout.fillMaxWidth
 | 
			
		||||
import androidx.compose.foundation.layout.padding
 | 
			
		||||
import androidx.compose.foundation.layout.size
 | 
			
		||||
import androidx.compose.material.minimumInteractiveComponentSize
 | 
			
		||||
import androidx.compose.material3.Icon
 | 
			
		||||
import androidx.compose.material3.MaterialTheme
 | 
			
		||||
import androidx.compose.material3.Surface
 | 
			
		||||
import androidx.compose.material3.Text
 | 
			
		||||
| 
						 | 
				
			
			@ -19,7 +20,6 @@ import androidx.compose.runtime.Composable
 | 
			
		|||
import androidx.compose.runtime.Stable
 | 
			
		||||
import androidx.compose.ui.Alignment
 | 
			
		||||
import androidx.compose.ui.Modifier
 | 
			
		||||
import androidx.compose.ui.res.painterResource
 | 
			
		||||
import androidx.compose.ui.res.stringResource
 | 
			
		||||
import androidx.compose.ui.text.font.FontWeight
 | 
			
		||||
import androidx.compose.ui.text.style.TextOverflow
 | 
			
		||||
| 
						 | 
				
			
			@ -27,15 +27,18 @@ import androidx.compose.ui.tooling.preview.Preview
 | 
			
		|||
import androidx.compose.ui.tooling.preview.PreviewParameter
 | 
			
		||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
 | 
			
		||||
import androidx.compose.ui.unit.dp
 | 
			
		||||
import androidx.core.net.toUri
 | 
			
		||||
import com.pixelized.rplexicon.R
 | 
			
		||||
import com.pixelized.rplexicon.data.model.Attack
 | 
			
		||||
import com.pixelized.rplexicon.ui.composable.AsyncImage
 | 
			
		||||
import com.pixelized.rplexicon.ui.screens.character.composable.common.DiceButton
 | 
			
		||||
import com.pixelized.rplexicon.ui.theme.LexiconTheme
 | 
			
		||||
import com.pixelized.rplexicon.utilitary.extentions.uri
 | 
			
		||||
 | 
			
		||||
@Stable
 | 
			
		||||
data class AttackUio(
 | 
			
		||||
    val icon: Uri?,
 | 
			
		||||
    val id: Attack? = null,
 | 
			
		||||
    @DrawableRes val icon: Int,
 | 
			
		||||
    val name: String,
 | 
			
		||||
    @StringRes val type: Int,
 | 
			
		||||
    val range: String?,
 | 
			
		||||
| 
						 | 
				
			
			@ -62,13 +65,16 @@ fun Attack(
 | 
			
		|||
            .padding(paddingValues = padding)
 | 
			
		||||
            .minimumInteractiveComponentSize()
 | 
			
		||||
            .then(other = modifier),
 | 
			
		||||
        horizontalArrangement = Arrangement.spacedBy(space = 16.dp),
 | 
			
		||||
        horizontalArrangement = Arrangement.spacedBy(space = 8.dp),
 | 
			
		||||
        verticalAlignment = Alignment.CenterVertically,
 | 
			
		||||
    ) {
 | 
			
		||||
        Icon(
 | 
			
		||||
            painter = painterResource(id = weapon.icon),
 | 
			
		||||
            contentDescription = null,
 | 
			
		||||
        )
 | 
			
		||||
        weapon.icon?.let { uri ->
 | 
			
		||||
            AsyncImage(
 | 
			
		||||
                modifier = Modifier.size(size = 36.dp),
 | 
			
		||||
                model = uri,
 | 
			
		||||
                contentDescription = null,
 | 
			
		||||
            )
 | 
			
		||||
        }
 | 
			
		||||
        Column(
 | 
			
		||||
            modifier = Modifier.weight(weight = 1f),
 | 
			
		||||
        ) {
 | 
			
		||||
| 
						 | 
				
			
			@ -140,7 +146,7 @@ private fun WeaponPreview(
 | 
			
		|||
private class WeaponPreviewProvider : PreviewParameterProvider<AttackUio> {
 | 
			
		||||
    override val values: Sequence<AttackUio> = sequenceOf(
 | 
			
		||||
        AttackUio(
 | 
			
		||||
            icon = R.drawable.ic_crossed_swords_24,
 | 
			
		||||
            icon = R.drawable.ic_crossed_swords_24.uri.toUri(),
 | 
			
		||||
            name = "Dagger",
 | 
			
		||||
            type = R.string.attack_type_melee,
 | 
			
		||||
            range = "5 ft reach",
 | 
			
		||||
| 
						 | 
				
			
			@ -148,7 +154,7 @@ private class WeaponPreviewProvider : PreviewParameterProvider<AttackUio> {
 | 
			
		|||
            damage = AttackUio.Dice(icon = R.drawable.ic_d8_24, label = "1d8"),
 | 
			
		||||
        ),
 | 
			
		||||
        AttackUio(
 | 
			
		||||
            icon = R.drawable.ic_pocket_bow_24,
 | 
			
		||||
            icon = R.drawable.ic_pocket_bow_24.uri.toUri(),
 | 
			
		||||
            name = "Long bow",
 | 
			
		||||
            type = R.string.attack_type_range,
 | 
			
		||||
            range = "30 ft reach",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,8 +5,10 @@ import androidx.compose.runtime.Stable
 | 
			
		|||
import androidx.compose.runtime.State
 | 
			
		||||
import androidx.compose.runtime.mutableStateOf
 | 
			
		||||
import androidx.compose.runtime.remember
 | 
			
		||||
import androidx.core.net.toUri
 | 
			
		||||
import com.pixelized.rplexicon.R
 | 
			
		||||
import com.pixelized.rplexicon.ui.screens.character.composable.actions.AttackUio
 | 
			
		||||
import com.pixelized.rplexicon.utilitary.extentions.uri
 | 
			
		||||
 | 
			
		||||
@Stable
 | 
			
		||||
@Composable
 | 
			
		||||
| 
						 | 
				
			
			@ -14,7 +16,7 @@ fun rememberAttackListStatePreview(): State<List<AttackUio>> = remember {
 | 
			
		|||
    mutableStateOf(
 | 
			
		||||
        listOf(
 | 
			
		||||
            AttackUio(
 | 
			
		||||
                icon = R.drawable.ic_crossed_swords_24,
 | 
			
		||||
                icon = R.drawable.ic_crossed_swords_24.uri.toUri(),
 | 
			
		||||
                name = "Dagger",
 | 
			
		||||
                type = R.string.attack_type_melee,
 | 
			
		||||
                range = "5 ft reach",
 | 
			
		||||
| 
						 | 
				
			
			@ -28,7 +30,7 @@ fun rememberAttackListStatePreview(): State<List<AttackUio>> = remember {
 | 
			
		|||
                ),
 | 
			
		||||
            ),
 | 
			
		||||
            AttackUio(
 | 
			
		||||
                icon = R.drawable.ic_pocket_bow_24,
 | 
			
		||||
                icon = R.drawable.ic_pocket_bow_24.uri.toUri(),
 | 
			
		||||
                name = "Long bow",
 | 
			
		||||
                type = R.string.attack_type_range,
 | 
			
		||||
                range = "30 ft reach",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -67,10 +67,7 @@ class AttackUioFactory @Inject constructor() {
 | 
			
		|||
 | 
			
		||||
        return AttackUio(
 | 
			
		||||
            id = attack,
 | 
			
		||||
            icon = when (attack.type) {
 | 
			
		||||
                Attack.Type.PHYSICAL_MELEE_ATTACK -> R.drawable.ic_crossed_swords_24
 | 
			
		||||
                Attack.Type.PHYSICAL_RANGE_ATTACK -> R.drawable.ic_pocket_bow_24
 | 
			
		||||
            },
 | 
			
		||||
            icon = attack.icon,
 | 
			
		||||
            name = attack.title,
 | 
			
		||||
            type = when (attack.type) {
 | 
			
		||||
                Attack.Type.PHYSICAL_MELEE_ATTACK -> R.string.attack_type_melee
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue