示例#1
0
        public FlatProperty GetProperty(string name)
        {
            if (Properties.ContainsKey(name))
            {
                return(Properties[name]);
            }

            for (int i = Mixin.Count - 1; i >= 0; i--)
            {
                FlatProperty prop = Mixin[i].GetProperty(name);
                if (prop != null)
                {
                    return(prop);
                }
            }

            return(null);
        }
示例#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);
        }