/// <summary> /// This function will update the user's settings when we add new features to structures and what not /// //TODO Still needs to check all settings, only doing buildings right now /// </summary> /// <param name="settings"></param> /// <returns></returns> private static bool UpdateSettings(GaBSettings settings) { if (settings == null) return false; if (settings.BuildingsSettings == null) return false; // Make sure no new buildings were added // ReSharper disable once LoopCanBePartlyConvertedToQuery foreach (var building in (Buildings[]) Enum.GetValues((typeof (Buildings)))) { var nameCurrent = BuildingSettings.NameFromBuildingId((int) building); // If the current building settings doesn't contain any records with the // building name from the Enum, we need to add it if (settings.BuildingsSettings.Any(b => b.Name == nameCurrent)) continue; // Find the list of IDs from this building to add var ds = ((Buildings[]) Enum.GetValues((typeof (Buildings)))).Where( b => BuildingSettings.NameFromBuildingId((int) b) == nameCurrent) .Select(x => (int) x) .ToList(); settings.BuildingsSettings.Add(new BuildingSettings(ds.ToList())); } return true; }
private static GaBSettings DefaultConfig() { var ret = new GaBSettings { ConfigVersion = new ModuleVersion(), TimeMinBetweenRun = 60, MailItems = new List<MailItem>(), BuildingsSettings = new List<BuildingSettings>() }; // Buildings generation, Ugly... but dynamic // ReSharper disable once LoopCanBePartlyConvertedToQuery foreach (var building in (Buildings[]) Enum.GetValues((typeof (Buildings)))) { var nameCurrent = BuildingSettings.NameFromBuildingId((int) building); if (ret.BuildingsSettings.Any(b => b.Name == nameCurrent)) continue; var ids = ((Buildings[]) Enum.GetValues((typeof (Buildings)))).Where( b => BuildingSettings.NameFromBuildingId((int) b) == nameCurrent) .Select(x => (int) x) .ToList(); ret.BuildingsSettings.Add(new BuildingSettings(ids.ToList())); } // General settings // No need, already set by default // Profession ret.DailySettings = DailyProfession.AllDailies; // Trading post / mission rewards ret.PopulateMissingSettings(); // Pigments for milling ret.Pigments = Pigment.AllPigments; return ret; }