diff --git a/app/src/main/java/net/pokeranalytics/android/model/handhistory/Street.kt b/app/src/main/java/net/pokeranalytics/android/model/handhistory/Street.kt index e45b7d41..ca2bf3cc 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/handhistory/Street.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/handhistory/Street.kt @@ -41,6 +41,14 @@ enum class Street : HandStep { return values()[this.ordinal + 1] } + val previous: Street? + get() { + return when (this) { + PREFLOP -> null + else -> values()[this.ordinal - 1] + } + } + // override fun draw(configuration: ReplayerConfiguration, canvas: Canvas, context: Context) { // TableDrawer.drawStreet(this, configuration, canvas, context) // } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt index cf860749..51a625be 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt @@ -309,13 +309,6 @@ class ActionList(var listener: ActionListListener? = null) : ArrayList() + + /*** + * The total number of added frames in the descriptors + */ + private var totalAddedFrames: Int = 0 + + val totalFrames: Int + get() { return this.totalAddedFrames } + + /*** + * Adds a frame descriptor with a frame [type] and a frame [count] + */ + fun add(type: FrameType, count: Int) { + val fd = FrameDescriptor(type, count, this.totalAddedFrames) + this.descriptors.add(fd) + this.totalAddedFrames += count + } + + /*** + * + */ + fun frameType(frame: Int): FrameType { + + this.descriptors.forEach { descriptor -> + if (frame in descriptor.range) { + return descriptor.type + } + } + + throw PAIllegalStateException("frame $frame asked out of $totalAddedFrames defined frames, descriptor count = ${this.descriptors.size}") + } + + fun reset() { + this.descriptors.clear() + this.totalAddedFrames = 0 + } + +} \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt index 1893f350..5a5b1708 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt @@ -12,18 +12,11 @@ import net.pokeranalytics.android.ui.modules.handhistory.model.ComputedAction import net.pokeranalytics.android.util.MathUtils import timber.log.Timber import kotlin.math.max -import kotlin.math.min class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { // Steps & Frames - enum class FrameType(val visualOccurences: Int) { - STATE(150), - GATHER_ANIMATION(4), - DISTRIBUTION_ANIMATION(4) - } - /*** * The number of frames per second */ @@ -42,17 +35,55 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { private val framesForChipsAnimation: Int get() { return (chipAnimationDuration / animationRate).toInt() } + private var frameManager = FrameManager() + + private fun defineFramesForCurrentStep() { + this.frameManager.reset() + + when (val step = this.currentStep) { + is ComputedAction -> this.frameManager.add(FrameType.STATE, 1) + is Street -> { + // gather animation if chips have been committed in the street + if (this.actionList.streetHasSignificantAction(step)) { + this.frameManager.add(FrameType.GATHER_ANIMATION, framesForChipsAnimation) + } + // Chip distribution animation on the Summary + if (step == Street.SUMMARY) { + this.frameManager.add(FrameType.DISTRIBUTION_ANIMATION, framesForChipsAnimation) + } + this.frameManager.add(FrameType.STATE, 1) + } + else -> throw PAIllegalStateException("unmanaged step: $step") + } + + } + /*** * The total number of frames for each kind of step */ private val numberOfFramesForCurrentStep: Int get() { - return when (val step = this.currentStep) { - is ComputedAction -> 1 - Street.SUMMARY -> 1 + 2 * framesForChipsAnimation // 2 animations - is Street -> 1 + framesForChipsAnimation - else -> throw PAIllegalStateException("unmanaged step: $step") - } + return this.frameManager.totalFrames +// return when (val step = this.currentStep) { +// is ComputedAction -> 1 +// is Street -> { +// var frames = 1 +// // gather animation if chips have been committed in the street +// if (this.actionList.streetHasSignificantAction(step)) { +// frames += framesForChipsAnimation +// } +// // Chip distribution animation on the Summary +// if (step == Street.SUMMARY) { +// frames += framesForChipsAnimation +// } +// frames +// } +// +// +//// Street.SUMMARY -> 1 + 2 * framesForChipsAnimation // 2 animations +//// is Street -> 1 + framesForChipsAnimation +// else -> throw PAIllegalStateException("unmanaged step: $step") +// } } /*** @@ -65,29 +96,36 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { */ val frameType: FrameType get() { - return when (val step = this.currentStep) { - is ComputedAction -> FrameType.STATE - Street.SUMMARY -> { - when (this.currentFrame) { - in (0 until framesForChipsAnimation) -> FrameType.GATHER_ANIMATION - in (framesForChipsAnimation until 2 * framesForChipsAnimation) -> FrameType.DISTRIBUTION_ANIMATION - else -> FrameType.STATE - } - } - is Street -> { - when (this.currentFrame) { - in (0 until framesForChipsAnimation) -> FrameType.GATHER_ANIMATION - else -> FrameType.STATE - } - } - else -> throw PAIllegalStateException("unmanaged step: $step") - } + return this.frameManager.frameType(this.currentFrame) + +// return when (val step = this.currentStep) { +// is ComputedAction -> FrameType.STATE +// Street.SUMMARY -> { +// when (this.currentFrame) { +// in (0 until framesForChipsAnimation) -> FrameType.GATHER_ANIMATION +// in (framesForChipsAnimation until 2 * framesForChipsAnimation) -> FrameType.DISTRIBUTION_ANIMATION +// else -> FrameType.STATE +// } +// } +// is Street -> { +// when (this.currentFrame) { +// in (0 until framesForChipsAnimation) -> FrameType.GATHER_ANIMATION +// else -> FrameType.STATE +// } +// } +// else -> throw PAIllegalStateException("unmanaged step: $step") +// } } + /*** + * Returns the number of visual occurrences for the current frame + * This function returns a longer value for the last frame of the last step + * because some player auto-replay videos because we want the viewer to have a pause. + */ private val visualOccurences: Int get() { return if (this.currentStepIndex == this.steps.size - 1 && this.currentFrame == this.numberOfFramesForCurrentStep - 1) { - FrameType.STATE.visualOccurences * 4 + FrameType.STATE.visualOccurences * 5 } else { this.frameType.visualOccurences } @@ -122,6 +160,7 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { val backwards = value < field field = value + defineFramesForCurrentStep() // if we go backwards we don't want to perform an animation, otherwise we want this.currentFrame = if (backwards) this.numberOfFramesForCurrentStep - 1 else 0 } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt index 635a5b8e..b6c104b1 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt @@ -159,7 +159,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { when (animator.currentStep) { is Street -> { when (animator.frameType) { - ReplayerAnimator.FrameType.STATE -> { + FrameType.STATE -> { if (animator.currentStep == Street.SUMMARY) { val winnerPots = animator.handHistory.winnerPots.firstOrNull { it.position == i } @@ -172,14 +172,14 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { } } - ReplayerAnimator.FrameType.GATHER_ANIMATION -> { + FrameType.GATHER_ANIMATION -> { lastCommittedAmount(i, animator)?.let { amount -> val color = colorForAmount(amount) val circle = animator.animatedChipCircleToPot(i) drawChipCircle(circle, color, canvas, context) } } - ReplayerAnimator.FrameType.DISTRIBUTION_ANIMATION -> { + FrameType.DISTRIBUTION_ANIMATION -> { val winnerPots = animator.handHistory.winnerPots.firstOrNull { it.position == i } winnerPots?.let { pot -> @@ -454,7 +454,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { private fun drawPot(street: Street, computedAction: ComputedAction?, animator: ReplayerAnimator, canvas: Canvas, context: Context) { - if (street == Street.SUMMARY && animator.frameType != ReplayerAnimator.FrameType.GATHER_ANIMATION) { + if (street == Street.SUMMARY && animator.frameType != FrameType.GATHER_ANIMATION) { return }