Skip to content

Commit 3990589

Browse files
committed
Updates project.
1 parent e443447 commit 3990589

File tree

8 files changed

+78
-41
lines changed

8 files changed

+78
-41
lines changed

MonoGameStateMachine/Api/BuilderFluent.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
// For more information, please refer to <http://unlicense.org>
2626
// ***************************************************************************
2727

28+
using JetBrains.Annotations;
29+
2830
namespace MonoGameStateMachine.Api
2931
{
32+
[PublicAPI]
3033
public interface BuilderFluent<TS, TT, TD>
3134
{
3235
/// <summary>

MonoGameStateMachine/Api/FluentImplementation.cs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,52 @@
2727

2828
using System;
2929
using System.Collections.Generic;
30-
using StateMachine;
3130
using StateMachine.Events;
3231

3332
namespace MonoGameStateMachine.Api
3433
{
35-
public class FluentImplementation<TS, TT, TD> :
36-
StateMachine.Fluent.Api.FluentImplementation<TS, TT, TD>,
34+
public class FluentImplementation<TS, TT, TD> : StateMachine.Fluent.Api.FluentImplementation<TS, TT, TD>,
3735
TransitionStateFluent<TS, TT, TD>, GlobalTransitionBuilderFluent<TS, TT, TD>
3836
{
39-
protected new Dictionary<Tuple<TS, TS>, TransitionModel<TS, TT, TD>> transitionModels =
40-
new Dictionary<Tuple<TS, TS>, TransitionModel<TS, TT, TD>>();
37+
public Dictionary<Tuple<TS, TS>, List<Timer>> AfterEntries { get; set; } = new Dictionary<Tuple<TS, TS>, List<Timer>>();
38+
public Dictionary<Tuple<TS>, List<Timer>> GlobalAfterEntries { get; set; } = new Dictionary<Tuple<TS>, List<Timer>>();
4139

4240
public FluentImplementation(TS startState) : base(startState)
4341
{
4442
}
4543

4644
public new Fsm<TS, TT, TD> Build()
4745
{
48-
if (FsmModel.States[startState] == null)
49-
{
50-
throw FsmBuilderException.StartStateCannotBeNull();
51-
}
52-
53-
FsmModel.Current = FsmModel.States[startState];
54-
Fsm<TS, TT, TD> fsm = new Fsm<TS, TT, TD>(FsmModel);
55-
return fsm;
46+
base.Build();
47+
var m = new Fsm<TS, TT, TD>(FsmModel);
48+
m.AfterEntries = AfterEntries;
49+
m.GlobalAfterEntries = GlobalAfterEntries;
50+
return m;
5651
}
5752

5853
public TransitionStateFluent<TS, TT, TD> After(float amount, TimeUnit timeUnit)
5954
{
60-
throw new NotImplementedException();
55+
List<Timer> l;
56+
var key = currentTransition;
57+
if (!AfterEntries.TryGetValue(key, out l))
58+
{
59+
l = new List<Timer>();
60+
AfterEntries.Add(key, l);
61+
}
62+
l.Add(new Timer(amount, timeUnit));
6163
return this;
6264
}
6365

6466
public TransitionStateFluent<TS, TT, TD> AfterGlobal(float amount, TimeUnit timeUnit)
6567
{
66-
throw new NotImplementedException();
68+
List<Timer> l;
69+
var key = currentGlobalTransition;
70+
if (!GlobalAfterEntries.TryGetValue(key, out l))
71+
{
72+
l = new List<Timer>();
73+
GlobalAfterEntries.Add(key, l);
74+
}
75+
l.Add(new Timer(amount, timeUnit));
6776
return this;
6877
}
6978

@@ -135,13 +144,13 @@ public TransitionStateFluent<TS, TT, TD> AfterGlobal(float amount, TimeUnit time
135144
return this;
136145
}
137146

138-
public GlobalTransitionBuilderFluent<TS, TT, TD> OnGlobal(TT trigger)
147+
public new GlobalTransitionBuilderFluent<TS, TT, TD> OnGlobal(TT trigger)
139148
{
140149
base.OnGlobal(trigger);
141150
return this;
142151
}
143152

144-
public GlobalTransitionBuilderFluent<TS, TT, TD> IfGlobal(
153+
public new GlobalTransitionBuilderFluent<TS, TT, TD> IfGlobal(
145154
Func<IfArgs<TS, TT>, bool> condition)
146155
{
147156
base.IfGlobal(condition);

MonoGameStateMachine/DataObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ public static DataObject<T> Of(GameTime gameTime)
5353
return new DataObject<T>(gameTime);
5454
}
5555
}
56-
}
56+
}

MonoGameStateMachine/Fsm.cs

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
// For more information, please refer to <http://unlicense.org>
2626
// ***************************************************************************
2727

28+
using System;
29+
using System.Collections.Generic;
2830
using JetBrains.Annotations;
2931
using Microsoft.Xna.Framework;
3032
using MonoGameStateMachine.Api;
@@ -34,7 +36,7 @@
3436
namespace MonoGameStateMachine
3537
{
3638
[PublicAPI]
37-
public class Fsm<TS, TT> : StateMachine.Fsm<TS, TT, GameTime>
39+
public class Fsm<TS, TT> : Fsm<TS, TT, GameTime>
3840
{
3941
public Fsm(FsmModel<TS, TT, GameTime> model) : base(model)
4042
{
@@ -45,36 +47,32 @@ public Fsm(State<TS, TT, GameTime> current, bool stackEnabled = false) : base(cu
4547
}
4648

4749
/// <summary>
48-
/// Gets you a builder for a Finite-State-Machine (FSM).
50+
/// Gets you a builder for a Finite-State-Machine (FSM).
4951
/// </summary>
5052
/// <param name="startState">The start state's key.</param>
5153
/// <returns></returns>
5254
public new static BuilderFluent<TS, TT, GameTime> Builder(TS startState)
5355
{
5456
return new FluentImplementation<TS, TT, GameTime>(startState);
5557
}
56-
57-
public new void Update(GameTime gameTime)
58-
{
59-
Model.Current.RaiseUpdated(new UpdateArgs<TS, TT, GameTime>(this, Current, gameTime));
60-
}
6158
}
6259

6360
[PublicAPI]
64-
public class Fsm<TS, TT, TD> : StateMachine.Fsm<TS, TT, DataObject<TD>>
61+
public class Fsm<TS, TT, TD> : StateMachine.Fsm<TS, TT, TD>
6562
{
66-
63+
public Dictionary<Tuple<TS, TS>, List<Timer>> AfterEntries { get; set; } = new Dictionary<Tuple<TS, TS>, List<Timer>>();
64+
public Dictionary<Tuple<TS>, List<Timer>> GlobalAfterEntries { get; set; } = new Dictionary<Tuple<TS>, List<Timer>>();
6765

68-
public Fsm(FsmModel<TS, TT, DataObject<TD>> model) : base(model)
66+
public Fsm(FsmModel<TS, TT, TD> model) : base(model)
6967
{
7068
}
7169

72-
public Fsm(State<TS, TT, DataObject<TD>> current, bool stackEnabled = false) : base(current, stackEnabled)
70+
public Fsm(State<TS, TT, TD> current, bool stackEnabled = false) : base(current, stackEnabled)
7371
{
7472
}
75-
73+
7674
/// <summary>
77-
/// Gets you a builder for a Finite-State-Machine (FSM).
75+
/// Gets you a builder for a Finite-State-Machine (FSM).
7876
/// </summary>
7977
/// <param name="startState">The start state's key.</param>
8078
/// <returns></returns>
@@ -83,9 +81,32 @@ public Fsm(State<TS, TT, DataObject<TD>> current, bool stackEnabled = false) : b
8381
return new FluentImplementation<TS, TT, DataObject<TD>>(startState);
8482
}
8583

86-
public new void Update(DataObject<TD> gameTime)
84+
public new void Update(TD data)
8785
{
88-
Model.Current.RaiseUpdated(new UpdateArgs<TS, TT, DataObject<TD>>(this, Current, gameTime));
86+
List<Timer> l;
87+
if (!AfterEntries.TryGetValue(Current, out l))
88+
{
89+
l = new List<Tuple<float, TimeUnit>>();
90+
AfterEntries.Add(key, l);
91+
}
92+
l.Add(new Tuple<float, TimeUnit>(amount, timeUnit));
93+
94+
foreach (var e in GlobalAfterEntries)
95+
{
96+
var target = e.Key;
97+
var ts = e.Value;
98+
foreach (var t in ts)
99+
{
100+
101+
}
102+
}
103+
if (!GlobalAfterEntries.TryGetValue(key, out l))
104+
{
105+
l = new List<Tuple<float, TimeUnit>>();
106+
GlobalAfterEntries.Add(key, l);
107+
}
108+
109+
Model.Current.RaiseUpdated(new UpdateArgs<TS, TT, TD>(this, Current, data));
89110
}
90111
}
91112
}

MonoGameStateMachine/MonoGameStateMachine.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
<Compile Include="Api\StateFluent.cs" />
7272
<Compile Include="Api\TransitionStateFluent.cs" />
7373
<Compile Include="DataObject.cs" />
74+
<Compile Include="Timer.cs" />
7475
<Compile Include="Fsm.cs" />
75-
<Compile Include="TransitionModel.cs" />
7676
<Compile Include="NUnitTests\FluentTests.cs" />
7777
<Compile Include="Properties\AssemblyInfo.cs" />
7878
<Compile Include="TimeUnit.cs" />

MonoGameStateMachine/NUnitTests/FluentTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ private class Button
5454
public bool IsActivated { get; set; }
5555
public State BtnState { get; set; }
5656
public State OldState { get; set; } = State.IDLE;
57-
public float RefreshTimer { get; set; } = 1F;
5857

5958
public int UpdateCounter { get; set; }
6059
}

MonoGameStateMachine/TransitionModel.cs renamed to MonoGameStateMachine/Timer.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,22 @@
2525
// For more information, please refer to <http://unlicense.org>
2626
// ***************************************************************************
2727

28-
using System;
29-
using System.Collections.Generic;
28+
using JetBrains.Annotations;
3029

3130
namespace MonoGameStateMachine
3231
{
33-
public class TransitionModel<TS, TT, TD> : StateMachine.TransitionModel<TS, TT, TD>
32+
[PublicAPI]
33+
public struct Timer
3434
{
35-
public List<Tuple<float, TimeUnit>> AfterEntries { get; set; } = new List<Tuple<float, TimeUnit>>();
35+
public float Value { get; set; }
36+
public TimeUnit Unit { get; set; }
37+
public float Time { get; set; }
3638

37-
public TransitionModel(TS source, TS target) : base(source, target)
39+
public Timer(float value, TimeUnit unit)
3840
{
41+
Value = value;
42+
Unit = unit;
43+
Time = value;
3944
}
4045
}
4146
}

StateMachine/Fluent/Api/FluentImplementation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Fsm<TS, TT, TD> Build()
6666
Fsm<TS, TT, TD> fsm = new Fsm<TS, TT, TD>(FsmModel);
6767
return fsm;
6868
}
69-
69+
7070
public StateFluent<TS, TT, TD> State(TS state)
7171
{
7272
currentState = Tuple.Create(state);

0 commit comments

Comments
 (0)