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(TyGlobal global, TyModEdit edit)
        {
            int  count  = 0;
            bool addNew = true;

            if (edit.Attributes.Count > 0)
            {
                // Find with TyGlobal based on first attribute
                string key   = edit.Attributes.Keys.ElementAt(0).ToLower();
                string regex = edit.Attributes[key];

                foreach (TyGlobalItem item in global.Items)
                {
                    if (ApplyGlobal_Find(global, item, edit, key, regex, ref count) > 0)
                    {
                        addNew = false;
                    }
                }
            }

            if (!addNew)
            {
                return;
            }

            // Add new to TyGlobal
            for (int x = 0; x < edit.SubItems.Count; x++)
            {
                global.Items.Add(new TyGlobalItem(edit.SubItems[x].Key, edit.SubItems[x].Value, (global.Items.Count == 0 ? null : global.Items[global.Items.Count - 1].Context), 0, false));
                ApplyGlobal_Add(global, global.Items[global.Items.Count - 1], edit.SubItems[x]);
            }
        }
Beispiel #4
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 #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);
        }
Beispiel #6
0
        public string ToString(TyGlobal global, string indent)
        {
            string result = (Key == null ? String.Empty : Key + " ") + (EqualSign ? "= " : String.Empty) + (Value ?? String.Empty).Trim();

            result = result.PadLeft((Indents - indent.Length) + 2 + result.Length, ' ');

            if (indent.Length > 0 && Key != null && Value != null && Key.ToLower() == "name" && Value.ToLower() != "setup")
            {
                indent = "";
            }

            foreach (TyGlobalItem item in SubItems)
            {
                result += "\r\n" + indent + item.ToString(global, indent + "  ");
            }

            if (indent.Length == 2 && global.Name.ToLower() == "global.sound")
            {
                result += "\r\n";
            }

            return(result);
        }