Skip to content

Commit

Permalink
Merge pull request #5 from RoadieRich/return-state-in-AddTransitionTo
Browse files Browse the repository at this point in the history
Adding `return this` to AddTransitionTo to allow chaining methods
  • Loading branch information
RoadieRich authored Jan 11, 2024
2 parents 46a2fdf + 5a0a0e6 commit 337192a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

initFuncState.AddTransitionTo(funcState, (vars) => true);

incrementFuncState.AddTransitionTo(StateMachine.ExitState, (vars) => vars["x"] > 10);
incrementFuncState.AddTransitionTo(funcState, (vars) => true);
incrementFuncState.AddTransitionTo(StateMachine.ExitState, (vars) => vars["x"] > 10)
.AddTransitionTo(funcState, (vars) => true);

funcState.AddTransitionTo(evenFuncState, (vars) => vars["x"] % 2 == 0);
funcState.AddTransitionTo(oddFuncState, (vars) => vars["x"] % 2 == 1);
funcState.AddTransitionTo(evenFuncState, (vars) => vars["x"] % 2 == 0)
.AddTransitionTo(oddFuncState, (vars) => vars["x"] % 2 == 1);

evenFuncState.AddTransitionTo(incrementFuncState, (vars) => true);

Expand Down
2 changes: 1 addition & 1 deletion StateMachine/RoadieRichStateMachine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<RepositoryType>git</RepositoryType>
<Authors>RoadieRich</Authors>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<Version>1.0.4</Version>
<Version>1.0.5</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion StateMachine/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public abstract class State : IDisposable
/// <param name="to">state to transition to</param>
/// <param name="condition">condition to transition. Evaluated each time <see cref="Inner(Dictionary{string, dynamic})"/> is run. If true, the state machine moves to the associated state. Use <c>null</c> to always transition.</param>
/// <remarks>Transition conditions are evaulated in the order they are added.</remarks>
public void AddTransitionTo(State to, TransitionConditionDelegate? condition)
/// <returns>The state this method was called on</returns>
public State AddTransitionTo(State to, TransitionConditionDelegate? condition)
{
transitions.Add(new Transition(to, condition));
return this;
}

internal State RunAndGetNextState(int delay, IDictionary<string, dynamic> vars)
Expand Down

0 comments on commit 337192a

Please sign in to comment.