public override void Process(ResourceManager resourceManager) { // NOTE: This (re)initializes a static data structure used for // resolving names into sector locations, so needs to be run // before any other objects (e.g. Worlds) are loaded. SectorMap.Milieu map = SectorMap.ForMilieu(resourceManager, GetStringOption("milieu")); Location loc = Location.Empty; if (HasOption("sector")) { string sectorName = GetStringOption("sector"); Sector sec = map.FromName(sectorName) ?? throw new HttpError(404, "Not Found", $"The specified sector '{sectorName}' was not found."); int hex = GetIntOption("hex", Astrometrics.SectorCentralHex); loc = new Location(sec.Location, hex); } else if (HasLocation()) { loc = GetLocation(); } if (loc.Hex.IsEmpty) { loc.Hex = Astrometrics.SectorCenter; } Sector sector = map.FromLocation(loc.Sector.X, loc.Sector.Y); var data = new Results.CreditsResult(); if (sector != null) { data.SectorX = sector.X; data.SectorY = sector.Y; // TODO: Multiple names foreach (var name in sector.Names.Take(1)) { data.SectorName = name.Text; } // Raw HTML credits data.Credits = sector.Credits?.Trim(); // Product info if (sector.Products.Count > 0) { data.ProductPublisher = sector.Products[0].Publisher; data.ProductTitle = sector.Products[0].Title; data.ProductAuthor = sector.Products[0].Author; data.ProductRef = sector.Products[0].Ref; } // Tags data.SectorTags = sector.TagString; // // Sector Credits // data.SectorAuthor = sector.Author; data.SectorSource = sector.Source; data.SectorPublisher = sector.Publisher; data.SectorCopyright = sector.Copyright; data.SectorRef = sector.Ref; data.SectorMilieu = sector.CanonicalMilieu; if (sector.DataFile != null) { data.SectorAuthor = sector.DataFile.Author ?? data.SectorAuthor; data.SectorSource = sector.DataFile.Source ?? data.SectorSource; data.SectorPublisher = sector.DataFile.Publisher ?? data.SectorPublisher; data.SectorCopyright = sector.DataFile.Copyright ?? data.SectorCopyright; data.SectorRef = sector.DataFile.Ref ?? data.SectorRef; data.SectorMilieu = sector.CanonicalMilieu; } // // Subsector Credits // int ssx = (loc.Hex.X - 1) / Astrometrics.SubsectorWidth; int ssy = (loc.Hex.Y - 1) / Astrometrics.SubsectorHeight; int ssi = ssx + ssy * 4; Subsector ss = sector.Subsector(ssi); if (ss != null) { data.SubsectorIndex = ss.Index; data.SubsectorName = ss.Name; } // // Routes Credits // // // World Data // WorldCollection worlds = sector.GetWorlds(resourceManager); if (worlds != null) { World world = worlds[loc.Hex]; if (world != null) { data.WorldName = world.Name; data.WorldHex = world.Hex; data.WorldUwp = world.UWP; data.WorldRemarks = world.Remarks; data.WorldIx = world.Importance; data.WorldEx = world.Economic; data.WorldCx = world.Cultural; data.WorldPbg = world.PBG; data.WorldAllegiance = sector.GetAllegianceFromCode(world.Allegiance)?.T5Code ?? ""; } } } SendResult(data); }
public override void Process() { ResourceManager resourceManager = new ResourceManager(context.Server); // NOTE: This (re)initializes a static data structure used for // resolving names into sector locations, so needs to be run // before any other objects (e.g. Worlds) are loaded. SectorMap.Milieu map = SectorMap.ForMilieu(resourceManager, GetStringOption("milieu")); Location loc = new Location(map.FromName("Spinward Marches").Location, 1910); if (HasOption("sector")) { string sectorName = GetStringOption("sector"); Sector sec = map.FromName(sectorName); if (sec == null) throw new HttpError(404, "Not Found", string.Format("The specified sector '{0}' was not found.", sectorName)); int hex = GetIntOption("hex", Astrometrics.SectorCentralHex); loc = new Location(sec.Location, hex); } else if (HasLocation()) { loc = GetLocation(); } if (loc.Hex.IsEmpty) loc.Hex = Astrometrics.SectorCenter; Sector sector = map.FromLocation(loc.Sector.X, loc.Sector.Y); var data = new Results.CreditsResult(); if (sector != null) { // TODO: Multiple names foreach (var name in sector.Names.Take(1)) data.SectorName = name.Text; // Raw HTML credits data.Credits = sector.Credits?.Trim(); // Product info if (sector.Products.Count > 0) { data.ProductPublisher = sector.Products[0].Publisher; data.ProductTitle = sector.Products[0].Title; data.ProductAuthor = sector.Products[0].Author; data.ProductRef = sector.Products[0].Ref; } // Tags data.SectorTags = sector.TagString; // // Sector Credits // data.SectorAuthor = sector.Author; data.SectorSource = sector.Source; data.SectorPublisher = sector.Publisher; data.SectorCopyright = sector.Copyright; data.SectorRef = sector.Ref; data.SectorEra = sector.Era; if (sector.DataFile != null) { data.SectorAuthor = sector.DataFile.Author ?? data.SectorAuthor; data.SectorSource = sector.DataFile.Source ?? data.SectorSource; data.SectorPublisher = sector.DataFile.Publisher ?? data.SectorPublisher; data.SectorCopyright = sector.DataFile.Copyright ?? data.SectorCopyright; data.SectorRef = sector.DataFile.Ref ?? data.SectorRef; data.SectorEra = sector.DataFile.Era ?? data.SectorEra; } // // Subsector Credits // int ssx = (loc.Hex.X - 1) / Astrometrics.SubsectorWidth; int ssy = (loc.Hex.Y - 1) / Astrometrics.SubsectorHeight; int ssi = ssx + ssy * 4; Subsector ss = sector.Subsector(ssi); if (ss != null) { data.SubsectorIndex = ss.Index; data.SubsectorName = ss.Name; } // // Routes Credits // // // World Data // WorldCollection worlds = sector.GetWorlds(resourceManager); if (worlds != null) { World world = worlds[loc.Hex]; if (world != null) { data.WorldName = world.Name; data.WorldHex = world.Hex; data.WorldUwp = world.UWP; data.WorldRemarks = world.Remarks; data.WorldIx = world.Importance; data.WorldEx = world.Economic; data.WorldCx = world.Cultural; data.WorldPbg = world.PBG; data.WorldAllegiance = sector.GetAllegianceFromCode(world.Allegiance).T5Code; } } } SendResult(context, data); }