Skip to content

Commit

Permalink
Add State.AddToGroups, StateGroup.AddToState, and StateGroup.AddToStates
Browse files Browse the repository at this point in the history
  • Loading branch information
canton7 committed Sep 1, 2015
1 parent a279bc8 commit 98847a1
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/StateMechanic/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,19 @@ public ChildStateMachine CreateChildStateMachine()
public void AddToGroup(StateGroup group)
{
this.innerState.AddGroup(group);
group.AddState(this);
group.AddStateInternal(this);
}

/// <summary>
/// Add this state to the given groups
/// </summary>
/// <param name="groups">Grousp to add this state to</param>
public void AddToGroups(params StateGroup[] groups)
{
foreach (var group in groups)
{
this.AddToGroup(group);
}
}

void IState<State>.FireEntryHandler(StateHandlerInfo<State> info)
Expand Down
23 changes: 22 additions & 1 deletion src/StateMechanic/StateGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ public StateGroup WithExit(Action<StateHandlerInfo<State>> exitHandler)
return this;
}

/// <summary>
/// Add the given state to this group
/// </summary>
/// <param name="state">State to add to this group</param>
public void AddState(State state)
{
state.AddToGroup(this);
}

/// <summary>
/// Add the given states to this group
/// </summary>
/// <param name="states">States to add to this group</param>
public void AddStates(params State[] states)
{
foreach (var state in States)
{
state.AddToGroup(this);
}
}

void IStateGroup<State>.FireEntryHandler(StateHandlerInfo<State> info)
{
this.innerStateGroup.FireEntryHandler(info);
Expand All @@ -88,7 +109,7 @@ void IStateGroup<State>.FireExitHandler(StateHandlerInfo<State> info)
this.innerStateGroup.FireExitHandler(info);
}

internal void AddState(State state)
internal void AddStateInternal(State state)
{
this.innerStateGroup.AddState(state);
}
Expand Down
23 changes: 22 additions & 1 deletion src/StateMechanic/StateGroup`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ public StateGroup<TStateData> WithExit(Action<StateHandlerInfo<State<TStateData>
return this;
}

/// <summary>
/// Add the given state to this group
/// </summary>
/// <param name="state">State to add to this group</param>
public void AddState(State<TStateData> state)
{
state.AddToGroup(this);
}

/// <summary>
/// Add the given states to this group
/// </summary>
/// <param name="states">States to add to this group</param>
public void AddStates(params State<TStateData>[] states)
{
foreach (var state in States)
{
state.AddToGroup(this);
}
}

void IStateGroup<State<TStateData>>.FireEntryHandler(StateHandlerInfo<State<TStateData>> info)
{
this.innerStateGroup.FireEntryHandler(info);
Expand All @@ -86,7 +107,7 @@ void IStateGroup<State<TStateData>>.FireExitHandler(StateHandlerInfo<State<TStat
this.innerStateGroup.FireExitHandler(info);
}

internal void AddState(State<TStateData> state)
internal void AddStateInternal(State<TStateData> state)
{
this.innerStateGroup.AddState(state);
}
Expand Down
14 changes: 13 additions & 1 deletion src/StateMechanic/State`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,19 @@ public ChildStateMachine<TStateData> CreateChildStateMachine()
public void AddToGroup(StateGroup<TStateData> group)
{
this.innerState.AddGroup(group);
group.AddState(this);
group.AddStateInternal(this);
}

/// <summary>
/// Add this state to the given groups
/// </summary>
/// <param name="groups">Grousp to add this state to</param>
public void AddToGroups(params StateGroup<TStateData>[] groups)
{
foreach (var group in groups)
{
this.AddToGroup(group);
}
}

void IState<State<TStateData>>.FireEntryHandler(StateHandlerInfo<State<TStateData>> info)
Expand Down

0 comments on commit 98847a1

Please sign in to comment.