using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace ToadieTechnika.GGJ2018Game
{
    public class AnimEaseInOutScale : MonoBehaviour
    {
        [SerializeField]
        Vector3 m_SineWaveManipulation;
        float m_CurrentTime;

        [SerializeField]
        bool m_isAbsolute;
        Vector2 m_NormalScale;
        bool m_isInit;

        void OnEnable()
        {
            if (!m_isInit)
            {
                m_NormalScale = transform.localScale;
                m_isInit = true;
            }

            m_CurrentTime = Random.Range(-10f, 10f);
            SineWaveScaleManipulation();
        }

        void Update()
        {
            m_CurrentTime += Time.deltaTime * m_SineWaveManipulation.z;
            SineWaveScaleManipulation();
        }

        void SineWaveScaleManipulation()
        {
            transform.localScale = new Vector2(SetSineWaveValue, SetSineWaveValue);
        }

        float SetSineWaveValue
        {
            get 
            { 
                //Assume the scale are equal
                if (m_isAbsolute)
                    return m_NormalScale.x + Mathf.Abs(Mathf.Sin(m_CurrentTime * m_SineWaveManipulation.x) * m_SineWaveManipulation.y); 
                else
                    return m_NormalScale.x + Mathf.Sin(m_CurrentTime * m_SineWaveManipulation.x) * m_SineWaveManipulation.y; 
            }
        }
    }
}