Example #1
0
 public LauncherItem(LauncherItemManager manager, IPetroglyhGameableObject gameObject)
 {
     Manager         = manager;
     GameObject      = gameObject;
     _commandHandler = new LauncherGameObjectCommandHandler(GameObject);
     SetNameAsync().Forget();
 }
 public LauncherItemEventSink(LauncherItemManager manager, IPetroglyhGameableObject gameObject)
 {
     Manager    = manager;
     GameObject = gameObject;
     if (!(gameObject is IModContainer modContainer))
     {
         return;
     }
     modContainer.ModCollectionModified += OnModsChanged;
 }
Example #3
0
        internal LauncherItem GetItemImpl(IPetroglyhGameableObject gameObject)
        {
            var item = TryGetItem(gameObject);

            if (item == null)
            {
                item = new LauncherItem(this, gameObject);
                AddItem(item);
            }

            return(item);
        }
Example #4
0
        private static void LaunchCore(IPetroglyhGameableObject gameObject, IReadOnlyList <IPetroglyhGameableObject>?linkedGameObjects = null)
        {
            if (gameObject is null)
            {
                throw new InvalidOperationException("No object to launch selected");
            }

            IGame game;
            IMod? mod = null;

            switch (gameObject)
            {
            case IGame g:
                game = g;
                break;

            case IMod m:
                mod  = m;
                game = mod.Game;
                break;

            default:
                throw new NotSupportedException("Selected object is not supported");
            }

            if (game is null)
            {
                throw new InvalidOperationException("No game to launch.");
            }

            var gameOptions = LauncherGameOptions.Instance;
            var args        = new GameCommandArguments();

            gameOptions.FillArgs(args);

            if (mod != null)
            {
                var modList = GetAllMods(mod);
                if (!modList.Any())
                {
                    throw new InvalidOperationException("The selected mod object seems to be invalid.");
                }
                args.Mods = modList;
            }

            args.Language = gameOptions.GetLanguageFromOptions(gameObject);

            RunGame(game, args, gameObject.IconFile, gameOptions.UseDebugBuild);
        }
Example #5
0
        internal static bool Launch(IPetroglyhGameableObject gameObject, IReadOnlyList <IPetroglyhGameableObject>?linkedGameObjects = null)
        {
            try
            {
                LaunchCore(gameObject, linkedGameObjects);
            }
            catch (Exception e)
            {
                MessageBox.Show($"Unable to start {gameObject.Name}:\r\n" +
                                e.Message, "FoC Launcher", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            return(true);
        }
Example #6
0
 public LauncherItem?TryGetItem(IPetroglyhGameableObject gameableObject)
 {
     return(_items.TryGetValue(gameableObject, out var item) ? item : null);
 }
Example #7
0
 public bool TryGetItem(IPetroglyhGameableObject gameObject, out ILauncherItem?item)
 {
     item = TryGetItem(gameObject);
     return(item != null);
 }
Example #8
0
 public ILauncherItem GetGameObjectItem(IPetroglyhGameableObject gameObject)
 {
     return(GetItemImpl(gameObject));
 }
Example #9
0
 internal LauncherGameObjectCommandHandler(IPetroglyhGameableObject gameObject)
 {
     GameObject = gameObject;
 }