diff --git a/CHANGELOG.md b/CHANGELOG.md index d586d95e02..69028b1f66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ ## 0.29.4 +* `Core`: + * `diceResultLimit` now is deprecated, use `commonDiceResultLimit` instead + * New extension `slotMachineDiceResultLimit` +* `Utils`: + * New enum `SlotMachineReelImages` + * New extension `Int#asSlotMachineReelImage` + * New data class `SlotMachineResult` + * New extension `Dice#calculateSlotMachineResult` + ## 0.29.3 * `Common`: diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 21c8e1c9df..0d3a71a24e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -52,7 +52,11 @@ val inlineQueryAnswerResultsLimit = 0 .. 50 val customTitleLength = 0 .. 16 -val diceResultLimit = 1 .. 6 +val commonDiceResultLimit = 1 .. 6 +@Deprecated("Renamed", ReplaceWith("commonDiceResultLimit", "dev.inmo.tgbotapi.types.commonDiceResultLimit")) +val diceResultLimit + get() = commonDiceResultLimit +val slotMachineDiceResultLimit = 1 .. 64 val botCommandLengthLimit = 1 .. 32 val botCommandLimit = botCommandLengthLimit diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SlotMachineUtils.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SlotMachineUtils.kt new file mode 100644 index 0000000000..4ac9cd338e --- /dev/null +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SlotMachineUtils.kt @@ -0,0 +1,43 @@ +package dev.inmo.tgbotapi.extensions.utils + +import dev.inmo.tgbotapi.types.DiceResult +import dev.inmo.tgbotapi.types.dice.Dice +import dev.inmo.tgbotapi.types.dice.SlotMachineDiceAnimationType +import kotlinx.serialization.Serializable +import kotlinx.serialization.Transient + +enum class SlotMachineReelImages { + BAR, BERRIES, LEMON, SEVEN +} +val Int.asSlotMachineReelImage + get() = when (this) { + 0 -> SlotMachineReelImages.BAR + 1 -> SlotMachineReelImages.BERRIES + 2 -> SlotMachineReelImages.LEMON + else -> SlotMachineReelImages.SEVEN + } + +@Serializable +data class SlotMachineResult( + val rawValue: DiceResult +) { + @Transient + val left = rawValue and 3 + @Transient + val center = rawValue shr 2 and 3 + @Transient + val right = rawValue shr 4 + + @Transient + val leftReel = left.asSlotMachineReelImage + @Transient + val centerReel = center.asSlotMachineReelImage + @Transient + val rightReel = right.asSlotMachineReelImage +} + +fun Dice.calculateSlotMachineResult() = if (animationType == SlotMachineDiceAnimationType) { + SlotMachineResult(value - 1) +} else { + null +}