commonMain.ru.casperix.spine.animation.Timeline.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spine-jvm Show documentation
Show all versions of spine-jvm Show documentation
Signals for all occasions
The newest version!
package ru.casperix.spine.animation
import ru.casperix.spine.Event
import ru.casperix.spine.MixBlend
import ru.casperix.spine.MixDirection
import ru.casperix.spine.Skeleton
import ru.casperix.spine.json.component.Curve
import ru.casperix.spine.json.component.TupleBezierCurve
interface Timeline {
val duration: Float
val frames: List
// val propertyIds: List
fun apply(context: AnimationContext)
}
class AnimationContext(
val skeleton: Skeleton,
val lastTime: Float,
val time: Float,
val events: List,
val weight: Float,
val blend: MixBlend,
val direction: MixDirection,
)
data class ChannelFrame(
val time: Float,
val value: Float,
val curve: Curve,
)
abstract class AbstractTimeline(frames: List) : Timeline {
final override val duration: Float = frames.maxOf { it.time }
fun createFrame(time: Float, value: Float, curve: Curve, channelIndex: Int = 0): ChannelFrame {
val actualCurve = if (curve is TupleBezierCurve) {
when (channelIndex) {
0 -> curve.first
1 -> curve.second
else -> throw Exception("Support only two sub-curve")
}
} else curve
return ChannelFrame(time, value, actualCurve)
}
}
interface BoneTimeline {
val boneIndex: Int
}
interface CurveTimeline : Timeline {
override val frames: List
companion object {
val LINEAR = 0
val STEPPED = 1
val BEZIER = 2
val BEZIER_SIZE = 18
}
}
interface CurveTimeline1 : CurveTimeline {
companion object {
const val VALUE = 1
const val ENTRIES = 2
}
}