public static bool TryLoadXmlDefinition(XmlElement ele, out PortalDevice device)
        {
            device = null;
            int             icon;
            string          name;
            List <Location> destinations = new List <Location>(3);

            if (!ele.HasAttribute("name") ||
                !int.TryParse(ele.GetAttribute("icon"), NumberStyles.HexNumber, null, out icon))
            {
                return(false);
            }
            name = ele.GetAttribute("name");

            string     description    = "";
            XmlElement descriptionEle = ele.SelectSingleNode("description") as XmlElement;

            if (descriptionEle != null)
            {
                description = descriptionEle.InnerText.Trim();
            }

            Location infoLocation = new Location(Location.GetNextInternalId(), name,
                                                 LocationType.PortalDevice, Coordinates.NO_COORDINATES, description);

            infoLocation.Icon = icon;

            foreach (XmlElement destEle in ele.GetElementsByTagName("destination"))
            {
                Coordinates destCoords;
                string      destName;
                if (!destEle.HasAttribute("name") ||
                    !double.TryParse(destEle.GetAttribute("NS"), out destCoords.NS) ||
                    !double.TryParse(destEle.GetAttribute("EW"), out destCoords.EW))
                {
                    return(false);
                }
                destName = destEle.GetAttribute("name");
                Location dest = new Location(Location.GetNextInternalId(), destName,
                                             LocationType.PortalDevice, Coordinates.NO_COORDINATES, description, destCoords);
                dest.Icon = icon;
                destinations.Add(dest);
            }
            if (destinations.Count == 1)
            {
                infoLocation.ExitCoords = destinations[0].ExitCoords;
            }

            device = new PortalDevice(icon, name, infoLocation, destinations);
            return(true);
        }
Пример #2
0
		public static bool TryLoadXmlDefinition(XmlElement ele, out PortalDevice device)
		{
			device = null;
			int icon;
			string name;
			List<Location> destinations = new List<Location>(3);

			if (!ele.HasAttribute("name")
					|| !int.TryParse(ele.GetAttribute("icon"), NumberStyles.HexNumber, null, out icon))
			{
				return false;
			}
			name = ele.GetAttribute("name");

			string description = "";
			XmlElement descriptionEle = ele.SelectSingleNode("description") as XmlElement;
			if (descriptionEle != null)
				description = descriptionEle.InnerText.Trim();

			Location infoLocation = new Location(Location.GetNextInternalId(), name,
				LocationType.PortalDevice, Coordinates.NO_COORDINATES, description);
			infoLocation.Icon = icon;

			foreach (XmlElement destEle in ele.GetElementsByTagName("destination"))
			{
				Coordinates destCoords;
				string destName;
				if (!destEle.HasAttribute("name")
						|| !double.TryParse(destEle.GetAttribute("NS"), out destCoords.NS)
						|| !double.TryParse(destEle.GetAttribute("EW"), out destCoords.EW))
				{
					return false;
				}
				destName = destEle.GetAttribute("name");
				Location dest = new Location(Location.GetNextInternalId(), destName,
					LocationType.PortalDevice, Coordinates.NO_COORDINATES, description, destCoords);
				dest.Icon = icon;
				destinations.Add(dest);
			}
			if (destinations.Count == 1)
				infoLocation.ExitCoords = destinations[0].ExitCoords;

			device = new PortalDevice(icon, name, infoLocation, destinations);
			return true;
		}