Esempio n. 1
0
        private void CheckTransitions()
        {
            while (_pushedTriggers.Count != 0)
            {
                FTrigger trigger = _pushedTriggers.Dequeue();

                for (int i = 0; i < _activeStates.Count; ++i)
                {
                    IState state = _activeStates[i];

                    ITransition transition = state.CheckTransitions(trigger);

                    if (transition != null)
                    {
                        if (transition.Target is IHistoryState historyState)
                        {
                            if (historyState.LastState == null)
                            {
                                FAssert.IsNotNull(historyState.Parent, $"`{historyState.Name}` parent is null. A history state should always have parent!");
                                historyState.LastState = historyState.Parent.InitialState;
                            }

                            FireTransition(state, new FTransition(transition.Trigger, historyState.LastState, transition.Condition, transition.Actions));
                        }
                        else
                        {
                            FireTransition(state, transition);
                        }

                        break;
                    }
                }
            }
        }
Esempio n. 2
0
        public void AddTransition(FTrigger trigger, IState target)
        {
            FAssert.IsTrue(trigger != null, "Trigger is invalid.");
            FAssert.IsNotNull(target, $"Target state can't be null.");

            _transitions.Add(new FTransition(trigger, target));
        }
Esempio n. 3
0
        public void AddTransition(FTrigger trigger, IState target, IEnumerable <ITransitionAction> actions)
        {
            FAssert.IsTrue(trigger != null, "Trigger is invalid.");
            FAssert.IsNotNull(target, $"Target state can't be null.");
            FAssert.IsNotNull(actions, "Actions can't be null");

            _transitions.Add(new FTransition(trigger, target, actions));
        }
Esempio n. 4
0
        public void AddTransition(FTrigger trigger, IState target, ICondition condition, ITransitionAction action)
        {
            FAssert.IsTrue(trigger != null, "Trigger is invalid.");
            FAssert.IsNotNull(target, $"Target state can't be null.");
            FAssert.IsNotNull(condition, $"Condition can't be null.");
            FAssert.IsNotNull(action, "Action can't be null");

            _transitions.Add(new FTransition(trigger, target, condition, action));
        }
Esempio n. 5
0
        public void PushTrigger(FTrigger trigger)
        {
            _pushedTriggers.Enqueue(trigger);

            if (_isCheckingTransitions == false)
            {
                _isCheckingTransitions = true;
                CheckTransitions();
                _isCheckingTransitions = false;
            }
        }
Esempio n. 6
0
        ITransition IState.CheckTransitions(FTrigger trigger)
        {
            for (int i = 0; i < _transitions.Count; i++)
            {
                ITransition transaction = _transitions[i];

                if (transaction.IsTriggered(trigger))
                {
                    return(transaction);
                }
            }

            return(null);
        }
Esempio n. 7
0
 bool ITransition.IsTriggered(FTrigger trigger)
 {
     return(this._trigger == trigger && (_condition == null || _condition.Evaluate()));
 }
Esempio n. 8
0
 public FTransition(FTrigger trigger, IState target, ICondition condition, IEnumerable <ITransitionAction> actions) : this(trigger, target, condition)
 {
     this._actions.AddRange(actions);
 }
Esempio n. 9
0
 public FTransition(FTrigger trigger, IState target, ICondition condition, ITransitionAction action) : this(trigger, target, condition)
 {
     _actions.Add(action);
 }
Esempio n. 10
0
 public FTransition(FTrigger trigger, IState target, ICondition condition) : this(trigger, target)
 {
     this._condition = condition;
 }
Esempio n. 11
0
 public FTransition(FTrigger trigger, IState target) : this(trigger)
 {
     this._target = target;
 }
Esempio n. 12
0
 private FTransition(FTrigger trigger)
 {
     this._trigger = trigger;
 }