Example #1
0
 /// <exception cref="FsmBuilderException">When the model is null</exception>
 public Fsm(FsmModel <TS, TT> model)
 {
     Model = model ?? throw FsmBuilderException.ModelCannotBeNull();
     if (Model.StackEnabled && !model.Current.ClearStack)
     {
         Model.Stack.Push(model.Current);
     }
 }
Example #2
0
 /// <exception cref="FsmBuilderException">When the initial state is null</exception>
 public Fsm(State <TS, TT> current, bool stackEnabled = false)
 {
     Model.StackEnabled = stackEnabled;
     Model.Current      = current ?? throw FsmBuilderException.StateCannotBeNull();
     if (Model.StackEnabled && !current.ClearStack)
     {
         Model.Stack.Push(current);
     }
 }
Example #3
0
 /// <exception cref="FsmBuilderException">
 ///     When the transition is null or another transition already leads to the same
 ///     target state
 /// </exception>
 public Fsm <TS, TT> Add(Transition <TS, TT> t)
 {
     if (t == null)
     {
         throw FsmBuilderException.TransitionCannotBeNull();
     }
     Model.GlobalTransitions.Add(t.Target, t);
     return(this);
 }
Example #4
0
 /// <exception cref="FsmBuilderException">When the handler is null</exception>
 public Fsm <TS, TT> AddStateChangeHandler(
     EventHandler <StateChangeArgs <TS, TT> > e)
 {
     if (e == null)
     {
         throw FsmBuilderException.HandlerCannotBeNull();
     }
     Model.StateChanged += e;
     return(this);
 }
Example #5
0
        /// <exception cref="FsmBuilderException">When the state is null or the state has already been added before</exception>
        public Fsm <TS, TT> Add(State <TS, TT> state)
        {
            if (state == null)
            {
                throw FsmBuilderException.StateCannotBeNull();
            }
            if (Model.States.ContainsKey(state.Identifier))
            {
                throw FsmBuilderException.StateCanOnlyBeAddedOnce(state);
            }

            Model.States.Add(state.Identifier, state);
            return(this);
        }
Example #6
0
 public void AddStateChangedHandler(
     EventHandler <StateChangeArgs <TS, TT> > e)
 {
     StateChanged += e ?? throw FsmBuilderException.HandlerCannotBeNull();
 }
Example #7
0
 /// <exception cref="FsmBuilderException">When the handler is null</exception>
 public void AddUpdatedHandler(Action <UpdateArgs <TS, TT> > e)
 {
     Updated += e ?? throw FsmBuilderException.HandlerCannotBeNull();
 }
Example #8
0
 /// <exception cref="FsmBuilderException">When the handler is null</exception>
 public void AddExitedHandler(Action <StateChangeArgs <TS, TT> > e)
 {
     Exited += e ?? throw FsmBuilderException.HandlerCannotBeNull();
 }