Exemplo n.º 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.");
            }
        }
Exemplo n.º 2
0
        public SectorViewModel(Game game, Camera camera, SpriteBatch spriteBatch)
        {
            _camera      = camera;
            _spriteBatch = spriteBatch;

            var serviceScope = ((LivGame)game).ServiceProvider;

            _player  = serviceScope.GetRequiredService <IPlayer>();
            _uiState = serviceScope.GetRequiredService <ISectorUiState>();

            _intarectionBus = serviceScope.GetRequiredService <IActorInteractionBus>();

            _intarectionBus.NewEvent += IntarectionBus_NewEvent;

            var personVisualizationContentStorage =
                serviceScope.GetRequiredService <IPersonVisualizationContentStorage>();
            var personSoundContentStorage             = serviceScope.GetRequiredService <IPersonSoundContentStorage>();
            var gameObjectVisualizationContentStorage =
                serviceScope.GetRequiredService <IGameObjectVisualizationContentStorage>();

            var sector = GetPlayerSectorNode(_player).Sector;

            if (sector is null)
            {
                throw new InvalidOperationException();
            }

            Sector = sector;

            var playerActor = (from actor in Sector.ActorManager.Items
                               where actor.Person == _player.MainPerson
                               select actor).SingleOrDefault();

            _mapViewModel = new MapViewModel(game, _player, _uiState, Sector, spriteBatch);

            ViewModelContext = new SectorViewModelContext(sector);

            var gameObjectParams = new GameObjectParams
            {
                Game                                  = game,
                Camera                                = camera,
                UiState                               = _uiState,
                Player                                = _player,
                SpriteBatch                           = _spriteBatch,
                SectorViewModelContext                = ViewModelContext,
                PersonSoundStorage                    = personSoundContentStorage,
                PersonVisualizationContentStorage     = personVisualizationContentStorage,
                GameObjectVisualizationContentStorage = gameObjectVisualizationContentStorage
            };

            _gameObjectsViewModel = new GameObjectsViewModel(gameObjectParams);

            var commandFactory = new ServiceProviderCommandFactory(((LivGame)game).ServiceProvider);

            var commandPool      = serviceScope.GetRequiredService <ICommandPool>();
            var sectorInteractor =
                new SectorInteractor(_uiState, commandPool, _camera, Sector, ViewModelContext, commandFactory);

            _sectorInteractor = sectorInteractor;
        }
Exemplo n.º 3
0
 public CommandInput(
     ISectorUiState sectorUiState,
     ICommandPool commandPool,
     Camera camera,
     ISector sector,
     SectorViewModelContext sectorViewModelContext,
     ServiceProviderCommandFactory commandFactory)
 {
     _uiState                = sectorUiState;
     _commandPool            = commandPool;
     _camera                 = camera;
     _sector                 = sector;
     _sectorViewModelContext = sectorViewModelContext;
     _commandFactory         = commandFactory;
 }