using UnityEngine;
using System;
using System.Collections.Generic;
using mgaia.Utils;

namespace mgaia.tk2d.Animations
{
    public class Tk2dSpriteAlphaAnimation : AbstractCodeAnimation
    {
        private tk2dBaseSprite[] mSprites;

        public Tk2dSpriteAlphaAnimation(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.color = new Color
                (
                    sprite.color.r,
                    sprite.color.g,
                    sprite.color.b,
                    Mathf.Lerp((float)fromValue, (float)toValue, normalizedTime)
                ));
        }

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