// // Copyright 2021–2022 alterNERDtive. // // This file is part of EDNA. // // EDNA is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // EDNA is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with EDNA. If not, see <https://www.gnu.org/licenses/>. // using System; using System.Threading.Tasks; using RestSharp; namespace alterNERDtive.Edna.Edts { /// /// A star system in the galaxy of Elite Dangerous. Or rather, what EDTS /// knows about a star system. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Either this or wrong class/struct order 🤷")] public struct StarSystem { /// /// Gets or sets the system’s name. /// public string Name { get; set; } /// /// Gets or sets the system’s coordinates. /// public Coordinates Position { get; set; } /// /// Gets or sets the system’s positional uncertainty in light years. /// public decimal Uncertainty { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "Really? For this?")] public struct Coordinates { public decimal X { get; set; } public decimal Y { get; set; } public decimal Z { get; set; } } } /// /// The EdtsApi class is used to query the publicly hosted EDTS API at /// http://edts.thargoid.space for data on unknown procedurally generated /// systems. /// public class EdtsApi { private static readonly string ApiUrl = "http://edts.thargoid.space/api/v1"; private static readonly RestClient ApiClient = new RestClient(ApiUrl); /// /// Pulls system data for a given procedurally generated system name. /// /// A procedurally generated system name. /// The system with calculated coordinates. public static async Task FindSystem(string name) { RestResponse response = await ApiClient.ExecuteAsync(new RestRequest($"system_position/{name}")); if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { throw new ArgumentException(message: $"“{name}” is not a valid proc gen system name.", paramName: nameof(name)); } return response.Data.Result!.Value; } private struct ApiResult { public StarSystem? Result { get; set; } } } }