@@ -34,7 +34,10 @@ namespace StateMachine.Fluent.Api
3434 public class FluentImplementation < TS , TT , TD > : GlobalTransitionBuilderFluent < TS , TT , TD > ,
3535 TransitionStateFluent < TS , TT , TD >
3636 {
37- protected FsmModel < TS , TT , TD > FsmModel { get ; set ; } = new FsmModel < TS , TT , TD > ( ) ;
37+ public Dictionary < Tuple < TS , TS > , List < Timer < TS > > > AfterEntries { get ; set ; } = new Dictionary < Tuple < TS , TS > , List < Timer < TS > > > ( ) ;
38+ public List < Timer < TS > > GlobalAfterEntries { get ; set ; } = new List < Timer < TS > > ( ) ;
39+
40+ protected FsmModel < TS , TT , TD > FsmModel { get ; set ; } = new FsmModel < TS , TT , TD > ( ) ;
3841 protected TS startState ;
3942
4043 protected Tuple < TS > currentState ;
@@ -65,8 +68,27 @@ public Fsm<TS, TT, TD> Build()
6568 FsmModel . Current = FsmModel . States [ startState ] ;
6669 return new Fsm < TS , TT , TD > ( FsmModel ) ;
6770 }
68-
69- public StateFluent < TS , TT , TD > State ( TS state )
71+
72+ public TransitionStateFluent < TS , TT , TD > After ( float amount , TimeUnit timeUnit )
73+ {
74+ var key = currentTransition ;
75+ if ( ! AfterEntries . TryGetValue ( key , out var l ) )
76+ {
77+ l = new List < Timer < TS > > ( ) ;
78+ AfterEntries . Add ( key , l ) ;
79+ }
80+ l . Add ( new Timer < TS > ( key . Item2 , amount , timeUnit ) ) ;
81+ return this ;
82+ }
83+
84+ public TransitionStateFluent < TS , TT , TD > AfterGlobal ( float amount , TimeUnit timeUnit )
85+ {
86+ var key = currentGlobalTransition ;
87+ GlobalAfterEntries . Add ( new Timer < TS > ( key . Item1 , amount , timeUnit ) ) ;
88+ return this ;
89+ }
90+
91+ public StateFluent < TS , TT , TD > State ( TS state )
7092 {
7193 currentState = Tuple . Create ( state ) ;
7294 if ( ! FsmModel . States . ContainsKey ( state ) )
@@ -98,14 +120,12 @@ public StateFluent<TS, TT, TD> Update(Action<UpdateArgs<TS, TT, TD>> update)
98120 public GlobalTransitionFluent < TS , TT , TD > GlobalTransitionTo ( TS state )
99121 {
100122 currentGlobalTransition = Tuple . Create ( state ) ;
101- if ( ! globalTransitionModels . ContainsKey ( currentGlobalTransition ) )
102- {
103- globalTransitionModels [ currentGlobalTransition ] = new TransitionModel < TS , TT > ( startState , state ) ;
104- new TransitionModel < TS , TT > ( startState , state ) ;
105- FsmModel . GlobalTransitions [ state ] =
106- new Transition < TS , TT , TD > ( globalTransitionModels [ currentGlobalTransition ] ) ;
107- }
108- return this ;
123+ if ( globalTransitionModels . ContainsKey ( currentGlobalTransition ) ) return this ;
124+
125+ globalTransitionModels [ currentGlobalTransition ] = new TransitionModel < TS , TT > ( startState , state ) ;
126+ FsmModel . GlobalTransitions [ state ] =
127+ new Transition < TS , TT , TD > ( globalTransitionModels [ currentGlobalTransition ] ) ;
128+ return this ;
109129 }
110130
111131 public GlobalTransitionBuilderFluent < TS , TT , TD > OnGlobal ( TT trigger )
0 commit comments