mirror of
https://github.com/BlossomiShymae/Needlework.Net.git
synced 2025-12-06 18:20:47 +01:00
WIP
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
namespace Needlework.Net.Core;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
10
Needlework.Net.Core/LcuConnector.cs
Normal file
10
Needlework.Net.Core/LcuConnector.cs
Normal 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;
|
||||
}
|
||||
49
Needlework.Net.Core/LcuSchemaHandler.cs
Normal file
49
Needlework.Net.Core/LcuSchemaHandler.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
21
Needlework.Net.Core/Resources.cs
Normal file
21
Needlework.Net.Core/Resources.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user