private static bool TryGetModpack(StartGameOptions options, [NotNullWhen(true)] out Modpack?modpack) { if (options.ModpackId.HasValue) { if (_modpacks.TryGetValue(options.ModpackId.Value, out modpack)) { return(true); } else { Log.Warning($"Modpack with ID {options.ModpackId.Value} does not exist, no modpack enabled"); return(false); } } if (!string.IsNullOrEmpty(options.ModpackName)) { foreach (var pack in Modpacks) { if (pack.DisplayName == options.ModpackName) { modpack = pack; return(true); } } Log.Warning($"Modpack with name {options.ModpackName} does not exist, no modpack enabled"); modpack = null; return(false); } modpack = null; return(false); }
private static bool TryGetInstance(StartGameOptions options, [NotNullWhen(true)] out IFactorioInstance?instance) { if (!string.IsNullOrEmpty(options.Uid)) { foreach (var inst in Manager.ManagedInstances) { if (inst.GetUniqueKey() == options.Uid) { instance = inst; return(true); } } Log.Error($"Factorio instance with ID {options.Uid} does not exist, aborting"); instance = null; return(false); } if (!string.IsNullOrEmpty(options.Name)) { foreach (var inst in Manager.ManagedInstances) { if (inst.GetName() == options.Name) { instance = inst; return(true); } } Log.Error($"Factorio instance with name {options.Name} does not exist, aborting"); instance = null; return(false); } instance = null; return(false); }
private static async Task <ErrorCode> StartGameAsync(StartGameOptions options) { SetDirectories(options); InitLogger(options); await InitProgramAsync(options); var code = ErrorCode.NoError; try { if (TryGetInstance(options, out var instance)) { foreach (var modManager in Manager.ModManagers) { foreach (var mod in modManager) { mod.Enabled = false; } } if (TryGetModpack(options, out var modpack)) { Log.Information($"Enabling modpack {modpack.DisplayName}"); modpack.Enabled = true; } ModStateManager.SaveModList(instance.Version); FileInfo?savegameFile = null; if (!string.IsNullOrWhiteSpace(options.SavegameFile)) { try { savegameFile = new FileInfo(options.SavegameFile); if (!savegameFile.Exists) { savegameFile = null; } } catch { savegameFile = null; } } Log.Information($"Starting Factorio instance '{instance}'"); instance.Start(Locations.GetModDir(instance.Version), savegameFile, options.CustomArguments?.Replace('\'', '"')); } else { code = ErrorCode.GameStart_InvalidInstance; } } catch (Exception ex) { Log.Fatal(ex, "Unable to start Factorio instance"); code = ErrorCode.GameStart_General; } UnloadProgram(); return(code); }
private static int StartGame(StartGameOptions options) { return(NoError); }
public static void optionSelect() { bool loopRunner = true; do { Console.Write("\nPlease Choose an option: "); try { string userDecision = Console.ReadLine(); int optionChosen; bool convertionSucceded = Int32.TryParse(userDecision, out optionChosen); char[,] gameTable; if (!convertionSucceded) { throw new InvalidOperationException("Please enter chosen option number!"); } if (optionChosen < 1 || optionChosen > 4) { throw new InvalidOperationException("Please enter number between 1 to 4!"); } Screen.Clear(); StartGameOptions startAnswer = (StartGameOptions)optionChosen; switch (startAnswer) { case StartGameOptions.SinglePlayer: { PlayerDetails player = new PlayerDetails(); PlayerDetails computer = new PlayerDetails(); EndGameOptions endAnswer; player.m_PlayerSymbol = m_Symbols[0]; computer.m_PlayerSymbol = m_Symbols[1]; inputName(ref player); computer.m_Name = "Computer"; do { gameTable = tableSizeInput(); singlePlayer(ref gameTable, ref player, ref computer); endAnswer = (EndGameOptions)afterGameOptions(); if (endAnswer == EndGameOptions.MainMenu) { Screen.Clear(); break; } if (endAnswer == EndGameOptions.Exit) { Environment.Exit(0); } } while (endAnswer == EndGameOptions.PlayAgain); if (endAnswer == EndGameOptions.MainMenu) { displayMenu(); continue; } break; } case StartGameOptions.MultiPlayer: { PlayerDetails player1 = new PlayerDetails(); PlayerDetails player2 = new PlayerDetails(); EndGameOptions endAnswer; player1.m_PlayerSymbol = m_Symbols[0]; player2.m_PlayerSymbol = m_Symbols[1]; Console.Write("First player - "); inputName(ref player1); Console.Write("Second player -"); inputName(ref player2); do { gameTable = tableSizeInput(); multiPlayer(ref gameTable, ref player1, ref player2); endAnswer = (EndGameOptions)afterGameOptions(); if (endAnswer == EndGameOptions.MainMenu) { Screen.Clear(); break; } if (endAnswer == EndGameOptions.Exit) { Environment.Exit(0); } } while (endAnswer == EndGameOptions.PlayAgain); if (endAnswer == EndGameOptions.MainMenu) { displayMenu(); continue; } break; } case StartGameOptions.Instractions: presentInstractions(); displayWelcome(); displayMenu(); continue; case StartGameOptions.Exit: { Environment.Exit(0); break; } } Console.ReadLine(); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); continue; } catch (Exception ex) { Console.WriteLine(ex.Message); continue; } loopRunner = false; } while (loopRunner); }