コード例 #1
0
        private static XmlInheritanceNode GetBestParentFor(XmlInheritanceNode node, string parentName)
        {
            XmlInheritanceNode xmlInheritanceNode = null;

            if (nodesByName.TryGetValue(parentName, out var value))
            {
                if (node.mod == null)
                {
                    for (int i = 0; i < value.Count; i++)
                    {
                        if (value[i].mod == null)
                        {
                            xmlInheritanceNode = value[i];
                            break;
                        }
                    }
                    if (xmlInheritanceNode == null)
                    {
                        for (int j = 0; j < value.Count; j++)
                        {
                            if (xmlInheritanceNode == null || value[j].mod.loadOrder < xmlInheritanceNode.mod.loadOrder)
                            {
                                xmlInheritanceNode = value[j];
                            }
                        }
                    }
                }
                else
                {
                    for (int k = 0; k < value.Count; k++)
                    {
                        if (value[k].mod != null && value[k].mod.loadOrder <= node.mod.loadOrder && (xmlInheritanceNode == null || value[k].mod.loadOrder > xmlInheritanceNode.mod.loadOrder))
                        {
                            xmlInheritanceNode = value[k];
                        }
                    }
                    if (xmlInheritanceNode == null)
                    {
                        for (int l = 0; l < value.Count; l++)
                        {
                            if (value[l].mod == null)
                            {
                                xmlInheritanceNode = value[l];
                                break;
                            }
                        }
                    }
                }
            }
            if (xmlInheritanceNode == null)
            {
                Log.Error("XML error: Could not find parent node named \"" + parentName + "\" for node \"" + node.xmlNode.Name + "\". Full node: " + node.xmlNode.OuterXml);
                return(null);
            }
            return(xmlInheritanceNode);
        }
コード例 #2
0
 private static void ResolveXmlNodesRecursively(XmlInheritanceNode node)
 {
     if (node.resolvedXmlNode != null)
     {
         Log.Error("XML error: Cyclic inheritance hierarchy detected for node \"" + node.xmlNode.Name + "\". Full node: " + node.xmlNode.OuterXml);
         return;
     }
     ResolveXmlNodeFor(node);
     for (int i = 0; i < node.children.Count; i++)
     {
         ResolveXmlNodesRecursively(node.children[i]);
     }
 }
コード例 #3
0
        public static void TryRegister(XmlNode node, ModContentPack mod)
        {
            XmlAttribute xmlAttribute  = node.Attributes[XmlInheritance.NameAttributeName];
            XmlAttribute xmlAttribute2 = node.Attributes[XmlInheritance.ParentNameAttributeName];

            if (xmlAttribute == null && xmlAttribute2 == null)
            {
                return;
            }
            List <XmlInheritanceNode> list = null;

            if (xmlAttribute != null && XmlInheritance.nodesByName.TryGetValue(xmlAttribute.Value, out list))
            {
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].mod == mod)
                    {
                        goto IL_0067;
                    }
                }
            }
            XmlInheritanceNode xmlInheritanceNode = new XmlInheritanceNode();

            xmlInheritanceNode.xmlNode = node;
            xmlInheritanceNode.mod     = mod;
            XmlInheritance.unresolvedNodes.Add(xmlInheritanceNode);
            if (xmlAttribute != null)
            {
                if (list != null)
                {
                    list.Add(xmlInheritanceNode);
                }
                else
                {
                    list = new List <XmlInheritanceNode>();
                    list.Add(xmlInheritanceNode);
                    XmlInheritance.nodesByName.Add(xmlAttribute.Value, list);
                }
            }
            return;

IL_0067:
            if (mod == null)
            {
                Log.Error("XML error: Could not register node named \"" + xmlAttribute.Value + "\" because this name is already used.");
            }
            else
            {
                Log.Error("XML error: Could not register node named \"" + xmlAttribute.Value + "\" in mod " + mod.ToString() + " because this name is already used in this mod.");
            }
        }
コード例 #4
0
ファイル: XmlInheritance.cs プロジェクト: KraigXu/GameProject
        public static void TryRegister(XmlNode node, ModContentPack mod)
        {
            XmlAttribute xmlAttribute  = node.Attributes["Name"];
            XmlAttribute xmlAttribute2 = node.Attributes["ParentName"];

            if (xmlAttribute == null && xmlAttribute2 == null)
            {
                return;
            }
            List <XmlInheritanceNode> value = null;

            if (xmlAttribute != null && nodesByName.TryGetValue(xmlAttribute.Value, out value))
            {
                for (int i = 0; i < value.Count; i++)
                {
                    if (value[i].mod == mod)
                    {
                        if (mod == null)
                        {
                            Log.Error("XML error: Could not register node named \"" + xmlAttribute.Value + "\" because this name is already used.");
                        }
                        else
                        {
                            Log.Error("XML error: Could not register node named \"" + xmlAttribute.Value + "\" in mod " + mod.ToString() + " because this name is already used in this mod.");
                        }
                        return;
                    }
                }
            }
            XmlInheritanceNode xmlInheritanceNode = new XmlInheritanceNode();

            xmlInheritanceNode.xmlNode = node;
            xmlInheritanceNode.mod     = mod;
            unresolvedNodes.Add(xmlInheritanceNode);
            if (xmlAttribute != null)
            {
                if (value != null)
                {
                    value.Add(xmlInheritanceNode);
                    return;
                }
                value = new List <XmlInheritanceNode>();
                value.Add(xmlInheritanceNode);
                nodesByName.Add(xmlAttribute.Value, value);
            }
        }
コード例 #5
0
        private static void ResolveXmlNodeFor(XmlInheritanceNode node)
        {
            if (node.parent == null)
            {
                node.resolvedXmlNode = node.xmlNode;
                return;
            }
            if (node.parent.resolvedXmlNode == null)
            {
                Log.Error("XML error: Internal error. Tried to resolve node whose parent has not been resolved yet. This means that this method was called in incorrect order.");
                node.resolvedXmlNode = node.xmlNode;
                return;
            }
            CheckForDuplicateNodes(node.xmlNode, node.xmlNode);
            XmlNode xmlNode = node.parent.resolvedXmlNode.CloneNode(deep: true);

            RecursiveNodeCopyOverwriteElements(node.xmlNode, xmlNode);
            node.resolvedXmlNode = xmlNode;
        }
コード例 #6
0
 public static XmlNode GetResolvedNodeFor(XmlNode originalNode)
 {
     if (originalNode.Attributes[XmlInheritance.ParentNameAttributeName] != null)
     {
         XmlInheritanceNode xmlInheritanceNode = default(XmlInheritanceNode);
         if (XmlInheritance.resolvedNodes.TryGetValue(originalNode, out xmlInheritanceNode))
         {
             return(xmlInheritanceNode.resolvedXmlNode);
         }
         if (XmlInheritance.unresolvedNodes.Any((XmlInheritanceNode x) => x.xmlNode == originalNode))
         {
             Log.Error("XML error: XML node \"" + originalNode.Name + "\" has not been resolved yet. There's probably a Resolve() call missing somewhere.");
         }
         else
         {
             Log.Error("XML error: Tried to get resolved node for node \"" + originalNode.Name + "\" which uses a ParentName attribute, but it is not in a resolved nodes collection, which means that it was never registered or there was an error while resolving it.");
         }
     }
     return(originalNode);
 }
コード例 #7
0
 private static void ResolveXmlNodeFor(XmlInheritanceNode node)
 {
     if (node.parent == null)
     {
         node.resolvedXmlNode = node.xmlNode;
     }
     else if (node.parent.resolvedXmlNode == null)
     {
         Log.Error("XML error: Internal error. Tried to resolve node whose parent has not been resolved yet. This means that this method was called in incorrect order.");
         node.resolvedXmlNode = node.xmlNode;
     }
     else
     {
         XmlInheritance.CheckForDuplicateNodes(node.xmlNode);
         XmlNode xmlNode = node.parent.resolvedXmlNode.CloneNode(true);
         xmlNode.Attributes.RemoveAll();
         XmlAttributeCollection attributes = node.xmlNode.Attributes;
         for (int i = 0; i < attributes.Count; i++)
         {
             if (!(attributes[i].Name == XmlInheritance.NameAttributeName) && !(attributes[i].Name == XmlInheritance.ParentNameAttributeName))
             {
                 XmlAttribute node2 = (XmlAttribute)xmlNode.OwnerDocument.ImportNode(attributes[i], true);
                 xmlNode.Attributes.Append(node2);
             }
         }
         XmlAttributeCollection attributes2 = node.parent.resolvedXmlNode.Attributes;
         for (int j = 0; j < attributes2.Count; j++)
         {
             if (!(attributes2[j].Name == XmlInheritance.NameAttributeName) && !(attributes2[j].Name == XmlInheritance.ParentNameAttributeName) && xmlNode.Attributes[attributes2[j].Name] == null)
             {
                 XmlAttribute node3 = (XmlAttribute)xmlNode.OwnerDocument.ImportNode(attributes2[j], true);
                 xmlNode.Attributes.Append(node3);
             }
         }
         XmlInheritance.RecursiveNodeCopyOverwriteElements(node.xmlNode, xmlNode);
         node.resolvedXmlNode = xmlNode;
     }
 }
コード例 #8
0
        private static XmlInheritanceNode GetBestParentFor(XmlInheritanceNode node, string parentName)
        {
            XmlInheritanceNode        xmlInheritanceNode = null;
            List <XmlInheritanceNode> list = default(List <XmlInheritanceNode>);

            if (XmlInheritance.nodesByName.TryGetValue(parentName, out list))
            {
                if (node.mod == null)
                {
                    int num = 0;
                    while (num < list.Count)
                    {
                        if (list[num].mod != null)
                        {
                            num++;
                            continue;
                        }
                        xmlInheritanceNode = list[num];
                        break;
                    }
                    if (xmlInheritanceNode == null)
                    {
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (xmlInheritanceNode == null || list[i].mod.loadOrder < xmlInheritanceNode.mod.loadOrder)
                            {
                                xmlInheritanceNode = list[i];
                            }
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < list.Count; j++)
                    {
                        if (list[j].mod != null && list[j].mod.loadOrder <= node.mod.loadOrder && (xmlInheritanceNode == null || list[j].mod.loadOrder > xmlInheritanceNode.mod.loadOrder))
                        {
                            xmlInheritanceNode = list[j];
                        }
                    }
                    if (xmlInheritanceNode == null)
                    {
                        int num2 = 0;
                        while (num2 < list.Count)
                        {
                            if (list[num2].mod != null)
                            {
                                num2++;
                                continue;
                            }
                            xmlInheritanceNode = list[num2];
                            break;
                        }
                    }
                }
            }
            if (xmlInheritanceNode == null)
            {
                Log.Error("XML error: Could not find parent node named \"" + parentName + "\" for node \"" + node.xmlNode.Name + "\". Full node: " + node.xmlNode.OuterXml);
                return(null);
            }
            return(xmlInheritanceNode);
        }