Skip to content

Commit

Permalink
Implement action add new items on monster edit (#241)
Browse files Browse the repository at this point in the history
* Implement action add new items on monster edit

* Implement add new items on monster edit
  • Loading branch information
alexandregpereira authored Jan 25, 2024
1 parent e146912 commit 4c35865
Show file tree
Hide file tree
Showing 37 changed files with 1,199 additions and 675 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package br.alexandregpereira.hunter.data

import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.StableRef
import kotlinx.cinterop.autoreleasepool
import kotlinx.cinterop.cstr
Expand All @@ -34,8 +36,9 @@ object IosDispatchers {
val IO: CoroutineDispatcher = NSQueueDispatcher(QOS_CLASS_UTILITY)
}

@OptIn(ExperimentalForeignApi::class)
class NSQueueDispatcher(private val qosClass: qos_class_t) : CoroutineDispatcher() {
private val queue = dispatch_get_global_queue(qosClass.toLong(), 0)
private val queue = dispatch_get_global_queue(qosClass.toLong(), 0.toULong())

init {
val key = "NSQueueDispatcher:$qosClass"
Expand All @@ -45,6 +48,7 @@ class NSQueueDispatcher(private val qosClass: qos_class_t) : CoroutineDispatcher
}
}

@OptIn(BetaInteropApi::class)
override fun dispatch(context: CoroutineContext, block: Runnable) {
dispatch_async(queue) {
autoreleasepool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@ import kotlin.native.ObjCName
data class AbilityDescription(
val name: String,
val description: String
)
) {

companion object {

fun create(
name: String = "",
description: String = ""
) = AbilityDescription(
name = name,
description = description
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,37 @@ data class Action(
val damageDices: List<DamageDice>,
val attackBonus: Int?,
val abilityDescription: AbilityDescription
)
) {

companion object {

fun create(
damageDices: List<DamageDice> = emptyList(),
attackBonus: Int? = null,
abilityDescription: AbilityDescription = AbilityDescription.create()
) = Action(
id = "",
damageDices = damageDices,
attackBonus = attackBonus,
abilityDescription = abilityDescription
)
}
}

@ObjCName(name = "DamageDice", exact = true)
data class DamageDice(
val dice: String,
val damage: Damage
)
) {

companion object {

fun create(
dice: String = "",
damage: Damage = Damage.create()
) = DamageDice(
dice = dice,
damage = damage
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,20 @@ data class Condition(
val index: String,
val type: ConditionType,
val name: String
)
) {

companion object {

fun create(
type: ConditionType = ConditionType.BLINDED,
name: String = ""
) = Condition(
index = "",
type = type,
name = name
)
}
}

@ObjCName(name = "ConditionType", exact = true)
enum class ConditionType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,20 @@ data class Damage(
val index: String,
val type: DamageType,
val name: String
)
) {

companion object {

fun create(
type: DamageType = DamageType.ACID,
name: String = ""
) = Damage(
index = "",
type = type,
name = name
)
}
}

@ObjCName(name = "DamageType", exact = true)
enum class DamageType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,18 @@ data class SavingThrow(
val index: String,
val modifier: Int,
val type: AbilityScoreType
)
) {
companion object {

fun create(
modifier: Int = 0,
type: AbilityScoreType = AbilityScoreType.STRENGTH,
): SavingThrow {
return SavingThrow(
index = "",
modifier = modifier,
type = type
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,17 @@ data class Skill(
val index: String,
val modifier: Int,
val name: String
)
) {

companion object {

fun create(
modifier: Int = 0,
name: String = "",
) = Skill(
index = "",
modifier = modifier,
name = name
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,21 @@ data class Speed(
data class SpeedValue(
val type: SpeedType,
val valueFormatted: String
)
) {

companion object {

fun create(
type: SpeedType = SpeedType.WALK,
valueFormatted: String = "",
): SpeedValue {
return SpeedValue(
type = type,
valueFormatted = valueFormatted
)
}
}
}

@ObjCName(name = "SpeedType", exact = true)
enum class SpeedType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,22 @@ data class SpellPreview(
val name: String,
val level: Int,
val school: SchoolOfMagic,
)
) {

companion object {

fun create(
name: String = "",
level: Int = 0,
school: SchoolOfMagic = SchoolOfMagic.ABJURATION
) = SpellPreview(
index = "",
name = name,
level = level,
school = school,
)
}
}

@ObjCName(name = "SchoolOfMagic", exact = true)
enum class SchoolOfMagic {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@ import kotlin.native.ObjCName
data class SpellUsage(
val group: String,
val spells: List<SpellPreview>
)
) {

companion object {

fun create(
group: String = "",
spells: List<SpellPreview> = emptyList()
) = SpellUsage(
group = group,
spells = spells
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,18 @@ data class Spellcasting(
val description: String,
val type: SpellcastingType,
val usages: List<SpellUsage>
)
) {

companion object {

fun create(
description: String = "",
type: SpellcastingType = SpellcastingType.SPELLCASTER,
usages: List<SpellUsage> = emptyList()
) = Spellcasting(
description = description,
type = type,
usages = usages
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private fun ActionDamageGrid(
) = Grid(modifier = modifier) {

val iconSize = 48.dp
attackBonus?.let {
attackBonus.takeUnless { it == 0 }?.let {
Bonus(value = it, name = stringResource(R.string.monster_detail_attack), iconSize = iconSize)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,6 @@ fun LazyListScope.monsterInfo(
onSpellClicked = onSpellClicked
)

item(key = "reactions") {
MonsterOptionalSectionAlphaTransition(
valueToValidate = { it.reactions },
dataList = monsters,
pagerState = pagerState,
getItemsKeys = getItemsKeys,
) {
ReactionBlock(reactions = it)
}
}

item(key = "space") {
Spacer(
modifier = Modifier
Expand Down Expand Up @@ -297,6 +286,17 @@ private fun LazyListScope.monsterInfoPart5(
}
}

item(key = "reactions") {
MonsterOptionalSectionAlphaTransition(
valueToValidate = { it.reactions },
dataList = monsters,
pagerState = pagerState,
getItemsKeys = getItemsKeys,
) {
ReactionBlock(reactions = it)
}
}

item(key = "legendaryActions") {
MonsterOptionalSectionAlphaTransition(
valueToValidate = { it.legendaryActions },
Expand Down
Loading

0 comments on commit 4c35865

Please sign in to comment.