diff --git a/fsm/FSM.cs b/fsm/FSM.cs index e13c147..afe3cec 100644 --- a/fsm/FSM.cs +++ b/fsm/FSM.cs @@ -8,33 +8,30 @@ namespace fsm; -public record class Context : imm.Recorded -{ +public class Context{ } -public record class State : imm.Recorded> - where T: State - where CTX: Context +public class State + where T : State + where CTX : Context { - virtual public (CTX, T) onEnter(CTX ctx, State oldState) + virtual public void onEnter(CTX ctx, State oldState) { - return (ctx, (T)this); } - virtual public (CTX, T) onExit(CTX ctx, State newState) + virtual public void onExit(CTX ctx, State newState) { - return (ctx, (T)this); } } -public record class FSM : imm.Recorded> - where T: FSM - where CTX: Context - where ST: State +public class FSM + where T : FSM + where CTX : Context + where ST : State { public CTX Context { get; private set; } - public ST State { get; private set; } + public ST State { get; private set; } public FSM(CTX context, ST state) { @@ -42,17 +39,8 @@ public record class FSM : imm.Recorded> State = state; } - public FSM Transition(ST newState) + public void Transition(ST newState) { - var (newOldCTX, oldState) = State.onExit(Context, newState); - - var (newCTX, storeState) = newState.onEnter(newOldCTX, oldState); - - return this with - { - Context = newCTX, - State = storeState, - }; } diff --git a/imm/FSM.cs b/imm/FSM.cs new file mode 100644 index 0000000..44bf500 --- /dev/null +++ b/imm/FSM.cs @@ -0,0 +1,61 @@ + + +using System; + + + +namespace imm; + + + +public record class Context : imm.Recorded +{ + +} + +public record class State : imm.Recorded> + where T : State + where CTX : Context +{ + virtual public (CTX, T) onEnter(CTX ctx, State oldState) + { + return (ctx, (T)this); + } + + virtual public (CTX, T) onExit(CTX ctx, State newState) + { + return (ctx, (T)this); + } +} + +public record class FSM : imm.Recorded> + where T : FSM + where CTX : Context + where ST : State +{ + public CTX Context { get; private set; } + public ST State { get; private set; } + + public FSM(CTX context, ST state) + { + Context = context; + State = state; + } + + public FSM Transition(ST newState) + { + var (newOldCTX, oldState) = State.onExit(Context, newState); + + var (newCTX, storeState) = newState.onEnter(newOldCTX, oldState); + + return this with + { + Context = newCTX, + State = storeState, + }; + } + + + +} + diff --git a/net/FSM.cs b/net/FSM.cs new file mode 100644 index 0000000..2f3a050 --- /dev/null +++ b/net/FSM.cs @@ -0,0 +1,63 @@ + + +using System; + + + +namespace net; + + + +public class Context{ + +} + +public class State + where T : State + where CTX : Context +{ + virtual public void onEnter(CTX ctx, State oldState) + { + } + + virtual public void onExit(CTX ctx, State newState) + { + } +} + +public class PotentialState : State + where T : State + where CTX : Context +{ + virtual public void onEnter(CTX ctx, State oldState) + { + } + + virtual public void onExit(CTX ctx, State newState) + { + } +} + + +public class FSM + where T : FSM + where CTX : Context + where ST : State +{ + public CTX Context { get; private set; } + public ST State { get; private set; } + + public FSM(CTX context, ST state) + { + Context = context; + State = state; + } + + public void Transition(ST newState) + { + } + + + +} +