Beispiel #1
0
        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);
        }
Beispiel #2
0
        private void OnStateChange(TimeMachineState state)
        {
            _canLetValueChange = false;

            _lastState = state;

            Shield.IsVisible = state.IsPaused ? true : false;

            PauseButton.IsEnabled = state.IsPaused ? false : true;

            PlayButton.IsEnabled = state.IsPaused ? true : false;

            counterLabel.Text = string.Format ("Position: {0}, Actions: {1}", state.Position, state.Actions.Count);

            if (ActionPositionsStepper.Value != state.Position)
                ActionPositionsStepper.Value = state.Position;

            if (ActionPositionsStepper.Maximum != state.Actions.Count && state.Actions.Count > 0)
                ActionPositionsStepper.Maximum = state.Actions.Count;
            
            if (state.Position <= 0)
            {
                CurrentActionTypeTextBlock.Text = string.Empty;
                CurrentActionDescription.Text = string.Empty;
            }
            else
            {
                var currentAction = state.Actions[state.Position - 1];
                CurrentActionTypeTextBlock.Text = currentAction.GetType().Name;
				CurrentActionDescription.Text = currentAction.ToString ();
//                CurrentActionDescription.Text = JsonConvert.SerializeObject(currentAction, Formatting.Indented);
            }
            _canLetValueChange = true;
        }
Beispiel #3
0
 public TimeMachineState(TimeMachineState other)
 {
     Actions = other.Actions;
     States = other.States;
     Position = other.Position;
     IsPaused = other.IsPaused;
 }