House.House.SaveHouseData C# (CSharp) Méthode

SaveHouseData() public méthode

public SaveHouseData ( ) : void
Résultat void
        public void SaveHouseData()
        {
            houseXML = new XmlDocument();
            XmlNode dec = houseXML.CreateNode(XmlNodeType.XmlDeclaration, "xml", xmlNamespace);
            houseXML.AppendChild(dec);
            XmlNode playersNode = houseXML.CreateNode(XmlNodeType.Element, "players", xmlNamespace);
            XmlNode playerNode, houses, node, coord, x, y;
            XmlAttribute attr, playerAttribute;

            foreach (PlayerHouses playerHouse in playerHouses)
            {
                playerAttribute = houseXML.CreateAttribute("id");
                playerAttribute.Value = playerHouse.PlayerName;
                playerNode = houseXML.CreateNode(XmlNodeType.Element, "player", xmlNamespace);
                playerNode.Attributes.Append(playerAttribute);

                houses = houseXML.CreateNode(XmlNodeType.Element, "houses", xmlNamespace);
                foreach (PlayerHouseCoords coords in playerHouse.Houses)
                {
                    node = houseXML.CreateNode(XmlNodeType.Element, "house", xmlNamespace);
                    attr = houseXML.CreateAttribute("name");
                    attr.Value = coords.HouseName;
                    node.Attributes.Append(attr);

                    coord = houseXML.CreateNode(XmlNodeType.Element, "topleft", xmlNamespace);
                    x = houseXML.CreateNode(XmlNodeType.Element, "x", xmlNamespace);
                    x.InnerXml = coords.TopLeft.X.ToString();
                    y = houseXML.CreateNode(XmlNodeType.Element, "y", xmlNamespace);
                    y.InnerXml = coords.TopLeft.Y.ToString();
                    coord.AppendChild(x);
                    coord.AppendChild(y);
                    node.AppendChild(coord);

                    coord = houseXML.CreateNode(XmlNodeType.Element, "bottomright", xmlNamespace);
                    x = houseXML.CreateNode(XmlNodeType.Element, "x", xmlNamespace);
                    x.InnerXml = coords.BottomRight.X.ToString();
                    y = houseXML.CreateNode(XmlNodeType.Element, "y", xmlNamespace);
                    y.InnerXml = coords.BottomRight.Y.ToString();
                    coord.AppendChild(x);
                    coord.AppendChild(y);
                    node.AppendChild(coord);

                    XmlNode locks;
                    locks = houseXML.CreateNode(XmlNodeType.Element, "lockchests", xmlNamespace);
                    locks.InnerXml = coords.LockChests.ToString();
                    node.AppendChild(locks);
                    locks = houseXML.CreateNode(XmlNodeType.Element, "lockdoors", xmlNamespace);
                    locks.InnerXml = coords.LockDoors.ToString();
                    node.AppendChild(locks);
                    locks = houseXML.CreateNode(XmlNodeType.Element, "locksigns", xmlNamespace);
                    locks.InnerXml = coords.LockSigns.ToString();
                    node.AppendChild(locks);

                    XmlNode teleportPoint, nodeX, nodeY;
                    teleportPoint = houseXML.CreateNode(XmlNodeType.Element, "teleportpoint", xmlNamespace);
                    nodeX = houseXML.CreateNode(XmlNodeType.Element, "x", xmlNamespace);
                    nodeX.InnerXml = coords.TeleportPoint.X.ToString();
                    nodeY = houseXML.CreateNode(XmlNodeType.Element, "y", xmlNamespace);
                    nodeY.InnerXml = coords.TeleportPoint.Y.ToString();
                    teleportPoint.AppendChild(nodeX);
                    teleportPoint.AppendChild(nodeY);
                    node.AppendChild(teleportPoint);

                    XmlNode allow, allowed;
                    allow = houseXML.CreateNode(XmlNodeType.Element, "allow", xmlNamespace);
                    IEnumerator allowIenum = coords.Allowed.GetEnumerator();
                    while (allowIenum.MoveNext())
                    {
                        allowed = houseXML.CreateNode(XmlNodeType.Element, "allowed", xmlNamespace);
                        allowed.InnerXml = (string)allowIenum.Current;
                        allow.AppendChild(allowed);
                    }
                    node.AppendChild(allow);

                    houses.AppendChild(node);
                }
                playerNode.AppendChild(houses);
                playersNode.AppendChild(playerNode);
            }

            houseXML.AppendChild(playersNode);
            houseXML.Save(xmlFilename);
        }