Beispiel #1
0
 public TimeMachineState(TimeMachineState other)
 {
     Actions = other.Actions;
     States = other.States;
     Position = other.Position;
     IsPaused = other.IsPaused;
 }
Beispiel #2
0
 public TimeMachineState(TimeMachineState other)
 {
     Actions  = other.Actions;
     States   = other.States;
     Position = other.Position;
     IsPaused = other.IsPaused;
 }
Beispiel #3
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));
        }
        private void OnStateChange(TimeMachineState state)
        {
            _lastState = state;

            Shield.Visibility = state.IsPaused ? Visibility.Visible : Visibility.Collapsed;

            PauseButton.Visibility = state.IsPaused ? Visibility.Collapsed : Visibility.Visible;
            PlayButton.Visibility = state.IsPaused ? Visibility.Visible : Visibility.Collapsed;

            ActionPositionsSlider.Value = state.Position;
            ActionPositionsSlider.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 = JsonConvert.SerializeObject(currentAction, Formatting.Indented);
            }
        }
Beispiel #5
0
        private void OnStateChange(TimeMachineState state)
        {
            _lastState = state;

            Shield.Visibility = state.IsPaused ? Visibility.Visible : Visibility.Collapsed;

            PauseButton.Visibility = state.IsPaused ? Visibility.Collapsed : Visibility.Visible;
            PlayButton.Visibility  = state.IsPaused ? Visibility.Visible : Visibility.Collapsed;

            ActionPositionsSlider.Value   = state.Position;
            ActionPositionsSlider.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   = JsonConvert.SerializeObject(currentAction, Formatting.Indented);
            }
        }