All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.ru.casperix.spine.animation.Timeline.kt Maven / Gradle / Ivy

There is a newer version: 0.9.0
Show 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
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy