// UNKNOWN // Star // Planet / Moon / Belt // Unidentified signals // Station internal AstronomicalObject(string name, EliteEnvironment environment, AstronomicalObjectType type, AstronomicalObject star) { Name = name; Environment = environment; ObjectsInternal = new ObservableCollection <AstronomicalObject>(); Objects = new ReadOnlyObservableCollection <AstronomicalObject>(ObjectsInternal); KnownObjectProximities = new StarProximityCollection(); _trades = new ObservableCollection <Trade>(); Trades = new ReadOnlyObservableCollection <Trade>(_trades); _commodityIndex = new Dictionary <Commodity, int>(); if (environment.AutoDistanceEnabled) { float distance = 0; foreach (AstronomicalObject otherObject in environment.Objects) { if (DistancesDB.TryGetDistance(this, otherObject, out distance)) { RegisterDistanceFrom(otherObject, distance); } } } Type = type; Star = star ?? this; Environment.ObjectsInternal.Add(this); }
/// <summary> /// Finds a specific star based on its name /// </summary> /// <param name="name">The name of a star</param> /// <param name="comparisonOptions">Options for comparing the star names</param> /// <returns>The <see cref="Star"/> instance that was found, or null if no star could be found with that name.</returns> /// <exception cref="ArgumentNullException">The provided name is null.</exception> public AstronomicalObject FindObjectByName(string name, AstronomicalObjectType type, StringComparison comparisonOptions = StringComparison.InvariantCultureIgnoreCase) { if (name == null) { throw new ArgumentNullException("name", "An astronomical object name cannot be null"); } return(Objects.Where(s => s.Name.Equals(name, comparisonOptions) && s.Type == type).FirstOrDefault()); }
internal static bool Load(XmlReader reader, EliteEnvironment container) { if (!reader.IsStartElement()) { return(false); } AstronomicalObjectType type = AstronomicalObjectType.Unspecified; if (Enum.TryParse <AstronomicalObjectType>(reader.LocalName, true, out type)) { string name = null; AstronomicalObject star = null; while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "name": name = reader.Value; break; case "star": star = container.FindObjectByName(reader.Value, AstronomicalObjectType.Star); if (star == null) { throw new EnvironmentLoadException(String.Format("The star {0} could not be found", reader.Value), reader); } break; } } if (name == null) { throw new EnvironmentLoadException("Missing name for astronomical object entry", reader); } AstronomicalObject result = new AstronomicalObject(name, container, type, star); // Read child elements int curDepth = reader.Depth; while (reader.Read() && reader.Depth >= curDepth) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case "notes": result.UserNotes = reader.ReadElementContentAsString(); break; } } } return(true); } else { return(false); } }