Skip to content

Commit

Permalink
slotmachine utils
Browse files Browse the repository at this point in the history
  • Loading branch information
InsanusMokrassar committed Nov 2, 2020
1 parent ea6ab8f commit a10d766
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit a10d766

Please sign in to comment.