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.*

interface Timeline {
    val duration: Float
    val frames: List
//    val propertyIds: List

    fun apply(context: AnimationContext)

}

class BoneAnimationContext(
    val bone: Bone,
    val context: AnimationContext,
)

class SlotAnimationContext(
    val slot: Slot,
    val 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,
) {
    fun getBoneContext(boneIndex: Int): BoneAnimationContext? {
        val bone = skeleton.bones.getOrNull(boneIndex) ?: return null
        if (!bone.isActive) return null
        return BoneAnimationContext(bone, this)
    }

    fun getSlotContext(slotIndex: Int): SlotAnimationContext? {
        val slot = skeleton.slots.getOrNull(slotIndex) ?: return null
        if (!slot.bone.isActive) return null
        return SlotAnimationContext(slot, this)
    }
}

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 }

    companion object {
        fun createFrame(time: Float, value: Float, curve: Curve, channelIndex: Int = 0): ChannelFrame {
            val actualCurve = curve
//                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