-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create spell compendium feature and edit spells (#239)
* Create spell compendium feature and edit spells * Adjust layout and implement spell search
- Loading branch information
1 parent
ba86ff4
commit 75e63aa
Showing
55 changed files
with
1,104 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...ster/core/src/commonMain/kotlin/br/alexandregpereira/hunter/domain/locale/LocaleNumber.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package br.alexandregpereira.hunter.domain.locale | ||
|
||
internal expect fun Int.formatToNumber(): String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...monster/core/src/iosMain/kotlin/br/alexandregpereira/hunter/domain/locale/LocaleNumber.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package br.alexandregpereira.hunter.domain.locale | ||
|
||
internal actual fun Int.formatToNumber(): String { | ||
return this.toString() | ||
} |
7 changes: 7 additions & 0 deletions
7
...monster/core/src/jvmMain/kotlin/br/alexandregpereira/hunter/domain/locale/LocaleNumber.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package br.alexandregpereira.hunter.domain.locale | ||
|
||
import java.text.NumberFormat | ||
|
||
internal actual fun Int.formatToNumber(): String { | ||
return NumberFormat.getIntegerInstance().format(this) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 101 additions & 12 deletions
113
...tlin/br/alexandregpereira/hunter/monster/registration/ui/form/MonsterSpellcastingsForm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,116 @@ | ||
package br.alexandregpereira.hunter.monster.registration.ui.form | ||
|
||
import androidx.compose.material.Text | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.FontStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.sp | ||
import br.alexandregpereira.hunter.domain.model.Action | ||
import br.alexandregpereira.hunter.domain.monster.spell.model.SpellPreview | ||
import br.alexandregpereira.hunter.domain.monster.spell.model.SpellUsage | ||
import br.alexandregpereira.hunter.domain.monster.spell.model.Spellcasting | ||
import br.alexandregpereira.hunter.domain.monster.spell.model.SpellcastingType | ||
import br.alexandregpereira.hunter.monster.registration.R | ||
import br.alexandregpereira.hunter.monster.registration.ui.changeAt | ||
import br.alexandregpereira.hunter.ui.compose.AppTextField | ||
import br.alexandregpereira.hunter.ui.compose.ClickableField | ||
import br.alexandregpereira.hunter.ui.compose.Form | ||
import br.alexandregpereira.hunter.ui.compose.PickerField | ||
|
||
@Composable | ||
internal fun MonsterSpellcastingsForm( | ||
spellcastings: List<Spellcasting>, | ||
modifier: Modifier = Modifier, | ||
onChanged: (List<Action>) -> Unit = {} | ||
onSpellClick: (String) -> Unit = {}, | ||
onChanged: (List<Spellcasting>) -> Unit = {} | ||
) = Form(modifier, stringResource(R.string.monster_registration_spells)) { | ||
Text( | ||
text = stringResource(R.string.monster_registration_work_in_progress), | ||
fontSize = 14.sp, | ||
fontWeight = FontWeight.Light, | ||
fontStyle = FontStyle.Italic, | ||
) | ||
if (spellcastings.isEmpty()) { | ||
AddButton(text = stringResource(R.string.monster_registration_add_spellcasting_type)) | ||
return@Form | ||
} | ||
val newSpellcastings = spellcastings.toMutableList() | ||
val options = SpellcastingType.entries | ||
val optionStrings = SpellcastingType.entries.map { it.toState().getStringName() } | ||
|
||
spellcastings.forEachIndexed { index, spellcasting -> | ||
PickerField( | ||
value = spellcasting.type.toState().getStringName(), | ||
label = stringResource(R.string.monster_registration_spellcasting_type_label), | ||
options = optionStrings, | ||
onValueChange = { optionIndex -> | ||
onChanged(newSpellcastings.changeAt(index) { copy(type = options[optionIndex]) }) | ||
} | ||
) | ||
AppTextField( | ||
text = spellcasting.description, | ||
label = stringResource(R.string.monster_registration_description), | ||
multiline = true, | ||
onValueChange = { newValue -> | ||
onChanged(newSpellcastings.changeAt(index) { copy(description = newValue) }) | ||
} | ||
) | ||
|
||
MonsterSpellsUsageForm( | ||
spellsUsage = spellcasting.usages, | ||
onSpellClick = onSpellClick, | ||
onChanged = { newSpellsUsage -> | ||
onChanged(newSpellcastings.changeAt(index) { copy(usages = newSpellsUsage) }) | ||
} | ||
) | ||
|
||
AddButton(text = stringResource(R.string.monster_registration_add_spellcasting_type)) | ||
} | ||
} | ||
|
||
@Composable | ||
internal fun MonsterSpellsUsageForm( | ||
spellsUsage: List<SpellUsage>, | ||
onSpellClick: (String) -> Unit = {}, | ||
onChanged: (List<SpellUsage>) -> Unit = {} | ||
) { | ||
val newSpellsUsage = spellsUsage.toMutableList() | ||
|
||
AddButton(text = stringResource(R.string.monster_registration_add_spell_group)) | ||
|
||
spellsUsage.forEachIndexed { index, spellUsage -> | ||
AppTextField( | ||
text = spellUsage.group, | ||
label = stringResource(R.string.monster_registration_spell_group), | ||
onValueChange = { newValue -> | ||
onChanged(newSpellsUsage.changeAt(index) { copy(group = newValue) }) | ||
} | ||
) | ||
|
||
MonsterSpellsForm(spells = spellUsage.spells, onSpellClick = onSpellClick) | ||
|
||
AddButton(text = stringResource(R.string.monster_registration_add_spell_group)) | ||
} | ||
} | ||
|
||
@Composable | ||
internal fun MonsterSpellsForm( | ||
spells: List<SpellPreview>, | ||
onSpellClick: (String) -> Unit = {} | ||
) { | ||
spells.forEach { spell -> | ||
ClickableField( | ||
text = spell.name, | ||
label = stringResource(R.string.monster_registration_spell_label), | ||
onClick = { onSpellClick(spell.index) }, | ||
) | ||
} | ||
|
||
AddButton(text = stringResource(R.string.monster_registration_add_spell)) | ||
} | ||
|
||
private fun SpellcastingType.toState() = when (this) { | ||
SpellcastingType.SPELLCASTER -> SpellcastingTypeState.SPELLCASTER | ||
SpellcastingType.INNATE -> SpellcastingTypeState.INNATE | ||
} | ||
|
||
private enum class SpellcastingTypeState(val stringRes: Int) { | ||
SPELLCASTER(R.string.monster_registration_spellcasting_caster_type), | ||
INNATE(R.string.monster_registration_spellcasting_innate_type), | ||
} | ||
|
||
@Composable | ||
private fun SpellcastingTypeState.getStringName() = stringResource(stringRes) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.