public Transition(FSMEvent trigger, State target, Guard guard, Action action) { this.trigger = trigger; this.target = target; this.guard = guard; this.action = action; }
public Transition(FSMEvent trigger, State target, Guard guard, Action action) { this.trigger = trigger; this.target = target; this.guard = guard; this.action = action; }
public FSMEvent RegisterEvent(string name) { if (registeredEvents.ContainsKey(name)) { throw new ArgumentException("Event '" + name + "' already registered"); } FSMEvent newEvent = new FSMEvent(nextEvent++, name); registeredEvents[name] = newEvent; return(newEvent); }
/// <summary> /// Add a transition. /// </summary> /// <param name="source">The source state name.</param> /// <param name="target">The target state name.</param> /// <param name="eventName">The event name that triggers this transition.</param> /// <param name="predicate">The guard predicate for this transition.</param> /// <param name="action">An action callback to be called if this transition is triggered.</param> public void AddTransition(string source, string target, FSMEvent trigger, Guard guard, Action action) { if (!states.ContainsKey(source)) { throw new ArgumentException("No such source state found"); } if (!states.ContainsKey(target)) { throw new ArgumentException("No such target state found"); } states[source].AddTransition(new Transition(trigger, states[target], guard, action)); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (ReferenceEquals(this, obj)) { return(true); } if (obj.GetType() != typeof(FSMEvent)) { return(false); } FSMEvent other = (FSMEvent)obj; return(id == other.id); }
/// <summary> /// Trigger an event. If a transition exists for this event name in /// the current state, the state will change to the transition's /// target state. /// </summary> /// <param name="eventName">The event name.</param> public void TriggerEvent(FSMEvent evt) { if (currentState == null) { throw new InvalidOperationException("No current state (you may need to call Start)"); } if (!registeredEvents.ContainsKey(evt.Name)) { throw new InvalidOperationException("Event is not registered"); } State newState = currentState.TriggerEvent(evt); if (newState != null) { currentState = newState; } }
internal State TriggerEvent(FSMEvent trigger) { if (!transitions.ContainsKey(trigger)) { return(null); } foreach (Transition transition in transitions[trigger]) { if (transition.CheckGuard()) { FireExitAction(); transition.FireAction(); State newState = transition.Target; newState.FireEnterAction(); return(newState); } } return(null); }
internal State TriggerEvent(FSMEvent trigger) { if(!transitions.ContainsKey(trigger)) { return null; } foreach (Transition transition in transitions[trigger]) { if(transition.CheckGuard()) { FireExitAction(); transition.FireAction(); State newState = transition.Target; newState.FireEnterAction(); return newState; } } return null; }
/// <summary> /// Add a transition. /// </summary> /// <param name="source">The source state name.</param> /// <param name="target">The target state name.</param> /// <param name="eventName">The event name that triggers this transition.</param> public void AddTransition(string source, string target, FSMEvent trigger) { AddTransition(source, target, trigger, null, null); }
/// <summary> /// Add a transition. /// </summary> /// <param name="source">The source state name.</param> /// <param name="target">The target state name.</param> /// <param name="eventName">The event name that triggers this transition.</param> /// <param name="guard">The guard predicate for this transition.</param> public void AddTransition(string source, string target, FSMEvent trigger, Guard guard) { AddTransition(source, target, trigger, guard, null); }
/// <summary> /// Trigger an event. If a transition exists for this event name in /// the current state, the state will change to the transition's /// target state. /// </summary> /// <param name="eventName">The event name.</param> public void TriggerEvent(FSMEvent evt) { if(currentState == null) { throw new InvalidOperationException("No current state (you may need to call Start)"); } if(!registeredEvents.ContainsKey(evt.Name)) { throw new InvalidOperationException("Event is not registered"); } State newState = currentState.TriggerEvent(evt); if(newState != null) { currentState = newState; } }
public FSMEvent RegisterEvent(string name) { if(registeredEvents.ContainsKey(name)) { throw new ArgumentException("Event '" + name + "' already registered"); } FSMEvent newEvent = new FSMEvent(nextEvent ++, name); registeredEvents[name] = newEvent; return newEvent; }
/// <summary> /// Add a transition. /// </summary> /// <param name="source">The source state name.</param> /// <param name="target">The target state name.</param> /// <param name="eventName">The event name that triggers this transition.</param> /// <param name="predicate">The guard predicate for this transition.</param> /// <param name="action">An action callback to be called if this transition is triggered.</param> public void AddTransition(string source, string target, FSMEvent trigger, Guard guard, Action action) { if(!states.ContainsKey(source)) { throw new ArgumentException("No such source state found"); } if(!states.ContainsKey(target)) { throw new ArgumentException("No such target state found"); } states[source].AddTransition(new Transition(trigger, states[target], guard, action)); }
/// <summary> /// Add a transition. /// </summary> /// <param name="source">The source state name.</param> /// <param name="target">The target state name.</param> /// <param name="eventName">The event name that triggers this transition.</param> /// <param name="action">An action callback to be called if this transition is triggered.</param> public void AddTransition(string source, string target, FSMEvent trigger, Action action) { AddTransition(source, target, trigger, null, action); }
/// <summary> /// Add a transition. /// </summary> /// <param name="source">The source state name.</param> /// <param name="target">The target state name.</param> /// <param name="eventName">The event name that triggers this transition.</param> /// <param name="guard">The guard predicate for this transition.</param> public void AddTransition(string source, string target, FSMEvent trigger, Guard guard) { AddTransition(source, target, trigger, guard, null); }