private void LoadEventFile(DayOfWeek today, string region) { var yesterday = today - 1; if (region.StartsWith("EU")) { region = "EU"; } var path = $"resources/config/events/events-{region}.xml"; if (!File.Exists(path)) { var root = new XElement("Events"); var eg = new XElement("EventGroup", new XAttribute("name", "Example event group")); var ev = new XElement("Event", new XAttribute("name", "Example Event"), new XAttribute("days", "*"), new XAttribute("start", "12:00"), new XAttribute("end", "15:00"), new XAttribute("color", "ff5566")); var ev2 = new XElement("Event", new XAttribute("name", "Example event 2"), new XAttribute("days", "*"), new XAttribute("start", "16:00"), new XAttribute("duration", "3:00"), new XAttribute("color", "ff5566")); eg.Add(ev); eg.Add(ev2); root.Add(eg); if (!Directory.Exists($"resources/config/events")) { Directory.CreateDirectory($"resources/config/events"); } root.Save(path); } try { var d = XDocument.Load(path); foreach (var egElement in d.Descendants().Where(x => x.Name == "EventGroup")) { var egName = egElement.Attribute("name").Value; var egRc = egElement.Attribute("remote") != null && bool.Parse(egElement.Attribute("remote").Value); var egStart = egElement.Attribute("start") != null ? DateTime.Parse(egElement.Attribute("start").Value) : DateTime.MinValue; var egEnd = egElement.Attribute("end") != null ? DateTime.Parse(egElement.Attribute("end").Value).AddDays(1) : DateTime.MaxValue; if (TimeManager.Instance.CurrentServerTime < egStart || TimeManager.Instance.CurrentServerTime > egEnd) { continue; } var eg = new EventGroup(egName, egStart, egEnd, egRc); foreach (var evElement in egElement.Descendants().Where(x => x.Name == "Event")) { var isYesterday = false; var isToday = false; if (evElement.Attribute("days").Value != "*") { if (evElement.Attribute("days").Value.Contains(',')) { var days = evElement.Attribute("days").Value.Split(','); foreach (var dayString in days) { var day = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), dayString); if (day == today) { isToday = true; } if (day == yesterday) { isYesterday = true; } } } else { var eventDay = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), evElement.Attribute("days").Value); isToday = eventDay == today; isYesterday = eventDay == yesterday; } } else { isToday = true; isYesterday = true; } if (!isToday && !isYesterday) { continue; } var name = evElement.Attribute("name").Value; var parsedStart = DateTime.Parse(evElement.Attribute("start").Value, CultureInfo.InvariantCulture); var parsedDuration = TimeSpan.Zero; var parsedEnd = DateTime.Now; bool isDuration; if (evElement.Attribute("duration") != null) { parsedDuration = TimeSpan.Parse(evElement.Attribute("duration").Value, CultureInfo.InvariantCulture); isDuration = true; } else if (evElement.Attribute("end") != null) { parsedEnd = DateTime.Parse(evElement.Attribute("end").Value, CultureInfo.InvariantCulture); isDuration = false; } else { parsedDuration = TimeSpan.Zero; parsedEnd = parsedStart; isDuration = true; } var color = "5599ff"; var start = parsedStart.Hour + parsedStart.Minute / 60D; var end = isDuration ? parsedDuration.Hours + parsedDuration.Minutes / 60D : parsedEnd.Hour + parsedEnd.Minute / 60D; if (evElement.Attribute("color") != null) { color = evElement.Attribute("color").Value; } if (isYesterday) { if (!EventUtils.EndsToday(start, end, isDuration)) { var e1 = new DailyEvent(name, parsedStart.Hour, 24, 0, color, false); end = start + end - 24; var e2 = new DailyEvent(name, parsedStart.Hour, parsedStart.Minute, end, color, isDuration); if (isToday) { eg.AddEvent(e1); } eg.AddEvent(e2); } else if (isToday) { var ev = new DailyEvent(name, parsedStart.Hour, parsedStart.Minute, end, color, isDuration); eg.AddEvent(ev); } } else { var ev = new DailyEvent(name, parsedStart.Hour, parsedStart.Minute, end, color, isDuration); eg.AddEvent(ev); } } if (eg.Events.Count != 0) { AddEventGroup(eg); } } SpecialEvents.Add(new DailyEvent("Reset", TimeManager.Instance.ResetHour, 0, 0, "ff0000")); } catch (Exception) { var res = TccMessageBox.Show("TCC", $"There was an error while reading events-{region}.xml. Manually correct the error and and press Ok to try again, else press Cancel to build a default config file.", MessageBoxButton.OKCancel); if (res == MessageBoxResult.Cancel) { File.Delete(path); } LoadEventFile(today, region); } }
public void Update(IInvalidator Invalidator, LiveSplitState State, float Width, float Height, LayoutMode Mode) { if (GameProcess == null || GameProcess.HasExited) { GameProcess = GetGameProcess(); } if (CurrentSplitIndex == -1 && State.CurrentSplitIndex != -1 && Settings.p_GraphShow) { OnRunStart(null, null); CurrentSplitIndex = State.CurrentSplitIndex; RunStartTime = (TimeSpan)State.CurrentTime[TimingMethod.RealTime]; } if (GameProcess != null && !GameProcess.HasExited) { int NewMana, NewRegen, NewPotions; if (ReadManaValues(out NewMana, out NewRegen, out NewPotions)) { if (Settings.p_GraphShow && State.CurrentSplitIndex != -1) { var SecondTenths = GetTimeSecondTenths(); if (State.IsGameTimePaused)//loading { if (IsInLoadingScreen) { int Index = SpecialEvents.FindLastIndex(e => e.Type == SpecialEventType.Load); if (Index == -1) { IsInLoadingScreen = false; } else { var Event = SpecialEvents[Index]; Event.Length = SecondTenths - Event.Time; SpecialEvents[Index] = Event; } } if (!IsInLoadingScreen) { SpecialEvents.Add(new SpecialEvent(SpecialEventType.Load, SecondTenths)); IsInLoadingScreen = true; } } else { if (IsInLoadingScreen) { IsInLoadingScreen = false; var Event = SpecialEvents[SpecialEvents.Count - 1]; Event.Length = SecondTenths - Event.Time; SpecialEvents[SpecialEvents.Count - 1] = Event; } else { if (NewMana < Mana)//blink (maybe other power) { SpecialEvents.Add(new SpecialEvent(SpecialEventType.Blink, SecondTenths)); } else if (NewPotions > Potions)//pickup potion(s) { for (var i = NewPotions; i > Potions; --i) { SpecialEvents.Add(new SpecialEvent(SpecialEventType.Pickup, SecondTenths)); } } else if (NewPotions < Potions)//drink potion(s) { for (var i = NewPotions; i < Potions; ++i) { SpecialEvents.Add(new SpecialEvent(SpecialEventType.Drink, SecondTenths)); } } } } if (SecondTenths >= ManaSnapshots.Count) { //make sure the structure is filled for (int i = ManaSnapshots.Count; i < SecondTenths; ++i) { ManaSnapshots.Add(new ManaSnapshot(Mana, Regen, Potions)); } //add the current mana values to the structure ManaSnapshots.Add(new ManaSnapshot(NewMana, NewRegen, NewPotions)); } } //only update if game time is running, as we are in a loading screen otherwise wherein the values may fluctuate if (!State.IsGameTimePaused) { Mana = NewMana; Regen = NewRegen; Potions = NewPotions; } } } if (Settings.p_HeaderShow) { HeaderLabel.Text = Settings.p_HeaderText; if (Settings.p_HeaderManaShow) { HeaderLabel.Text += Mana + Settings.p_HeaderManaText; } if (Settings.p_HeaderRegenShow) { HeaderLabel.Text += Regen + Settings.p_HeaderRegenText; } if (Settings.p_HeaderPotionsShow) { HeaderLabel.Text += Potions + Settings.p_HeaderPotionsText; } if (Invalidator != null) { Invalidator.Invalidate(0, 0, Width, Height); } } }