/// <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); } }
/// <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); } }
/// <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); }
/// <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); }
/// <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); }
public void AddStateChangedHandler( EventHandler <StateChangeArgs <TS, TT> > e) { StateChanged += e ?? throw FsmBuilderException.HandlerCannotBeNull(); }
/// <exception cref="FsmBuilderException">When the handler is null</exception> public void AddUpdatedHandler(Action <UpdateArgs <TS, TT> > e) { Updated += e ?? throw FsmBuilderException.HandlerCannotBeNull(); }
/// <exception cref="FsmBuilderException">When the handler is null</exception> public void AddExitedHandler(Action <StateChangeArgs <TS, TT> > e) { Exited += e ?? throw FsmBuilderException.HandlerCannotBeNull(); }