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

public class Guage : MonoBehaviour
{
    [Header("Assets")]
    [SerializeField] private IntVariable _totalPower = default;
    [SerializeField] private BoolVariable _onState = default;
    [SerializeField] private GameEvent _totalPowerUpdateEvent = default;

    [Header("Refs")]
    [SerializeField] private Animator needleAnimator = default;

    // Start is called before the first frame update
    private void OnEnable()
    {
        _totalPowerUpdateEvent.AddListener(UpdateAnimatorVariable);
    }

    private void OnDisable()
    {
        _totalPowerUpdateEvent.RemoveListener(UpdateAnimatorVariable);
    }

    private void UpdateAnimatorVariable()
    {
        bool lockedOff = _onState != null ? !_onState.Value : false;
        if (lockedOff)
        {
            needleAnimator.SetInteger("GuageValue", 0);
        }
        else
        {
            needleAnimator.SetInteger("GuageValue", _totalPower);
        }
    }
}
