Exemple #1
0
        public static FilterEntry CreateFillerEntry()
        {
            var entry = new FilterEntry();

            entry.Header          = new FilterEntryHeader();
            entry.Header.Type     = FilterGenerationConfig.FilterEntryType.Filler;
            entry.Header.IsFrozen = false;
            entry.Header.IsActive = true;

            return(entry);
        }
 public void UpdateParent(FilterEntry newParent)
 {
     foreach (var ident in this.Content)
     {
         foreach (var filterLine in ident.Value)
         {
             if (filterLine is FilterLine <ILineValueCore> line)
             {
                 line.Parent = newParent;
             }
         }
     }
 }
Exemple #3
0
        public IFilterEntry Clone()
        {
            var clone = new FilterEntry
            {
                Content  = this.Content.Clone(),
                Header   = this.Header.Clone(),
                IsFrozen = this.IsFrozen
            };

            clone.Content.UpdateParent(clone);
            clone.Header.GenerationTags.ForEach(x => x.Target = clone);

            return(clone);
        }
Exemple #4
0
        public static FilterEntry CreateDataEntry(IFilterLine line)
        {
            var entry = new FilterEntry();

            entry.Header             = new FilterEntryHeader();
            entry.Header.HeaderValue = line.Ident;
            entry.Header.IsFrozen    = line.identCommented;
            entry.Header.IsActive    = true;
            entry.Header.Type        = FilterGenerationConfig.FilterEntryType.Content;
            entry.Header.ExtractTagsFromLine(line, entry);

            entry.Content         = new FilterEntryDataContent();
            entry.Content.Content = new Dictionary <string, List <IFilterLine> >();
            return(entry);
        }
Exemple #5
0
        public static FilterEntry CreateCommentEntry(IFilterLine line)
        {
            var entry = new FilterEntry();

            entry.Header          = new FilterEntryHeader();
            entry.Header.Type     = FilterGenerationConfig.FilterEntryType.Comment;
            entry.Header.IsFrozen = true;
            entry.Header.IsActive = true;

            entry.Content         = new FilterEntryDataContent();
            entry.Content.Content = new Dictionary <string, List <IFilterLine> >();
            entry.Content.AddComment(line);

            return(entry);
        }
        public void ExtractTagsFromLine(IFilterLine line, FilterEntry entry)
        {
            GenerationTags = new List <GenerationTag>();
            TierTags       = new TierTagSet();

            bool          firstComment = true;
            StringBuilder builder      = new StringBuilder();
            var           strings      = line.Comment.ToLower().Split(FilterGenerationConfig.WhiteLineChars);

            foreach (var s in strings)
            {
                if (s.Length == 0)
                {
                    continue;
                }

                if (s[0] == '%')
                {
                    GenerationTag tag;
                    var           split   = s.Substring(1).ToUpper();
                    var           lastPos = split.Length - 1;
                    var           command = split.Substring(0, lastPos);
                    short         digit   = -1;

                    // in case the command is something without digit at the end (like %UP, unlike %h3)
                    if (FilterGenerationConfig.EntryCommand.ContainsKey(split))
                    {
                        command = split;
                    }

                    // checking if the last char is a digit wont work correctly in cases of e.g. "crafting-83"
                    // which will save the "3" as strictness, so we instead check if the command is in the EntryCommand list
                    else if (FilterGenerationConfig.EntryCommand.ContainsKey(command))
                    {
                        digit = short.Parse(split.Substring(lastPos));
                    }

                    else if (FilterGenerationConfig.EntryCommand.ContainsKey(split.Split(new[] { "->" }, StringSplitOptions.None).First()))
                    {
                        command = split.Split(new[] { "->" }, StringSplitOptions.None).First();
                    }

                    else
                    {
                        throw new Exception("unknown entry tag command: " + split);
                    }

                    var tagType = FilterGenerationConfig.EntryCommand[command];
                    tag            = tagType(entry) as GenerationTag;
                    tag.Strictness = digit;
                    tag.Value      = command;

                    if (tag is ReceiverEntryCommand r)
                    {
                        r.TypeValue = split.Replace(command, "");
                    }
                    if (tag is SenderEntryCommand se)
                    {
                        se.TypeValue = split.Replace(command, "");
                    }

                    this.GenerationTags.Add(tag);
                }
                else if (s[0] == '$')
                {
                    this.TierTags.Add(s);
                }
                else
                {
                    if (!firstComment)
                    {
                        builder.Append(" ");
                    }
                    else
                    {
                        firstComment = false;
                    }

                    builder.Append(s);
                }
            }

            HeaderComment = builder.ToString();
        }