This commit is contained in:
BlossomiShymae
2024-08-02 02:25:17 -05:00
parent b9b067a1c5
commit a8741cd352
41 changed files with 1051 additions and 53 deletions

View File

@@ -1,6 +0,0 @@
namespace Needlework.Net.Core;
public class Class1
{
}

View File

@@ -0,0 +1,10 @@
using BlossomiShymae.GrrrLCU;
namespace Needlework.Net.Core;
public static class LcuConnector
{
public static Func<ProcessInfo> GetProcessInfo { get; } = Connector.GetProcessInfo;
public static Func<int, string, Uri> GetLeagueClientUri { get; } = Connector.GetLeagueClientUri;
public static Func<HttpMethod, string, CancellationToken, Task<HttpResponseMessage>> SendAsync { get; } = Connector.SendAsync;
}

View File

@@ -0,0 +1,49 @@
using Microsoft.OpenApi.Models;
namespace Needlework.Net.Core;
public class LcuSchemaHandler
{
internal OpenApiDocument OpenApiDocument { get; }
public SortedDictionary<string, OpenApiPathItem> Plugins { get; } = [];
public OpenApiInfo Info => OpenApiDocument.Info;
public LcuSchemaHandler(OpenApiDocument openApiDocument)
{
OpenApiDocument = openApiDocument;
// Group paths by plugins
foreach (var tag in OpenApiDocument.Tags)
{
foreach (var path in OpenApiDocument.Paths)
{
var containsTag = false;
var sentinelTag = string.Empty;
foreach (var operation in path.Value.Operations)
{
foreach (var operationTag in operation.Value.Tags)
{
var lhs = tag.Name.Replace("Plugin ", string.Empty);
var rhs = operationTag.Name.Replace("Plugin ", string.Empty);
if (lhs.Equals(rhs, StringComparison.OrdinalIgnoreCase))
{
containsTag = true;
sentinelTag = lhs.ToLower();
break; // Break early since all operations in a path share the same tags
}
}
if (containsTag)
break; // Ditto
}
if (containsTag)
Plugins[sentinelTag] = path.Value;
}
}
}
}

View File

@@ -6,4 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BlossomiShymae.GrrrLCU" Version="0.4.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.16" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.16" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,21 @@
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers;
namespace Needlework.Net.Core;
public static class Resources
{
/// <summary>
/// Get the OpenApi document of the LCU schema. Provided by dysolix.
/// </summary>
/// <param name="httpClient"></param>
/// <returns></returns>
public static async Task<OpenApiDocument> GetOpenApiDocumentAsync(HttpClient httpClient)
{
var stream = await httpClient.GetStreamAsync("https://raw.githubusercontent.com/dysolix/hasagi-types/main/swagger.json");
var document = new OpenApiStreamReader().Read(stream, out var _);
return document;
}
}