-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea6ab8f
commit a10d766
Showing
3 changed files
with
57 additions
and
1 deletion.
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
43 changes: 43 additions & 0 deletions
43
...nsions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SlotMachineUtils.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,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 | ||
} |