コード例 #1
0
        public static Attribute AddAttribute(string nodeName, string attributeName, Type attrType)
        {
            Node node = PssgSchema.AddNode(nodeName);

            if (attrType != null)
            {
                bool add = true;
                for (int i = 0; i < node.Attributes.Count; i++)
                {
                    if (node.Attributes[i].Name == attributeName)
                    {
                        add = false;
                        // Allow overwrite if current data type is null
                        PssgSchema.SetAttributeDataTypeIfNull(node.Attributes[i], attrType);
                        return(node.Attributes[i]);
                    }
                }

                if (add)
                {
                    PssgSchema.Attribute attr = new Attribute(attributeName, attrType);
                    node.Attributes.Add(attr);
                    return(attr);
                }
            }

            return(null);
        }
コード例 #2
0
        public PssgNode(XElement elem, PssgFile file, PssgNode node)
        {
            this.File       = file;
            this.ParentNode = node;
            this.NodeInfo   = PssgSchema.AddNode(elem.Name.LocalName);// PssgSchema.GetNode(elem.Name.LocalName);

            this.Attributes = new PssgAttributeCollection();
            PssgAttribute attr;

            foreach (XAttribute xAttr in elem.Attributes())
            {
                attr = new PssgAttribute(xAttr, file, this);
                this.Attributes.Add(attr);
            }

            // Add data, and sub nodes code here
            if (elem.FirstNode != null && elem.FirstNode is XText)
            {
                this.data       = this.FromString(elem.Value);
                this.ChildNodes = new PssgNodeCollection();
            }
            else
            {
                this.data       = new byte[0];
                this.ChildNodes = new PssgNodeCollection(elem.Elements().Count());
                int nodeCount = 0;
                foreach (XElement subElem in elem.Elements())
                {
                    this.ChildNodes.Add(new PssgNode(subElem, file, this));
                    ++nodeCount;
                }
            }
            PssgSchema.SetNodeDataTypeIfNull(this.NodeInfo, this.ValueType);
        }
コード例 #3
0
 public PssgNode(string name, PssgFile file, PssgNode node)
 {
     this.File       = file;
     this.ParentNode = node;
     this.NodeInfo   = PssgSchema.AddNode(name);
     this.Attributes = new PssgAttributeCollection();
     this.data       = new byte[0];
     this.ChildNodes = new PssgNodeCollection();
 }
コード例 #4
0
        public static PssgSchema.Node RenameNode(PssgNode pssgNode, string nodeName)
        {
            PssgSchema.Node node = PssgSchema.AddNode(nodeName);

            foreach (PssgAttribute attr in pssgNode.Attributes)
            {
                PssgSchema.AddAttribute(node.Name, attr.AttributeInfo.Name, attr.AttributeInfo.DataType);
            }

            return(node);
        }
コード例 #5
0
        public PssgNode SetChild(PssgNode childNode, PssgNode newChildNode)
        {
            newChildNode.File       = this.File;
            newChildNode.ParentNode = this;
            PssgNode node = this.ChildNodes.Set(childNode, newChildNode);

            if (node != null)
            {
                node.NodeInfo = PssgSchema.AddNode(node);
            }
            return(node);
        }
コード例 #6
0
        //public static void CreatePssgInfo(out PssgNodeInfo[] nodeInfo, out PssgAttributeInfo[] attributeInfo)
        //{
        //    nodeInfo = new PssgNodeInfo[entries.Count];
        //    List<PssgAttributeInfo> attrInfo = new List<PssgAttributeInfo>();

        //    int i = 0, j = 0;
        //    foreach (KeyValuePair<string, Node> node in entries)
        //    {
        //        nodeInfo[i] = new PssgNodeInfo(i + 1, node.Key);

        //        foreach (Attribute attr in node.Value.Attributes)
        //        {
        //            attr.Id = ++j;
        //            PssgAttributeInfo aInfo = new PssgAttributeInfo(attr.Id, attr.Name);
        //            attrInfo.Add(aInfo);
        //            nodeInfo[i].attributeInfo.Add(attr.Id, aInfo);
        //        }

        //        node.Value.Id = ++i;
        //    }

        //    attributeInfo = attrInfo.ToArray();
        //}

        public static PssgSchema.Node AddNode(PssgNode node)
        {
            Node sNode = new Node(node.Name);

            sNode.DataType = node.ValueType;

            foreach (PssgAttribute attr in node.Attributes)
            {
                Attribute sAttr = new Attribute(attr.Name, attr.ValueType);
                sNode.Attributes.Add(sAttr);
            }

            return(PssgSchema.AddNode(sNode));
        }
コード例 #7
0
        public static Attribute AddAttribute(string nodeName, string attributeName)
        {
            Node node = PssgSchema.AddNode(nodeName);

            for (int i = 0; i < node.Attributes.Count; i++)
            {
                if (node.Attributes[i].Name == attributeName)
                {
                    return(node.Attributes[i]);
                }
            }

            PssgSchema.Attribute attr = new Attribute(attributeName);
            node.Attributes.Add(attr);
            return(attr);
        }
コード例 #8
0
        public PssgNode AppendChild(PssgNode childNode)
        {
            if (this.IsDataNode == true)
            {
                return(null);
            }

            if (this.ChildNodes == null)
            {
                this.ChildNodes = new PssgNodeCollection();
            }

            childNode.File       = this.File;
            childNode.ParentNode = this;
            this.ChildNodes.Add(childNode);
            childNode.NodeInfo = PssgSchema.AddNode(childNode);

            return(childNode);
        }
コード例 #9
0
ファイル: PssgNode.cs プロジェクト: ptasev/Ego-Engine-Modding
        public PssgNode AppendChild(PssgNode childNode)
        {
            if (this.IsDataNode == true)
            {
                throw new InvalidOperationException("Cannot append a child node to a data node");
            }

            if (this.ChildNodes == null)
            {
                this.ChildNodes = new PssgNodeCollection();
            }

            childNode.File       = this.File;
            childNode.ParentNode = this;
            this.ChildNodes.Add(childNode);
            childNode.NodeInfo = PssgSchema.AddNode(childNode);

            return(childNode);
        }
コード例 #10
0
        public PssgNode AppendChild(PssgNode childNode)
        {
            if (this.IsDataNode == true)
            {
                MessageBox.Show("Adding sub nodes to a node with data is not allowed!", "PSSG Editor", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(null);
            }

            if (this.ChildNodes == null)
            {
                this.ChildNodes = new PssgNodeCollection();
            }

            childNode.File       = this.File;
            childNode.ParentNode = this;
            this.ChildNodes.Add(childNode);
            childNode.NodeInfo = PssgSchema.AddNode(childNode);

            return(childNode);
        }
コード例 #11
0
        public static void LoadFromPssg(PssgBinaryReader reader)
        {
            int       attributeInfoCount = reader.ReadInt32();
            int       nodeInfoCount      = reader.ReadInt32();
            Node      node;
            Attribute attribute;

            for (int i = 0; i < nodeInfoCount; i++)
            {
                int nId = reader.ReadInt32();
                node    = new Node(reader.ReadPSSGString());
                node.Id = nId;

                if (entries.ContainsKey(node.Name))
                {
                    entries[node.Name].Id = node.Id;
                }
                else
                {
                    PssgSchema.AddNode(node);
                }

                int subAttributeInfoCount = reader.ReadInt32();
                for (int j = 0; j < subAttributeInfoCount; j++)
                {
                    int id = reader.ReadInt32();
                    attribute    = new Attribute(reader.ReadPSSGString());
                    attribute.Id = id;

                    Attribute attr = PssgSchema.GetAttribute(node.Name, attribute.Name);
                    if (attr == null)
                    {
                        PssgSchema.AddAttribute(node.Name, attribute);
                    }
                    else
                    {
                        attr.Id = attribute.Id;
                    }
                }
            }
        }
コード例 #12
0
        public static void AddAttribute(string nodeName, Attribute attribute)
        {
            Node node = PssgSchema.AddNode(nodeName);

            bool add = true;

            for (int i = 0; i < node.Attributes.Count; i++)
            {
                if (node.Attributes[i].Name == attribute.Name)
                {
                    add = false;
                    // Allow overwrite if current data type is null
                    PssgSchema.SetAttributeDataTypeIfNull(node.Attributes[i], attribute.DataType);
                    break;
                }
            }

            if (add)
            {
                node.Attributes.Add(attribute);
            }
        }
コード例 #13
0
        public static Attribute AddAttribute(string nodeName, string attributeName)
        {
            Node node = PssgSchema.AddNode(nodeName);

            bool add = true;

            for (int i = 0; i < node.Attributes.Count; i++)
            {
                if (node.Attributes[i].Name == attributeName)
                {
                    add = false;
                    return(node.Attributes[i]);
                }
            }

            if (add)
            {
                PssgSchema.Attribute attr = new Attribute(attributeName);
                node.Attributes.Add(attr);
                return(attr);
            }

            return(null);
        }
コード例 #14
0
        public static void LoadSchema(Stream stream)
        {
            entries.Clear();

            PssgSchema.AddAttribute("FETEXTLAYOUT", "height", typeof(Single));
            PssgSchema.AddAttribute("FETEXTLAYOUT", "depth", typeof(Single));
            PssgSchema.AddAttribute("FETEXTLAYOUT", "tracking", typeof(Single));

            PssgSchema.AddAttribute("NEGLYPHMETRICS", "advanceWidth", typeof(Single));
            PssgSchema.AddAttribute("NEGLYPHMETRICS", "horizontalBearing", typeof(Single));
            PssgSchema.AddAttribute("NEGLYPHMETRICS", "verticalBearing", typeof(Single));
            PssgSchema.AddAttribute("NEGLYPHMETRICS", "physicalWidth", typeof(Single));
            PssgSchema.AddAttribute("NEGLYPHMETRICS", "physicalHeight", typeof(Single));

            PssgSchema.AddAttribute("FEATLASINFODATA", "u0", typeof(Single));
            PssgSchema.AddAttribute("FEATLASINFODATA", "v0", typeof(Single));
            PssgSchema.AddAttribute("FEATLASINFODATA", "u1", typeof(Single));
            PssgSchema.AddAttribute("FEATLASINFODATA", "v1", typeof(Single));

            if (stream.Length == 0)
            {
                return;
            }

            using (stream)
            {
                XDocument xDoc = XDocument.Load(stream);

                foreach (XNode xN in xDoc.Descendants("node"))
                {
                    if (xN is XElement)
                    {
                        XElement elemNode = (XElement)xN;
                        string   nodeName = elemNode.Attribute("name").Value;
                        Node     node     = PssgSchema.AddNode(nodeName);
                        Type     nodeType = Type.GetType(elemNode.Attribute("dataType").Value, false);
                        if (nodeType != null)
                        {
                            node.DataType = nodeType;
                        }
                        node.ElementsPerRow = Convert.ToInt32(elemNode.Attribute("elementsPerRow").Value);
                        string linkAttributeName = elemNode.Attribute("linkAttributeName").Value;
                        if (!string.IsNullOrEmpty(linkAttributeName))
                        {
                            node.LinkAttributeName = linkAttributeName;
                        }

                        foreach (XNode subNode in elemNode.Descendants("attribute"))
                        {
                            if (xN is XElement)
                            {
                                string attrName = ((XElement)subNode).Attribute("name").Value;
                                Type   attrType = Type.GetType(((XElement)subNode).Attribute("dataType").Value, false);
                                if (attrType != null)
                                {
                                    bool add = true;
                                    for (int i = 0; i < node.Attributes.Count; i++)
                                    {
                                        if (node.Attributes[i].Name == attrName)
                                        {
                                            add = false;
                                            node.Attributes[i].DataType = attrType;
                                            break;
                                        }
                                    }

                                    if (add)
                                    {
                                        node.Attributes.Add(new Attribute(attrName, attrType));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }