Exemple #1
0
        /// <summary>
        ///     Peeks a state from the stack. A peek returns null if the stack is empty. It doesn't trigger any call.
        /// </summary>
        /// <returns></returns>
        public StateMB <T> PeekState()
        {
            StateMB <T> state = null;

            if (stack.Count > 0)
            {
                state = stack.Peek();
            }

            return(state);
        }
Exemple #2
0
        /// <summary>
        ///     Checks if a an StateType is the current state.
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public bool IsCurrent(StateMB <T> state)
        {
            if (state == null)
            {
                throw new ArgumentNullException();
            }

            var current = PeekState();

            if (current == null)
            {
                return(false);
            }
            return(current.GetType() == state.GetType());
        }
Exemple #3
0
        /// <summary>
        ///     Pushes state by instance of the class triggering OnEnterState for the
        ///     pushed state and if not silent OnExitState for the previous state in the stack
        /// </summary>
        /// <param name="state"></param>
        /// <param name="isSilent"></param>
        /// <exception cref="EvaluateException"></exception>
        public void PushState(StateMB <T> state, bool isSilent = false)
        {
            if (!statesRegister.ContainsKey(state.GetType()))
            {
                throw new EvaluateException(
                          "State " + state + " not registered yet!");
            }

            Log("Operation: Push, state: " + state.GetType(), "purple");
            if (stack.Count > 0 && !isSilent)
            {
                var previous = stack.Peek();
                previous.OnExitState();
            }

            stack.Push(state);
            state.OnEnterState();
        }