using System;
using UnityEngine;
using mgaia.Utils;

namespace mgaia.tk2d.Animations
{
    public class Tk2dSlicedSpriteDimensionAnimation : AbstractCodeAnimation
    {
        private tk2dSlicedSprite[] mSprites;

        public Tk2dSlicedSpriteDimensionAnimation(float[] keyTimes, ValueType[] keyValues, ValueType initialValue, bool loop) : base(keyTimes, keyValues, initialValue, loop) { }

        protected override void Lerp(ValueType fromValue, ValueType toValue, float normalizedTime)
        {
            mSprites.ForEach(sprite => sprite.dimensions = Vector2.Lerp((Vector2)fromValue, (Vector2)toValue, normalizedTime));
        }

        protected override void OnActivateAnimation(object[] objs)
        {
            mSprites = objs.Select(obj => obj as tk2dSlicedSprite).ToArray();
        }
    }
}