-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SpanshAttack: moved EDTS stuff to plugin code
see #62
- Loading branch information
1 parent
fdccb3a
commit 2d6c96f
Showing
7 changed files
with
138 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace alterNERDtive.edts | ||
{ | ||
|
||
public struct StarSystem | ||
{ | ||
public string Name { get; set; } | ||
public Position Coords { get; set; } | ||
} | ||
public struct Position | ||
{ | ||
public int X { get; set; } | ||
public int Y { get; set; } | ||
public int Z { get; set; } | ||
public int Precision { get; set; } | ||
} | ||
|
||
public class EdtsApi | ||
{ | ||
private static readonly string APIURL = "http://edts.thargoid.space/api/v1/"; | ||
private static HttpClient ApiClient; | ||
|
||
static EdtsApi() | ||
{ | ||
ApiClient = new HttpClient | ||
{ | ||
BaseAddress = new Uri(APIURL) | ||
}; | ||
ApiClient.DefaultRequestHeaders.Accept.Clear(); | ||
ApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||
} | ||
|
||
public static StarSystem GetCoordinates(string name) | ||
{ | ||
HttpResponseMessage response = ApiClient.GetAsync($"system_position/{name}").Result; | ||
|
||
if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) // 400 | ||
{ | ||
throw new ArgumentException($"“{name}” is not a valid proc gen system name.", "~system"); | ||
} | ||
|
||
response.EnsureSuccessStatusCode(); | ||
dynamic json = response.Content.ReadAsAsync<dynamic>().Result["result"]; | ||
|
||
int x = json["position"]["x"]; | ||
int y = json["position"]["y"]; | ||
int z = json["position"]["z"]; | ||
int uncertainty = json["uncertainty"]; | ||
|
||
return new StarSystem { Name=name, Coords=new Position { X=x, Y=y, Z=z, Precision=uncertainty } }; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net48" /> | ||
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net48" /> | ||
</packages> |
Binary file not shown.