예제 #1
0
 public static AWSettings FromFile(AssaultWingCore game, string directory)
 {
     var filename = GetSettingsFilename(directory);
     if (File.Exists(filename))
     {
         var settings = (AWSettings)TypeLoader.LoadTemplate(filename, typeof(AWSettings), typeof(TypeParameterAttribute), true);
         if (settings != null)
         {
             settings.Filename = filename;
             settings.Validate(game);
             return settings;
         }
         Log.Write("Errors while reading settings from " + filename);
     }
     Log.Write("Creating a new settings file " + filename);
     var newSettings = new AWSettings { Filename = filename };
     newSettings.ToFile();
     return newSettings;
 }
예제 #2
0
 /// <summary>
 /// Returns operations that update the <see cref="BotPlayer"/> instances to conform to the settings.
 /// </summary>
 public IEnumerable<TeamOperation> UpdateBotPlayerConfiguration(IEnumerable<Team> teams, AWSettings settings)
 {
     var removeExtraBots = teams
         .SelectMany(team => team.Members.OfType<BotPlayer>().Skip(1))
         .Select(botPlayer => TeamOperation.Remove(botPlayer));
     var switchOnOrOff = settings.Players.BotsEnabled
         ? teams
             .Where(team => !team.Members.OfType<BotPlayer>().Any())
             .Select(team => TeamOperation.CreateToExistingTeam(team, GetBotPlayerName(team.Name)))
         : teams
             .SelectMany(team => team.Members.OfType<BotPlayer>())
             .Select(botPlayer => TeamOperation.Remove(botPlayer));
     var addMissingTeams = settings.Players.BotsEnabled
         ? GetFreeTeamNames(teams).Take(2 - teams.Count()).Select(name => TeamOperation.CreateToNewTeam(name, GetBotPlayerName(name)))
         : new TeamOperation[0];
     return removeExtraBots.Union(switchOnOrOff).Union(addMissingTeams);
 }