Exemplo n.º 1
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 <XmlInheritance.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)
                    {
                        if (mod == null)
                        {
                            Log.Error("XML error: Could not register node named \"" + xmlAttribute.Value + "\" because this name is already used.");
                        }
                        else
                        {
                            Log.Error(string.Concat(new string[]
                            {
                                "XML error: Could not register node named \"",
                                xmlAttribute.Value,
                                "\" in mod ",
                                mod.ToString(),
                                " because this name is already used in this mod."
                            }));
                        }
                        return;
                    }
                }
            }
            XmlInheritance.XmlInheritanceNode xmlInheritanceNode = new XmlInheritance.XmlInheritanceNode();
            xmlInheritanceNode.xmlNode = node;
            xmlInheritanceNode.mod     = mod;
            XmlInheritance.unresolvedNodes.Add(xmlInheritanceNode);
            if (xmlAttribute != null)
            {
                if (list != null)
                {
                    list.Add(xmlInheritanceNode);
                }
                else
                {
                    list = new List <XmlInheritance.XmlInheritanceNode>();
                    list.Add(xmlInheritanceNode);
                    XmlInheritance.nodesByName.Add(xmlAttribute.Value, list);
                }
            }
        }
Exemplo n.º 2
0
 private static void ResolveXmlNodesRecursively(XmlInheritance.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;
     }
     XmlInheritance.ResolveXmlNodeFor(node);
     for (int i = 0; i < node.children.Count; i++)
     {
         XmlInheritance.ResolveXmlNodesRecursively(node.children[i]);
     }
 }
Exemplo n.º 3
0
        private static void ResolveXmlNodeFor(XmlInheritance.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;
            }
            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))
                {
                    if (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;
        }
Exemplo n.º 4
0
        private static void ResolveXmlNodeFor(XmlInheritance.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.", false);
                node.resolvedXmlNode = node.xmlNode;
                return;
            }
            XmlInheritance.CheckForDuplicateNodes(node.xmlNode, node.xmlNode);
            XmlNode xmlNode = node.parent.resolvedXmlNode.CloneNode(true);

            XmlInheritance.RecursiveNodeCopyOverwriteElements(node.xmlNode, xmlNode);
            node.resolvedXmlNode = xmlNode;
        }
Exemplo n.º 5
0
        private static XmlInheritance.XmlInheritanceNode GetBestParentFor(XmlInheritance.XmlInheritanceNode node, string parentName)
        {
            XmlInheritance.XmlInheritanceNode        xmlInheritanceNode = null;
            List <XmlInheritance.XmlInheritanceNode> list;

            if (XmlInheritance.nodesByName.TryGetValue(parentName, out list))
            {
                if (node.mod == null)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (list[i].mod == null)
                        {
                            xmlInheritanceNode = list[i];
                            break;
                        }
                    }
                    if (xmlInheritanceNode == null)
                    {
                        for (int j = 0; j < list.Count; j++)
                        {
                            if (xmlInheritanceNode == null || list[j].mod.loadOrder < xmlInheritanceNode.mod.loadOrder)
                            {
                                xmlInheritanceNode = list[j];
                            }
                        }
                    }
                }
                else
                {
                    for (int k = 0; k < list.Count; k++)
                    {
                        if (list[k].mod != null)
                        {
                            if (list[k].mod.loadOrder <= node.mod.loadOrder && (xmlInheritanceNode == null || list[k].mod.loadOrder > xmlInheritanceNode.mod.loadOrder))
                            {
                                xmlInheritanceNode = list[k];
                            }
                        }
                    }
                    if (xmlInheritanceNode == null)
                    {
                        for (int l = 0; l < list.Count; l++)
                        {
                            if (list[l].mod == null)
                            {
                                xmlInheritanceNode = list[l];
                                break;
                            }
                        }
                    }
                }
            }
            if (xmlInheritanceNode == null)
            {
                Log.Error(string.Concat(new string[]
                {
                    "XML error: Could not find parent node named \"",
                    parentName,
                    "\" for node \"",
                    node.xmlNode.Name,
                    "\". Full node: ",
                    node.xmlNode.OuterXml
                }));
                return(null);
            }
            return(xmlInheritanceNode);
        }
Exemplo n.º 6
0
 internal bool <> m__0(XmlInheritance.XmlInheritanceNode x)
 {
     return(x.xmlNode == this.originalNode);
 }
Exemplo n.º 7
0
 private static bool <ResolveXmlNodes> m__0(XmlInheritance.XmlInheritanceNode x)
 {
     return(x.parent == null || x.parent.resolvedXmlNode != null);
 }