Beispiel #1
0
        public static bool ApplyGlobal_EqualSign(TyGlobal global, TyGlobalItem root, TyModEditItem edit)
        {
            string[] mad = new string[] { "zwrite", "type", "effect", "id" };

            // Name is always defined without an equal sign
            if (edit.Key == "name")
            {
                return(false);
            }

            // All definitions are set with the equal sign except name
            if (global.Name.EndsWith("sound"))
            {
                return(true);
            }

            // Only select definitions have equal signs
            if (global.Name.EndsWith("mad") && mad.Contains(edit.Key))
            {
                return(true);
            }

            // Harder to determine model entry
            // So we base off of the surrounding subitems
            if (global.Name.EndsWith("model"))
            {
                if (root.SubItems.Count > 0)
                {
                    return(root.SubItems[0].EqualSign);
                }
            }

            // Default to true
            return(true);
        }
Beispiel #2
0
 public static void ApplyGlobal_Add(TyGlobal global, TyGlobalItem root, TyModEditItem edit)
 {
     for (int x = 0; x < edit.SubItems.Count; x++)
     {
         root.SubItems.Add(new TyGlobalItem(edit.SubItems[x].Key, edit.SubItems[x].Value, root.Context, root.Indents + 4, ApplyGlobal_EqualSign(global, root, edit)));
     }
 }
Beispiel #3
0
        public static void ApplyGlobal_Apply(TyGlobal global, TyGlobalItem item, TyModEdit edit)
        {
            TyGlobalItem newItem;

            // If we are directly setting the value
            if (edit.Value != null)
            {
                item.Value = edit.Value;
            }

            switch (edit.Type)
            {
            case TyModEdit.EditType.exclusive:
                item.SubItems.Clear();
                for (int x = 0; x < edit.SubItems.Count; x++)
                {
                    item.SubItems.Add(new TyGlobalItem(edit.SubItems[x].Key, edit.SubItems[x].Value, item.Context, item.Indents + 4, ApplyGlobal_EqualSign(global, item, edit.SubItems[x])));
                }
                break;

            case TyModEdit.EditType.inclusive:

                for (int x = 0; x < edit.SubItems.Count; x++)
                {
                    newItem = item.SubItems.Find(s => s.Key == edit.SubItems[x].Key);
                    if (newItem != null)
                    {
                        newItem.Value = edit.SubItems[x].Value;
                    }
                    else
                    {
                        item.SubItems.Add(new TyGlobalItem(edit.SubItems[x].Key, edit.SubItems[x].Value, item.Context, item.Indents + 4, ApplyGlobal_EqualSign(global, item, edit.SubItems[x])));
                    }
                }
                break;

            case TyModEdit.EditType.replace:
                for (int x = 0; x < edit.SubItems.Count; x++)
                {
                    newItem = item.SubItems.Find(s => s.Key == edit.SubItems[x].Key);
                    if (newItem != null)
                    {
                        newItem.Value = edit.SubItems[x].Value;
                    }
                }
                break;
            }
        }
Beispiel #4
0
        private void ParseContents_Match(string contents, Match match, int length, string context)
        {
            string[]            lines = contents.Substring(match.Index, length).Split(new char[] { '\n' });
            string[]            words = null;
            int                 indent;
            TyGlobalItem        root = null, parent = null;
            List <TyGlobalItem> lastItems = new List <TyGlobalItem>();

            foreach (string line in lines)
            {
                if (lastItems.Count > 0)
                {
                    indent = ParseContents_GetLineInfo(line.Replace("\r", String.Empty), ref lastItems, out words);
                    parent = lastItems[lastItems.Count - 1];

                    if (words.Length == 0)
                    {
                        //parent.SubItems.Add(new TyGlobalItem(null, null, indent));
                    }
                    else if (words.Length == 1)
                    {
                        parent.SubItems.Add(new TyGlobalItem(null, words[0], context, indent));
                        lastItems.Add(parent.SubItems[parent.SubItems.Count - 1]);
                    }
                    else if (words[1] == "=")
                    {
                        parent.SubItems.Add(new TyGlobalItem(words[0], String.Join(" ", words, 2, words.Length - 2), context, indent, true));
                        lastItems.Add(parent.SubItems[parent.SubItems.Count - 1]);
                    }
                    else
                    {
                        parent.SubItems.Add(new TyGlobalItem(words[0], String.Join(" ", words, 1, words.Length - 1), context, indent));
                        lastItems.Add(parent.SubItems[parent.SubItems.Count - 1]);
                    }
                }
                else if (line.StartsWith("name "))
                {
                    root = new TyGlobalItem("name", line.Substring(5).Trim(), context, 0);
                    lastItems.Add(root);
                }
            }

            if (root.Key != null && root.Value != null)
            {
                Items.Add(root);
            }
        }
Beispiel #5
0
        public static int ApplyGlobal_Find(TyGlobal global, TyGlobalItem item, TyModEdit edit, string key, string regex, ref int count)
        {
            if (item.Key != null && item.Key.ToLower() == key)
            {
                if (item.Value != null && Regex.IsMatch(item.Value, regex))
                {
                    if (edit.Context == null || (item.Context != null && Regex.IsMatch(item.Context, edit.Context, RegexOptions.Multiline)))
                    {
                        ApplyGlobal_Apply(global, item, edit);
                        count++;
                    }
                }
            }

            foreach (TyGlobalItem sub in item.SubItems)
            {
                ApplyGlobal_Find(global, sub, edit, key, regex, ref count);
            }

            return(count);
        }