示例#1
0
        public void InstallGame(Game game)
        {
            logger.Info($"Installing {game.GetIdentifierInfo()}");
            IGameController controller = null;

            try
            {
                controller = GameControllerFactory.GetGameBasedController(game, appSettings);
                Controllers.RemoveController(game.Id);
                Controllers.AddController(controller);
                UpdateGameState(game.Id, null, null, true, null, null);
                controller.Install();
            }
            catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                if (controller != null)
                {
                    Controllers.RemoveController(game.Id);
                    UpdateGameState(game.Id, null, null, false, null, null);
                }

                logger.Error(exc, "Cannot install game: ");
                dialogs.ShowMessage(
                    string.Format(resources.FindString("LOCGameInstallError"), exc.Message),
                    resources.FindString("LOCGameError"),
                    MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#2
0
文件: Boot.cs 项目: torybash/TankGame
        private void BootGame()
        {
            //Setting up controllers, databases, flow-stack etc.

            //Core functionality
            var viewDatabase   = databaseHelper.Get <ViewDatabase>();
            var viewController = new ViewController(viewDatabase);
            var flowStack      = new FlowStack();

            //Game, map, battle
            var tankDatabase  = databaseHelper.Get <TankDatabase>();
            var crewDatabase  = databaseHelper.Get <CrewDatabase>();
            var cardsDatabase = databaseHelper.Get <CardsDatabase>();
            var activeCardsPanelLifecycleHandler = new ActiveCardsPanelLifecycleHandler(viewController);
            var abilitiesPanelLifecycleHandler   = new AbilitiesPanelLifecycleHandler(tankDatabase);
            var tankPanelLifecycleHandler        = new TankPanelLifecycleHandler();
            var dragAndDropArrow      = new DragAndDropArrowController(viewController);
            var battleHUD             = new BattleHUD(viewController, activeCardsPanelLifecycleHandler, abilitiesPanelLifecycleHandler, tankPanelLifecycleHandler, dragAndDropArrow);
            var gameControllerFactory = new GameControllerFactory(flowStack, viewController, battleHUD, tankDatabase, crewDatabase, cardsDatabase);

            //Main menu
            var mainMenuControllerFactory = new MainMenuControllerFactory(flowStack, viewController, gameControllerFactory);

            //Start Flow
            var menuFlow = new MainMenuFlow(mainMenuControllerFactory);

            flowStack.Push(menuFlow);
        }
示例#3
0
        public void UnInstallGame(Game game)
        {
            if (game.State.Running || game.State.Launching)
            {
                dialogs.ShowMessage(
                    resources.FindString("LOCGameUninstallRunningError"),
                    resources.FindString("LOCGameError"),
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
                return;
            }

            try
            {
                var controller = GameControllerFactory.GetGameBasedController(game, appSettings);
                Controllers.RemoveController(game.Id);
                Controllers.AddController(controller);
                UpdateGameState(game.Id, null, null, null, true, null);
                controller.Uninstall();
            }
            catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                logger.Error(exc, "Cannot un-install game: ");
                dialogs.ShowMessage(
                    string.Format(resources.FindString("LOCGameUninstallError"), exc.Message),
                    resources.FindString("LOCGameError"),
                    MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#4
0
        public void InitializeCommandsTest()
        {
            var database    = new GameDatabase();
            var controllers = new GameControllerFactory();
            var model       = new MainViewModel(
                database,
                null,
                null,
                null,
                new PlayniteSettings(),
                new GamesEditor(
                    new GameDatabase(),
                    controllers,
                    new PlayniteSettings(),
                    null,
                    null),
                null,
                new ExtensionFactory(database, controllers));

            var props = typeof(MainViewModel).GetProperties();

            foreach (var prop in props)
            {
                if (prop.Name.EndsWith("Command"))
                {
                    var cmd = prop.GetValue(model, null);
                    if (cmd == null)
                    {
                        Assert.Fail($"{prop.Name} is not defined.");
                    }
                }
            }
        }
        public void Execute(object parameter)
        {
            IGameControllerContext context        = parameter as IGameControllerContext;
            IGameController        gameController = GameControllerFactory.CreateGameController(context.GameMode);

            gameController.InitializeGame(context);
        }
示例#6
0
        public void Create_GameOptionsSetToLocalConnection_ReturnsLocalController()
        {
            var gameController = new GameControllerFactory().Create(new GameOptions {
                Connection = Enums.GameConnectionTypes.Local
            }, this.CreateGameControllerSetup());

            gameController.ShouldBeOfType <LocalGameController>();
        }
        public void Execute(object parameter)
        {
            GameMode gameMode = (GameMode)parameter;

            IGameController gameController = GameControllerFactory.CreateGameController(gameMode);

            gameController.StartGame();
        }
示例#8
0
        public void PlayGame(Game game)
        {
            if (!game.IsInstalled)
            {
                InstallGame(game);
                return;
            }

            logger.Info($"Starting {game.GetIdentifierInfo()}");
            var dbGame = database.GetGame(game.Id);

            if (dbGame == null)
            {
                dialogs.ShowMessage(
                    string.Format(resources.FindString("LOCGameStartErrorNoGame"), game.Name),
                    resources.FindString("LOCGameError"),
                    MessageBoxButton.OK, MessageBoxImage.Error);
                UpdateJumpList();
                return;
            }

            IGameController controller = null;

            try
            {
                controller = GameControllerFactory.GetGameBasedController(game, appSettings);
                Controllers.RemoveController(game.Id);
                Controllers.AddController(controller);
                UpdateGameState(game.Id, null, null, null, null, true);
                controller.Play(database.GetEmulators());
            }
            catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                if (controller != null)
                {
                    Controllers.RemoveController(game.Id);
                    UpdateGameState(game.Id, null, null, null, null, false);
                }

                logger.Error(exc, "Cannot start game: ");
                dialogs.ShowMessage(
                    string.Format(resources.FindString("LOCGameStartError"), exc.Message),
                    resources.FindString("LOCGameError"),
                    MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try
            {
                UpdateJumpList();
            }
            catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                logger.Error(exc, "Failed to set jump list data: ");
            }
        }
示例#9
0
        public void Create_SetupWithAllHandlers_ControllerHasHandlersSet()
        {
            var gameControllerSetup = this.CreateGameControllerSetup();
            var gameController      = new GameControllerFactory().Create(null, gameControllerSetup);

            gameController.GameJoinedEvent.ShouldBe(gameControllerSetup.GameJoinedEventHandler);
            gameController.InitialBoardSetupEvent.ShouldBe(gameControllerSetup.InitialBoardSetupEventHandler);
            gameController.LoggedInEvent.ShouldBe(gameControllerSetup.LoggedInEventHandler);
            gameController.StartInitialSetupTurnEvent.ShouldBe(gameControllerSetup.StartInitialSetupTurnEvent);
        }
示例#10
0
 public GamesEditor(GameDatabase database, Settings appSettings, IDialogsFactory dialogs)
 {
     this.dialogs             = dialogs;
     this.database            = database;
     this.appSettings         = appSettings;
     Controllers              = new GameControllerFactory(database);
     Controllers.Installed   += Controllers_Installed;
     Controllers.Uninstalled += Controllers_Uninstalled;
     Controllers.Started     += Controllers_Started;
     Controllers.Stopped     += Controllers_Stopped;
 }
示例#11
0
 public DesktopGamesEditor(
     GameDatabase database,
     GameControllerFactory controllerFactory,
     PlayniteSettings appSettings,
     IDialogsFactory dialogs,
     ExtensionFactory extensions,
     PlayniteApplication app) : base(
         database,
         controllerFactory,
         appSettings,
         dialogs,
         extensions,
         app)
 {
 }
示例#12
0
 public GamesEditor(
     GameDatabase database,
     GameControllerFactory controllerFactory,
     PlayniteSettings appSettings,
     IDialogsFactory dialogs,
     ExtensionFactory extensions)
 {
     this.dialogs             = dialogs;
     this.database            = database;
     this.appSettings         = appSettings;
     this.extensions          = extensions;
     controllers              = controllerFactory;
     controllers.Installed   += Controllers_Installed;
     controllers.Uninstalled += Controllers_Uninstalled;
     controllers.Started     += Controllers_Started;
     controllers.Stopped     += Controllers_Stopped;
 }
示例#13
0
        public GameHostWindow()
        {
            InitializeComponent();

            myGameProvider.LoadGames();

            IDictionary <string, IGame> myGames = myGameProvider.GetGames();

            if (myGames.Any())
            {
                GameControllerFactory.SetViewModel(myGameViewModel);

                myGameViewModel.Games = myGames;

                this.DataContext = myGameViewModel;
            }
        }
示例#14
0
        private void StartGameWithBuffs()
        {
            IGameController gameController = _gameController;

            if (gameController != null)
            {
                gameController.EndCurrentGame();
            }
            _playerView = UnityEngine.Object.FindObjectsOfType <PlayerView>();
            _uiView     = UnityEngine.Object.FindObjectsOfType <UiView>();
            IGameControllerFactory gameControllerFactory = new GameControllerFactory(TypeGame.GameWithBuffs);

            _gameController = gameControllerFactory.GameController;
            IPlayerControllerFactory playerControllerFactory = new PlayerControllerFactory(_playerView, playerPanelHierarchies, _gameController);

            IUiView[] uiView = _uiView;
            new UiControllerFactory(uiView, playerControllerFactory.PlayerController, _gameController);
        }
示例#15
0
        public void InitializeCommandsTest()
        {
            var database    = new GameDatabase();
            var controllers = new GameControllerFactory();
            var model       = new DesktopAppViewModel();
            var props       = typeof(DesktopAppViewModel).GetProperties();

            foreach (var prop in props)
            {
                if (prop.Name.EndsWith("Command"))
                {
                    var cmd = prop.GetValue(model, null);
                    if (cmd == null)
                    {
                        Assert.Fail($"{prop.Name} is not defined.");
                    }
                }
            }
        }
示例#16
0
 public GamesEditor(
     GameDatabase database,
     GameControllerFactory controllerFactory,
     PlayniteSettings appSettings,
     IDialogsFactory dialogs,
     ExtensionFactory extensions,
     PlayniteApplication app)
 {
     this.Dialogs                 = dialogs;
     this.Database                = database;
     this.AppSettings             = appSettings;
     this.Extensions              = extensions;
     this.Application             = app;
     controllers                  = controllerFactory;
     controllers.Installed       += Controllers_Installed;
     controllers.Uninstalled     += Controllers_Uninstalled;
     controllers.Started         += Controllers_Started;
     controllers.Stopped         += Controllers_Stopped;
     AppSettings.PropertyChanged += AppSettings_PropertyChanged;
 }
        public GameHostWindow()
        {
            InitializeComponent();

            myGameProvider.LoadGames();

            IDictionary <string, IGame> myGames = myGameProvider.GetGames();

            if (myGames.Any())
            {
                myGameHost = GameControllerFactory.CreateGameController(GameMode.SinglePlayer);
            }

            IGameViewModel viewModel = myGameHost.GetGameViewModel();

            viewModel.Games = myGames;

            viewModel.GameControllerCommand = new GameControllerCommand(myGameHost);

            viewModel.StartGameCommand = new StartGameCommand(myGameHost);

            this.DataContext = viewModel;
        }
示例#18
0
 public GameLibrary()
 {
     Controllers = new GameControllerFactory();
     Api         = new PlayniteAPI(null, null, null, paths: new PlaynitePathsAPI(), null, notifications: new NotificationsAPI());
     LoadPlugins();
 }
示例#19
0
        public void Create_DefaultGameOptions_ReturnsLocalController()
        {
            var gameController = new GameControllerFactory().Create(new GameOptions(), this.CreateGameControllerSetup());

            gameController.ShouldBeOfType <LocalGameController>();
        }
示例#20
0
        public void Create_NullParameter_ReturnsLocalController()
        {
            var gameController = new GameControllerFactory().Create(null, this.CreateGameControllerSetup());

            gameController.ShouldBeOfType <LocalGameController>();
        }
 public MainMenuControllerFactory(FlowStack flowStack, ViewController viewController, GameControllerFactory gameControllerFactory)
 {
     this.flowStack             = flowStack;
     this.viewController        = viewController;
     this.gameControllerFactory = gameControllerFactory;
 }