private bool Check(IFilterEntry entry) { if (entry is FilterCondition) { return(true); } if (entry is FilterAnd and) { if (and.Left == null || and.Right == null) { return(false); } return(Check(and.Left) && Check(and.Right)); } else if (entry is FilterOr or) { if (or.Left == null || or.Right == null) { return(false); } return(Check(or.Left) && Check(or.Right)); } return(true); }
public void Run() { this.filterEntry = this.FindFilterEntry(); this.SaveTableHeaderLines(); this.ScanFilterContent(); this.WriteTableIntoEntry(); }
public bool Equals(IFilterEntry entry) { if (this.Enabled != entry.Enabled) { return(false); } return(this.LineList.SequenceEqual(entry.LineList)); }
public bool Equals(IFilterEntry line) { if (line is FilterFiller) { return(this.LineList.SequenceEqual((line as FilterComment).LineList)); } return(false); }
public static void SetEnabled(this IFilterEntry me, bool enabled) { if (me.Header.Type != FilterGenerationConfig.FilterEntryType.Content) { return; } me.Header.IsFrozen = !enabled; }
public static IEnumerable <T> GetValues <T>(this IFilterEntry me, string ident) where T : class, ILineValueCore { var results = me.GetLines <T>(ident); foreach (var item in results) { yield return(item.Value as T); } }
public static bool DisableIfInvalid(this IFilterEntry me, string ident) { var valid = me.GetLines(ident)?.All(x => x.Value.IsValid()) ?? false; if (!valid) { me.SetEnabled(false); } return(true); }
public static bool HasLine <T>(this IFilterEntry me, string ident) { var list = me.GetLines(ident).ToList(); if (list == null || list.Count == 0) { return(false); } return(true); }
public static IEnumerable <FilterLine <T> > GetLines <T>(this IFilterEntry me, string ident) where T : ILineValueCore { if (me.Header.Type != FilterConstants.FilterEntryType.Content) { yield break; } var results = me.Content.Content.Where(x => x.Key == ident).SelectMany(x => x.Value).ToList(); foreach (var item in results) { yield return(item as FilterLine <T>); } }
public FilterBuilder Or() { if (isOr) { throw new InvalidOperationException("Cant start another OR filter until previous OR filter has right-side condition."); } IFilterEntry entry = conditions.LastOrDefault(); left = entry ?? throw new Exception("Can't use a Or condition on an empty filter."); conditions.RemoveAt(conditions.Count - 1); isOr = true; return(this); }
public static IEnumerable <IFilterLine> GetLines(this IFilterEntry me, string ident) { if (me.Header.Type != FilterGenerationConfig.FilterEntryType.Content) { yield break; } var results = me.Content.Content.Where(x => x.Key == ident).SelectMany(x => x.Value).ToList(); foreach (var item in results) { yield return(item); } }
private void EditEntry(IFilterEntry entry, short textR, short textG, short textB, short textO, string rarity) { var textLine = entry.Content.Content["SetTextColor"].Single(); var rarityLine = entry.Content.Content["Rarity"].Single(); if (textLine.Value is ColorValueContainer color) { color.R = textR; color.G = textG; color.B = textB; color.O = textO; } if (rarityLine.Value is NumericValueContainer rar) { rar.Value = rarity; } }
private List <IFilterEntry> BuildEntryList(List <IFilterLine> lineList) { var resultList = new List <IFilterEntry>(lineList.Count / 5); IFilterEntry currentEntry = null; foreach (var line in lineList) { // init entry or create new one when finding new Show/Hide ident if (currentEntry == null || (line.LineType == EntryDataType.Rule && (line.Ident == "Show" || line.Ident == "Hide"))) { currentEntry = FilterEntryFactory.GenerateEntryOfType(line.LineType); currentEntry.Enabled = line.Enabled; resultList.Add(currentEntry); } currentEntry.LineList.Add(line); } return(this.CleanUpEntryList(resultList)); }
public static bool IsSectionTitleEntry(IFilterEntry entry, IFilterEntry tocEntry = null) { if (entry.Header.Type != FilterConstants.FilterEntryType.Comment) { return(false); } if (!entry.Content.Content.ContainsKey("comment")) { return(false); } if (entry.Content.Content["comment"].Count < MinSectionTitleLineCount) { return(false); } var line = GetTitleLineFromEntry(entry); if (line.Comment.Trim()[0] != SectionTitleKeyIdentStart || !line.Comment.Contains(SectionTitleKeyIdentEnd)) { return(false); } // skip the actual ToC entry, even tho it does look fitting if (entry == tocEntry || line.Comment.ToUpper().Contains("[WELCOME]")) { return(false); } bool IsDivider(IFilterLine l) => l.Comment.Length > 5 && l.Comment[2] == l.Comment[3] && l.Comment[3] == l.Comment[4]; if (!IsDivider(entry.Content.Content["comment"][0]) || !IsDivider(entry.Content.Content["comment"][0])) { return(false); } return(true); }
public FilterOr(IFilterEntry left, IFilterEntry right) { Left = left ?? throw new ArgumentNullException(nameof(left)); Right = right ?? throw new ArgumentNullException(nameof(right)); }
public static int GetTitleDepth(IFilterEntry entry) => GetTitleDepth(GetTitleLineFromEntry(entry).Comment);
private static IFilterLine GetTitleLineFromEntry(IFilterEntry entry) => entry.Content.Content["comment"][SectionTitleLineIndex];
public void Init() { this.InitialRule = this.Clone(); }
public static string GetTitle(IFilterEntry entry, int depth) => GetTitle(GetTitleLineFromEntry(entry).Comment, depth);