Пример #1
0
        private static ICommand SelectCommandBySelectedViewModel(ISelectableViewModel selectedViewModel,
                                                                 ServiceProviderCommandFactory commandFactory, ISectorUiState _uiState)
        {
            switch (selectedViewModel)
            {
            case IActorViewModel:
                var activeActor = _uiState.ActiveActor;
                if (activeActor is null)
                {
                    throw new InvalidOperationException();
                }

                if (_uiState.TacticalAct is null)
                {
                    Debug.Fail("Combat act is not selected.");
                }

                return(commandFactory.GetCommand <AttackCommand>());

            case IMapNodeViewModel:
                return(commandFactory.GetCommand <MoveCommand>());

            default:
                throw new InvalidOperationException(
                          $"Object of unknown type (${selectedViewModel.GetType()}) was selected.");
            }
        }
Пример #2
0
        private bool DidOpenDropMenu(KeyboardState keyboardState)
        {
            if (!keyboardState.IsKeyUp(Keys.O) || _lastKeyboardState?.IsKeyDown(Keys.O) != true)
            {
                return(false);
            }

            _lastKeyboardState = keyboardState;

            var openCommand = _commandFactory.GetCommand <OpenContainerCommand>();

            var actor = _uiState.ActiveActor?.Actor;

            if (actor is null)
            {
                Debug.Fail(
                    "Active actor must be assigned before the sector view model and the sector interactor start processing of user input.");
                return(true);
            }

            _uiState.SelectedViewModel = GetStaticObjectUnderActor(actor);
            if (openCommand.CanExecute().IsSuccess)
            {
                _commandPool.Push(openCommand);
            }

            return(true);
        }
Пример #3
0
        private bool HandleHotKeys()
        {
            var keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyUp(Keys.T) && _lastKeyboardState?.IsKeyDown(Keys.T) == true)
            {
                _lastKeyboardState = keyboardState;

                var transitionCommand = _commandFactory.GetCommand <SectorTransitionMoveCommand>();

                if (transitionCommand.CanExecute().IsSuccess)
                {
                    _commandPool.Push(transitionCommand);
                }

                return(true);
            }

            if (keyboardState.IsKeyUp(Keys.O) && _lastKeyboardState?.IsKeyDown(Keys.O) == true)
            {
                _lastKeyboardState = keyboardState;

                var openCommand = _commandFactory.GetCommand <OpenContainerCommand>();

                var actor = _uiState.ActiveActor?.Actor;
                if (actor is null)
                {
                    Debug.Fail(
                        "Active actor must be assigned befor sector view model and command input starts processing of user input.");
                    return(true);
                }

                _uiState.SelectedViewModel = GetStaticObjectUnderActor(actor);
                if (openCommand.CanExecute().IsSuccess)
                {
                    _commandPool.Push(openCommand);
                }

                return(true);
            }

            _lastKeyboardState = keyboardState;

            return(false);
        }