コード例 #1
0
        internal Initializer(Controllers controller, GameData gameData)
        {
            var inputInitialized = new InputController(new PCInput());

            controller.AddController(inputInitialized);

            ServiceLocator.SetService(new ShipProviderPool(gameData.Ship.Provider));

            var shipWeaponFactory = new ShipWeaponFactory(
                gameData.ShipWeapon,
                new ShipWeaponBulletsPool(gameData.ShipWeapon.Bullet));

            var shipFactory = new ShipInitializer(
                gameData.Ship,
                ServiceLocator.Resolve <ShipProviderPool>(),
                shipWeaponFactory.GetShipWeapon);

            controller.AddController(shipFactory.CreateShipFromData(gameData.Ship));

            var playerInitialized = new PlayerInitializer(shipFactory.GetShip, gameData.Player, inputInitialized.Input);

            controller.AddController(playerInitialized.PlayerController);

            var cameraInitialized = new CameraInitializer(gameData.Camera, shipFactory.GetShip);

            controller.AddController(cameraInitialized.CameraController);

            IEnemyFactory factory = new AsteroidFactory();

            factory.Create(new Health(100.0f, 100.0f));
        }
コード例 #2
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);
            }
        }
コード例 #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 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: ");
            }
        }