using Utility;

namespace Core.State
{
    public class StateControl
    {
        public Map<string, IState> States
        {
            get { return _states; }
        }

        private Map<string, IState> _states = new Map<string, IState>();

        public IState CurrIState
        {
            get { return _currIState; }
        }
        private IState _currIState;
        public void AddState(string name, IState state)
        {
            _states[name] = state;
        }

        public void Update(float t)
        {
            if (_currIState != null)
            {
                _currIState.Update(t);
            }
        }

        public void ChangeState(string name)
        {
            if (!_states.TryGetValue(name,out IState state))
            {
                return;
            }

            if (_currIState != null)
            {
                _currIState.Exit();
            }
            _currIState = state;
            _currIState.Enter();
        }
       
    }
}