From 7c81634fd85e9d698bc58c55069d20352eeeb349 Mon Sep 17 00:00:00 2001 From: rlovely Date: Thu, 11 Jan 2024 15:25:49 -0500 Subject: [PATCH 1/2] Adding `return this` to AddTransitionTo to allow chaining methods --- StateMachine/RoadieRichStateMachine.csproj | 2 +- StateMachine/State.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/StateMachine/RoadieRichStateMachine.csproj b/StateMachine/RoadieRichStateMachine.csproj index 8a7d921..fda725f 100644 --- a/StateMachine/RoadieRichStateMachine.csproj +++ b/StateMachine/RoadieRichStateMachine.csproj @@ -13,7 +13,7 @@ git RoadieRich True - 1.0.4 + 1.0.5 diff --git a/StateMachine/State.cs b/StateMachine/State.cs index 937b73e..0095400 100644 --- a/StateMachine/State.cs +++ b/StateMachine/State.cs @@ -14,9 +14,10 @@ public abstract class State : IDisposable /// state to transition to /// condition to transition. Evaluated each time is run. If true, the state machine moves to the associated state. Use null to always transition. /// Transition conditions are evaulated in the order they are added. - public void AddTransitionTo(State to, TransitionConditionDelegate? condition) + public State AddTransitionTo(State to, TransitionConditionDelegate? condition) { transitions.Add(new Transition(to, condition)); + return this; } internal State RunAndGetNextState(int delay, IDictionary vars) From 5a0a0e62b7438023df9da9e044d12a7f8b821fe1 Mon Sep 17 00:00:00 2001 From: rlovely Date: Thu, 11 Jan 2024 15:31:14 -0500 Subject: [PATCH 2/2] utilizing chainable AddTransitionTo in Demo project --- Demo/Program.cs | 8 ++++---- StateMachine/State.cs | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Demo/Program.cs b/Demo/Program.cs index 12f3e5d..904dfaf 100644 --- a/Demo/Program.cs +++ b/Demo/Program.cs @@ -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); diff --git a/StateMachine/State.cs b/StateMachine/State.cs index 0095400..0a19262 100644 --- a/StateMachine/State.cs +++ b/StateMachine/State.cs @@ -14,6 +14,7 @@ public abstract class State : IDisposable /// state to transition to /// condition to transition. Evaluated each time is run. If true, the state machine moves to the associated state. Use null to always transition. /// Transition conditions are evaulated in the order they are added. + /// The state this method was called on public State AddTransitionTo(State to, TransitionConditionDelegate? condition) { transitions.Add(new Transition(to, condition));