public ISystem FindSystem(string name, EDSM.GalacticMapping glist = null) // in system or name { ISystem ds1 = SystemCache.FindSystem(name); // now go thru the cache.. if (ds1 == null) { HistoryEntry vs = FindByName(name); if (vs != null) { ds1 = vs.System; } else if (glist != null) { EDSM.GalacticMapObject gmo = glist.Find(name, true, true); if (gmo != null && gmo.points.Count > 0) { ds1 = SystemClassDB.GetSystem(gmo.galMapSearch); if (ds1 != null) { return(new EDSM.GalacticMapSystem(ds1, gmo)); } else { return(new EDSM.GalacticMapSystem(gmo)); } } } } return(ds1); }
public GalacticMapSystem(ISystem sys, GalacticMapObject gmo) { this.allegiance = sys.allegiance; this.CommanderCreate = sys.CommanderCreate; this.CommanderUpdate = sys.CommanderUpdate; this.cr = sys.cr; this.CreateDate = sys.CreateDate; this.eddb_updated_at = sys.eddb_updated_at; this.faction = sys.faction; this.government = sys.government; this.gridid = sys.gridid; this.id_eddb = sys.id_eddb; this.id_edsm = sys.id_edsm; this.name = sys.name; this.needs_permit = sys.needs_permit; this.population = sys.population; this.primary_economy = sys.primary_economy; this.randomid = sys.randomid; this.security = sys.security; this.state = sys.state; this.status = sys.status; this.UpdateDate = sys.UpdateDate; this.x = sys.x; this.y = sys.y; this.z = sys.z; this.GalMapObject = gmo; }
// Checks Cache, Database, History, Galactic map if required, and EDSM directly if required public ISystem FindSystem(string name, EDSM.GalacticMapping glist, bool checkedsm) // in system or name { ISystem ds1 = SystemCache.FindSystem(name, checkedsm); // go thru the cache and edsm if required if (ds1 == null) { HistoryEntry vs = FindByName(name); // else try and find in our list if (vs != null) { ds1 = vs.System; } else if (glist != null) // if we have a galmap { EDSM.GalacticMapObject gmo = glist.Find(name, true); if (gmo != null && gmo.points.Count > 0) // valid item, and has position { ds1 = SystemCache.FindSystem(gmo.galMapSearch); // only thru the db/cache, as we checked above for edsm direct, may be null return(gmo.GetSystem(ds1)); // and return a ISystem. If ds1=null, we use the points pos, if ds1 is found, we use the cache position } } } return(ds1); }
public GalacticMapSystem(ISystem sys, GalacticMapObject gmo) { this.Allegiance = sys.Allegiance; this.CommanderCreate = sys.CommanderCreate; this.CommanderUpdate = sys.CommanderUpdate; this.CreateDate = sys.CreateDate; this.EDDBUpdatedAt = sys.EDDBUpdatedAt; this.Faction = sys.Faction; this.Government = sys.Government; this.GridID = sys.GridID; this.EDDBID = sys.EDDBID; this.EDSMID = sys.EDSMID; this.Name = sys.Name; this.NeedsPermit = sys.NeedsPermit; this.Population = sys.Population; this.PrimaryEconomy = sys.PrimaryEconomy; this.RandomID = sys.RandomID; this.Security = sys.Security; this.State = sys.State; this.status = sys.status; this.UpdateDate = sys.UpdateDate; this.X = sys.X; this.Y = sys.Y; this.Z = sys.Z; this.GalMapObject = gmo; }
public GalacticMapSystem(GalacticMapObject gmo) { this.name = gmo.galMapSearch; this.x = gmo.points[0].X; this.y = gmo.points[0].Y; this.z = gmo.points[0].Z; this.GalMapObject = gmo; }
public GalacticMapSystem(GalacticMapObject gmo) { this.Name = gmo.galMapSearch; this.X = gmo.points[0].X; this.Y = gmo.points[0].Y; this.Z = gmo.points[0].Z; this.GalMapObject = gmo; }
public bool Parse(string file) { var gmobjects = new List <GalacticMapObject>(); try { string json = BaseUtils.FileHelpers.TryReadAllTextFromFile(file); if (json != null) { JArray galobjects = JArray.ParseThrowCommaEOL(json); foreach (JObject jo in galobjects) { GalacticMapObject galobject = new GalacticMapObject(jo); GalMapType ty = galacticMapTypes.Find(x => x.Typeid.Equals(galobject.type)); if (ty == null) { ty = galacticMapTypes[galacticMapTypes.Count - 1]; // last one is default.. System.Diagnostics.Trace.WriteLine("Unknown Gal Map object " + galobject.type + " " + galobject.name); } galobject.galMapType = ty; gmobjects.Add(galobject); if (galobject.points.Count == 1 && galobject.galMapSearch != null && galobject.galMapUrl != null) { var gms = new GalacticMapSystem(galobject); SystemCache.FindCachedJournalSystem(gms); } } galacticMapObjects = gmobjects; return(true); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("GalacticMapping.parsedata exception:" + ex.Message); } return(false); }
public GalacticMapSystem(GalacticMapObject gmo) : base() { this.Name = gmo.galMapSearch; this.X = gmo.points[0].X; this.Y = gmo.points[0].Y; this.Z = gmo.points[0].Z; this.GalMapObject = gmo; if (gmo.galMapUrl != null) { var rematch = EDSMIdRegex.Match(gmo.galMapUrl); long edsmid; if (rematch != null && long.TryParse(rematch.Groups[1].Value, out edsmid)) { this.EDSMID = edsmid; } } }
public bool ParseJson(string json) { var gmobjects = new List <GalacticMapObject>(); try { if (json.HasChars()) { //Dictionary<string, int> counts = new Dictionary<string, int>(); foreach (var v in GalMapType.GetTypes()) counts[v.Typeid] = 0; JArray galobjects = (JArray)JArray.Parse(json); foreach (JObject jo in galobjects) { GalacticMapObject galobject = new GalacticMapObject(jo); GalMapType ty = galacticMapTypes.Find(x => x.Typeid.Equals(galobject.type)); //System.Diagnostics.Debug.WriteLine($"Type {galobject.type}"); //counts[galobject.type]++; if (ty == null) { ty = galacticMapTypes[galacticMapTypes.Count - 1]; // last one is default.. System.Diagnostics.Trace.WriteLine("Unknown Gal Map object " + galobject.type); } galobject.galMapType = ty; gmobjects.Add(galobject); } galacticMapObjects = gmobjects; return(true); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("GalacticMapping.parsedata exception:" + ex.Message); } return(false); }
public bool ParseData() { var gmobjects = new List <GalacticMapObject>(); try { string json = BaseUtils.FileHelpers.TryReadAllTextFromFile(GalacticMappingFile); if (json != null) { JArray galobjects = (JArray)JArray.Parse(json); foreach (JObject jo in galobjects) { GalacticMapObject galobject = new GalacticMapObject(jo); GalMapType ty = galacticMapTypes.Find(x => x.Typeid.Equals(galobject.type)); if (ty == null) { ty = galacticMapTypes[galacticMapTypes.Count - 1]; // last one is default.. Console.WriteLine("Unknown Gal Map object " + galobject.type); } galobject.galMapType = ty; gmobjects.Add(galobject); } galacticMapObjects = gmobjects; return(true); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("GalacticMapping.parsedata exception:" + ex.Message); } return(false); }
public GalacticMapObject FindNearest(double x, double y, double z) { GalacticMapObject nearest = null; if (galacticMapObjects != null) { double mindist = double.MaxValue; foreach (GalacticMapObject gmo in galacticMapObjects) { if (gmo.points.Count == 1) // only for single point bits { double distsq = (gmo.points[0].X - x) * (gmo.points[0].X - x) + (gmo.points[0].Y - y) * (gmo.points[0].Y - y) + (gmo.points[0].Z - z) * (gmo.points[0].Z - z); if (distsq < mindist) { mindist = distsq; nearest = gmo; } } } } return(nearest); }
public GalacticMapSystem(ISystem sys, GalacticMapObject gmo) : base(sys) { this.GalMapObject = gmo; }