示例#1
0
        public bool IsRedundantMixin(FlatType type)
        {
            foreach (FlatType mixinType in Mixin)
            {
                if (mixinType.Equals(type))
                {
                    continue;
                }

                if (mixinType.Mixin.Contains(type))
                {
                    return(true);
                }

                if (mixinType.IsRedundantMixin(type))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#2
0
        // Builds Index
        private Dictionary <string, FlatTypeNode> ReadTypeNodes(M2dReader reader)
        {
            Dictionary <string, XmlNode>      xmlNodes = new Dictionary <string, XmlNode>();
            Dictionary <string, FlatTypeNode> types    = new Dictionary <string, FlatTypeNode>();

            foreach (PackFileEntry entry in reader.Files)
            {
                if (!entry.Name.StartsWith(root))
                {
                    continue;
                }

                XmlDocument xmlDocument = reader.GetXmlDocument(entry);
                XmlNode     node        = xmlDocument.SelectSingleNode("model");
                if (node == null)
                {
                    Console.WriteLine($"Missing model node for: {entry.Name}");
                    continue;
                }

                if (node.Attributes?["name"] == null)
                {
                    Console.WriteLine($"Missing name for: {entry.Name}");
                    continue;
                }

                string name = node.Attributes["name"].Value;
                xmlNodes[name] = node;
                var type = new FlatType(name);
                Hierarchy.Add(entry.Name, type);
                types[name.ToLower()] = new FlatTypeNode(type);
                //Console.WriteLine($"Created type: {type.Name}");
            }

            // Populate Mixin and Property for Types.
            foreach ((string name, XmlNode node) in xmlNodes)
            {
                FlatType    type       = types[name.ToLower()].Value;
                XmlNodeList mixinNodes = node.SelectNodes("mixin");
                foreach (XmlNode mixinNode in mixinNodes)
                {
                    string mixinName = mixinNode.Attributes["name"].Value;
                    type.Mixin.Add(types[mixinName.ToLower()].Value);
                }

                XmlNodeList propNodes = node.SelectNodes("property");
                foreach (XmlNode propNode in propNodes)
                {
                    if (propNode?.Attributes == null)
                    {
                        throw new ConstraintException("Null value found for property node");
                    }

                    FlatProperty property;

                    XmlNodeList setNodes = propNode.SelectNodes("set");
                    string      propName = propNode.Attributes["name"].Value;
                    string      propType = propNode.Attributes["type"].Value;
                    string      propId   = propNode.Attributes["id"].Value;

                    if (propType.StartsWith("Assoc"))
                    {
                        List <(string, string)> values = new List <(string, string)>();
                        foreach (XmlNode setNode in setNodes)
                        {
                            values.Add((setNode.Attributes["index"].Value, setNode.Attributes["value"].Value));
                        }

                        property = new FlatProperty {
                            Name  = propName,
                            Type  = propType,
                            Id    = propId,
                            Value = FlatProperty.ParseAssocType(propType, values),
                        };
                    }
                    else
                    {
                        string value = setNodes[0].Attributes["value"].Value;
                        property = new FlatProperty {
                            Name  = propName,
                            Type  = propType,
                            Id    = propId,
                            Value = FlatProperty.ParseType(propType, value),
                        };
                    }

                    type.Properties.Add(property.Name, property);
                }
            }

            return(types);
        }
示例#3
0
 protected bool Equals(FlatType other)
 {
     return(Name == other.Name && Properties.Count == other.Properties.Count &&
            !Properties.Except(other.Properties).Any());
 }
示例#4
0
 public FlatTypeNode(FlatType value)
 {
     Value    = value;
     Children = new List <FlatTypeNode>();
 }