public TimeMachineState Execute(TimeMachineState previousState, IAction action)
        {
            if (action is ResumeTimeMachineAction)
            {
                return(previousState
                       .WithIsPaused(false)
                       .WithStates(previousState.States.Take(previousState.Position + 1).ToImmutableList())
                       .WithActions(previousState.Actions.Take(previousState.Position).ToImmutableList()));
            }

            if (action is PauseTimeMachineAction)
            {
                return(previousState
                       .WithIsPaused(true));
            }

            if (action is SetTimeMachinePositionAction)
            {
                return(previousState
                       .WithPosition(((SetTimeMachinePositionAction)action).Position)
                       .WithIsPaused(true));
            }

            if (previousState.IsPaused)
            {
                return(previousState);
            }

            var innerState = _reducer(previousState.States.Last(), action);

            return(previousState
                   .WithStates(previousState.States.Add(innerState))
                   .WithActions(previousState.Actions.Add(action))
                   .WithPosition(previousState.Position + 1));
        }
 public TimeMachineState(TimeMachineState other)
 {
     Actions  = other.Actions;
     States   = other.States;
     Position = other.Position;
     IsPaused = other.IsPaused;
 }
        public TimeMachineState Execute(TimeMachineState previousState, IAction action)
        {
            if(action is ResumeTimeMachineAction)
            {
                return previousState
                    .WithIsPaused(false)
                    .WithStates(previousState.States.Take(previousState.Position + 1).ToImmutableList())
                    .WithActions(previousState.Actions.Take(previousState.Position).ToImmutableList());
            }

            if(action is PauseTimeMachineAction)
            {
                return previousState
                    .WithIsPaused(true);
            }

            if(action is SetTimeMachinePositionAction)
            {
                return previousState
                    .WithPosition(((SetTimeMachinePositionAction)action).Position)
                    .WithIsPaused(true);
            }

            if (previousState.IsPaused)
            {
                return previousState;
            }

            var innerState = _reducer(previousState.States.Last(), action);

            return previousState
                .WithStates(previousState.States.Add(innerState))
                .WithActions(previousState.Actions.Add(action))
                .WithPosition(previousState.Position + 1);
        }
 public TimeMachineState(TimeMachineState other)
 {
     Actions = other.Actions;
     States = other.States;
     Position = other.Position;
     IsPaused = other.IsPaused;
 }
Exemple #5
0
 private TState Unlift(TimeMachineState state)
 {
     return((TState)state.States[state.Position]);
 }