|
|
|
|
@ -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 |
|
|
|
|
} |
|
|
|
|
|