tgbotapi/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt

81 lines
3.1 KiB
Kotlin
Raw Normal View History

2020-10-04 11:06:30 +00:00
package dev.inmo.tgbotapi.types.dice
2020-04-24 12:25:47 +00:00
2022-08-05 18:39:46 +00:00
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
2020-11-04 17:52:22 +00:00
import dev.inmo.tgbotapi.types.*
2021-05-29 09:34:14 +00:00
import dev.inmo.tgbotapi.utils.RiskFeature
2021-06-28 05:12:51 +00:00
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
2020-08-18 06:50:11 +00:00
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
2020-04-24 12:25:47 +00:00
@Serializable(DiceAnimationTypeSerializer::class)
2022-08-05 10:31:39 +00:00
@ClassCastsIncluded
sealed interface DiceAnimationType {
val emoji: String
val valueLimits: IntRange
2020-04-24 12:25:47 +00:00
}
@Serializable(DiceAnimationTypeSerializer::class)
object CubeDiceAnimationType : DiceAnimationType {
2020-04-24 12:25:47 +00:00
override val emoji: String = "\uD83C\uDFB2"
2020-11-04 17:52:22 +00:00
override val valueLimits: IntRange
2020-11-26 13:37:35 +00:00
get() = dartsCubeAndBowlingDiceResultLimit
2020-04-24 12:25:47 +00:00
}
@Serializable(DiceAnimationTypeSerializer::class)
object DartsDiceAnimationType : DiceAnimationType {
2020-04-24 12:25:47 +00:00
override val emoji: String = "\uD83C\uDFAF"
2020-11-04 17:52:22 +00:00
override val valueLimits: IntRange
2020-11-26 13:37:35 +00:00
get() = dartsCubeAndBowlingDiceResultLimit
2020-04-24 12:25:47 +00:00
}
@Serializable(DiceAnimationTypeSerializer::class)
object BasketballDiceAnimationType : DiceAnimationType {
2020-05-16 14:46:49 +00:00
override val emoji: String = "\uD83C\uDFC0"
2020-11-04 17:52:22 +00:00
override val valueLimits: IntRange
2020-11-26 13:37:35 +00:00
get() = basketballAndFootballDiceResultLimit
}
@Serializable(DiceAnimationTypeSerializer::class)
object FootballDiceAnimationType : DiceAnimationType {
2020-11-04 17:47:01 +00:00
override val emoji: String = ""
2020-11-04 17:52:22 +00:00
override val valueLimits: IntRange
2020-11-26 13:37:35 +00:00
get() = basketballAndFootballDiceResultLimit
2020-11-25 17:09:49 +00:00
}
@Serializable(DiceAnimationTypeSerializer::class)
object BowlingDiceAnimationType : DiceAnimationType {
2020-11-25 17:09:49 +00:00
override val emoji: String = "\uD83C\uDFB3"
override val valueLimits: IntRange
2020-11-26 13:37:35 +00:00
get() = dartsCubeAndBowlingDiceResultLimit
2020-11-04 17:52:22 +00:00
}
@Serializable(DiceAnimationTypeSerializer::class)
object SlotMachineDiceAnimationType : DiceAnimationType {
2020-11-04 17:52:22 +00:00
override val emoji: String = "\uD83C\uDFB0"
override val valueLimits: IntRange
get() = slotMachineDiceResultLimit
2020-11-04 17:47:01 +00:00
}
@Serializable(DiceAnimationTypeSerializer::class)
2020-05-16 14:46:49 +00:00
data class CustomDiceAnimationType(
2020-04-24 12:25:47 +00:00
override val emoji: String
) : DiceAnimationType {
2020-11-04 17:52:22 +00:00
override val valueLimits: IntRange
get() = error("Custom dice animation type have unknown value limits")
}
2020-04-24 12:25:47 +00:00
2021-05-29 09:34:14 +00:00
@RiskFeature
object DiceAnimationTypeSerializer : KSerializer<DiceAnimationType> {
2020-08-18 06:50:11 +00:00
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("DiceAnimationType", PrimitiveKind.STRING)
2020-04-24 12:25:47 +00:00
override fun deserialize(decoder: Decoder): DiceAnimationType {
return when (val type = decoder.decodeString()) {
CubeDiceAnimationType.emoji -> CubeDiceAnimationType
DartsDiceAnimationType.emoji -> DartsDiceAnimationType
2020-05-16 14:46:49 +00:00
BasketballDiceAnimationType.emoji -> BasketballDiceAnimationType
2020-11-02 05:13:16 +00:00
SlotMachineDiceAnimationType.emoji -> SlotMachineDiceAnimationType
2020-11-04 17:47:01 +00:00
FootballDiceAnimationType.emoji -> FootballDiceAnimationType
2020-11-25 17:09:49 +00:00
BowlingDiceAnimationType.emoji -> BowlingDiceAnimationType
2020-05-16 14:46:49 +00:00
else -> CustomDiceAnimationType(type)
2020-04-24 12:25:47 +00:00
}
}
override fun serialize(encoder: Encoder, value: DiceAnimationType) {
encoder.encodeString(value.emoji)
}
}