Skip to content

Commit

Permalink
Fix isPlayable case only specifically
Browse files Browse the repository at this point in the history
  • Loading branch information
BigBang1112 committed Dec 21, 2024
1 parent 5b0ab93 commit 9a36b9e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 8 deletions.
9 changes: 9 additions & 0 deletions ManiaAPI.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ManiaAPI.NadeoAPI.Extension
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManiaAPI.TMX.Extensions.Gbx", "Src\ManiaAPI.TMX.Extensions.Gbx\ManiaAPI.TMX.Extensions.Gbx.csproj", "{D9BCFCDF-41B7-401A-994F-B7ABE1C35304}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{D0C62B54-1D9D-4F31-8B0A-8158C882CF77}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateTM2020MapSample", "Samples\UpdateTM2020MapSample\UpdateTM2020MapSample.csproj", "{C5078DA8-4570-4A71-97B1-427DF356E49A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -127,6 +131,10 @@ Global
{D9BCFCDF-41B7-401A-994F-B7ABE1C35304}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9BCFCDF-41B7-401A-994F-B7ABE1C35304}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9BCFCDF-41B7-401A-994F-B7ABE1C35304}.Release|Any CPU.Build.0 = Release|Any CPU
{C5078DA8-4570-4A71-97B1-427DF356E49A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5078DA8-4570-4A71-97B1-427DF356E49A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5078DA8-4570-4A71-97B1-427DF356E49A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5078DA8-4570-4A71-97B1-427DF356E49A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -150,6 +158,7 @@ Global
{766F17F2-306E-4E4B-89EB-75CDF2907F63} = {4F91FD3F-1931-44A8-B52C-6CE105E2938A}
{BAD4BC26-CDE0-4F69-B35B-39A51871A407} = {96BF39EA-937E-400B-AAE6-7729AEEFF976}
{D9BCFCDF-41B7-401A-994F-B7ABE1C35304} = {4F91FD3F-1931-44A8-B52C-6CE105E2938A}
{C5078DA8-4570-4A71-97B1-427DF356E49A} = {D0C62B54-1D9D-4F31-8B0A-8158C882CF77}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E273F519-B658-4F1C-8132-DF78A841A592}
Expand Down
20 changes: 20 additions & 0 deletions Samples/UpdateTM2020MapSample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using ManiaAPI.NadeoAPI;
using ManiaAPI.NadeoAPI.Extensions.Gbx;
using Spectre.Console;

using var ns = new NadeoServices();

var login = AnsiConsole.Ask<string>("Enter Ubisoft Connect [green]login[/]:");

var password = AnsiConsole.Prompt(
new TextPrompt<string>("Enter Ubisoft Connect [green]password[/]:")
.PromptStyle("red")
.Secret());

await ns.AuthorizeAsync(login, password, AuthorizationMethod.UbisoftAccount);

AnsiConsole.MarkupLine("[green]Authorization successful[/]");

var mapInfo = await ns.UpdateMapAsync(Guid.Parse(args[0]), args[1]);

AnsiConsole.WriteLine(mapInfo.ToString());
21 changes: 21 additions & 0 deletions Samples/UpdateTM2020MapSample/UpdateTM2020MapSample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Spectre.Console" Version="0.49.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Src\ManiaAPI.NadeoAPI.Extensions.Gbx\ManiaAPI.NadeoAPI.Extensions.Gbx.csproj" />
<ProjectReference Include="..\..\Src\ManiaAPI.NadeoAPI\ManiaAPI.NadeoAPI.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Src/ManiaAPI.NadeoAPI.Extensions.Gbx/MapInfoSubmit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ internal sealed record MapInfoSubmit(int AuthorScore,
string MapStyle,
string MapType,
string MapUid,
string MapName,
string Name,
bool IsPlayable);
29 changes: 22 additions & 7 deletions Src/ManiaAPI.NadeoAPI.Extensions.Gbx/NadeoServicesExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using GBX.NET.Engines.Game;
using ManiaAPI.NadeoAPI.JsonContexts;
using System.Diagnostics;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using TmEssentials;

namespace ManiaAPI.NadeoAPI.Extensions.Gbx;
Expand All @@ -26,7 +29,7 @@ public static async Task<MapInfo> UploadMapAsync(this INadeoServices services, S
ArgumentNullException.ThrowIfNull(stream);
ArgumentException.ThrowIfNullOrEmpty(fileName);

using var bufferedStream = new BufferedStream(stream);
await using var bufferedStream = new BufferedStream(stream);

using var content = CreateContent(bufferedStream, fileName);

Expand Down Expand Up @@ -83,7 +86,7 @@ public static async Task<MapInfo> UpdateMapAsync(this INadeoServices services, G
ArgumentNullException.ThrowIfNull(stream);
ArgumentNullException.ThrowIfNull(fileName);

using var bufferedStream = new BufferedStream(stream);
await using var bufferedStream = new BufferedStream(stream);

using var content = CreateContent(bufferedStream, fileName);

Expand Down Expand Up @@ -132,10 +135,10 @@ private static MultipartFormDataContent CreateContent(BufferedStream bufferedStr
bufferedStream.Position = 0;

var mapInfo = new MapInfoSubmit(
map.AuthorTime.GetValueOrDefault().TotalMilliseconds,
map.GoldTime.GetValueOrDefault().TotalMilliseconds,
map.SilverTime.GetValueOrDefault().TotalMilliseconds,
map.BronzeTime.GetValueOrDefault().TotalMilliseconds,
map.AuthorTime?.TotalMilliseconds ?? -1,
map.GoldTime?.TotalMilliseconds ?? -1,
map.SilverTime?.TotalMilliseconds ?? -1,
map.BronzeTime?.TotalMilliseconds ?? -1,
AccountUtils.ToAccountId(map.AuthorLogin),
map.Collection.HasValue && map.Collection.Value.Number != 26 ? map.Collection : "Stadium",
map.MapStyle ?? string.Empty,
Expand All @@ -144,9 +147,21 @@ private static MultipartFormDataContent CreateContent(BufferedStream bufferedStr
map.MapName,
true);

Debug.WriteLine($"Upload/Update map JSON content: {JsonSerializer.Serialize(mapInfo, NadeoAPIMapInfoJsonContext.Default.MapInfoSubmit)}");

return new MultipartFormDataContent
{
{ JsonContent.Create(mapInfo, NadeoAPIMapInfoJsonContext.Default.MapInfoSubmit), "nadeoservices-core-parameters" },
{ new StringContent(map.AuthorTime.GetValueOrDefault().TotalMilliseconds.ToString()), "authorScore" },
{ new StringContent(map.GoldTime.GetValueOrDefault().TotalMilliseconds.ToString()), "goldScore" },
{ new StringContent(map.SilverTime.GetValueOrDefault().TotalMilliseconds.ToString()), "silverScore" },
{ new StringContent(map.BronzeTime.GetValueOrDefault().TotalMilliseconds.ToString()), "bronzeScore" },
{ new StringContent(AccountUtils.ToAccountId(map.AuthorLogin).ToString()), "author" },
{ new StringContent(map.Collection.HasValue && map.Collection.Value.Number != 26 ? map.Collection : "Stadium"), "collectionName" },
{ new StringContent(map.MapStyle ?? string.Empty), "mapStyle" },
{ new StringContent(map.MapType ?? string.Empty), "mapType" },
{ new StringContent(map.MapUid), "mapUid" },
{ new StringContent(map.MapName), "name" },
{ new StringContent(@"{""isPlayable"":true}", Encoding.UTF8, "application/json"), "nadeoservices-core-parameters" },
{ new StreamContent(bufferedStream), "data", fileName }
};
}
Expand Down

0 comments on commit 9a36b9e

Please sign in to comment.