public static void Initialize() { foreach (string file in Content.GetFiles("Content/news")) { IEnumerable <XElement> source1 = XDocument.Load(TitleContainer.OpenStream(file)).Elements((XName)"NewsStory"); if (source1 != null) { if (DG.isHalloween) { IEnumerable <XElement> source2 = source1.Elements <XElement>((XName)"NewsStoryHalloween"); if (source2 != null && source2.Count <XElement>() > 0) { source1 = source2; } } DuckNews duckNews = DuckNews.Parse(source1.ElementAt <XElement>(0)); if (duckNews != null) { DuckNews._stories.Add(duckNews); } } } DuckNews._stories = DuckNews._stories.OrderBy <DuckNews, int>((Func <DuckNews, int>)(x => (int)x._section)).ToList <DuckNews>(); }
public static DuckNews Parse(XElement rootElement) { DuckNews duckNews1 = new DuckNews(); XAttribute xattribute1 = rootElement.Attributes((XName)"name").FirstOrDefault <XAttribute>(); if (xattribute1 != null) { duckNews1._name = xattribute1.Value; } foreach (XElement element in rootElement.Elements()) { if (element.Name == (XName)"Section") { XAttribute xattribute2 = element.Attributes((XName)"name").FirstOrDefault <XAttribute>(); if (xattribute2 != null) { try { duckNews1._section = (NewsSection)Enum.Parse(typeof(NewsSection), xattribute2.Value); } catch { return((DuckNews)null); } } } else if (element.Name == (XName)"Requirement") { Script.activeProfile = Profiles.DefaultPlayer1; duckNews1._requirements.Add(ScriptStatement.Parse(element.Value + " ")); } else if (element.Name == (XName)"Dialogue") { XAttribute xattribute2 = element.Attributes((XName)"value").FirstOrDefault <XAttribute>(); if (xattribute2 != null) { duckNews1._dialogue.Add(xattribute2.Value); } } else if (element.Name == (XName)"VALUE") { Script.activeProfile = Profiles.DefaultPlayer1; duckNews1._valueCalculation = ScriptStatement.Parse(element.Value + " "); } else if (element.Name == (XName)"VALUE2") { Script.activeProfile = Profiles.DefaultPlayer1; duckNews1._valueCalculation2 = ScriptStatement.Parse(element.Value + " "); } else if (element.Name == (XName)"Cycle") { XAttribute xattribute2 = element.Attributes((XName)"value").FirstOrDefault <XAttribute>(); if (xattribute2 != null) { duckNews1._cycle = (CycleMode)Enum.Parse(typeof(CycleMode), xattribute2.Value); } } else if (element.Name == (XName)"SubStory") { DuckNews duckNews2 = DuckNews.Parse(element); duckNews1._subStories.Add(duckNews2); } } return(duckNews1); }