public static SpaceShipHardpoint FromXml(XmlResource Xml, SpaceShipHardpoint DstObject)
        {
            if (Xml == null)
            {
                throw new ArgumentNullException("Xml");
            }
            SpaceShipHardpoint Result = DstObject;

            if (DstObject == null)
            {
                Result = new SpaceShipHardpoint();
            }
            Result = SpaceShip.FromXml(Xml, Result) as SpaceShipHardpoint;

            XmlNode obj = Xml.Xml.LastChild;

            string             baseName   = GetXmlText(obj, "Base", string.Empty);
            SpaceShipHardpoint baseObject = Result;

            if (!string.IsNullOrEmpty(baseName))
            {
                try
                {
                    baseObject = SpaceShipHardpoint.FromXml(ResourceManager.Get <XmlResource>(baseName), null);
                }
                catch (KeyNotFoundException e)
                {
                    baseObject = Result;
                    Console.WriteLine("XML Error: Failed to locate XML base " + baseName);
                }
            }

            string[] offsetRaw = GetXmlText(obj, "Offset", "0,0").Split(',');
            Result.Offset  = new Vector2(float.Parse(offsetRaw[0]), float.Parse(offsetRaw[1]));
            Result.Texture = ResourceManager.Get <TextureResource>(GetXmlText(obj, "Texture", baseObject.Texture.Name));
            return(Result);
        }
Example #2
0
        private static List <SpaceObject> GetXmlNested(XmlNode Parent, string Name, List <SpaceObject> Default)
        {
            if (Parent.HasChildNodes)
            {
                XmlNodeList children = Parent.ChildNodes;
                foreach (XmlNode node in children)
                {
                    if (node.Name.ToUpperInvariant() == Name.ToUpperInvariant())
                    {
                        List <SpaceObject> result = new List <SpaceObject>();
                        if (node.ChildNodes.Count > 0)
                        {
                            children = node.ChildNodes;
                            foreach (XmlNode childNode in children)
                            {
                                if (childNode.Name.ToUpperInvariant() == "hardpoint".ToUpperInvariant())
                                {
                                    SpaceShipHardpoint child = SpaceShipHardpoint.FromXml(new XmlResource()
                                    {
                                        Xml = new XmlDocument()
                                        {
                                            InnerXml = childNode.OuterXml
                                        }
                                    }, null);
                                    result.Add(child);
                                }
                            }
                        }

                        return(result);
                    }
                }
            }

            return(Default);
        }