Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #307 from aspriddell/add-modern-operator-info
Browse files Browse the repository at this point in the history
add modern operator info database models
  • Loading branch information
aspriddell authored Apr 3, 2022
2 parents 4bc96df + ebd8d86 commit e4194c5
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 15 deletions.
5 changes: 3 additions & 2 deletions DragonFruit.Six.Api/Legacy/Entities/LegacyOperatorInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

using System;
using DragonFruit.Six.Api.Enums;
using DragonFruit.Six.Api.Modern.Entities;
using Newtonsoft.Json;

namespace DragonFruit.Six.Api.Legacy.Entities
{
/// <summary>
/// Represents a DragonFruit-maintained operator info database entry
/// Represents a DragonFruit-maintained operator info database entry targeting the legacy stats api
/// </summary>
/// <remarks>
/// As of Y6S4, the database is no longer maintained due to Ubisoft no longer updating legacy operator stats
/// As of Y6S4, the database is no longer maintained. It is recommended to begin migration to modern stats and consume <see cref="ModernOperatorInfo"/> instead
/// </remarks>
[Serializable]
public class LegacyOperatorInfo
Expand Down
16 changes: 5 additions & 11 deletions DragonFruit.Six.Api/Legacy/LegacyStatsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public static Task<LegacyStats> GetLegacyStatsAsync(this Dragon6Client client, U
public static Task<IReadOnlyDictionary<string, LegacyStats>> GetLegacyStatsAsync(this Dragon6Client client, IEnumerable<UbisoftAccount> accounts, CancellationToken token = default)
{
const LegacyStatTypes generalStats = LegacyStatTypes.All & ~(LegacyStatTypes.Operators | LegacyStatTypes.Weapons);
return GetLegacyStatsImplAsync(client, accounts,
a => new LegacyStatsRequest(a, generalStats),
LegacyStatsDeserializer.DeserializeGeneralStats, token);
return GetPlatformStatsImplAsync(client, accounts, a => new LegacyStatsRequest(a, generalStats), LegacyStatsDeserializer.DeserializeGeneralStats, token);
}

/// <summary>
Expand All @@ -65,9 +63,7 @@ public static Task<IEnumerable<LegacyOperatorStats>> GetLegacyOperatorStatsAsync
/// <returns><see cref="IEnumerable{T}"/> of <see cref="LegacyOperatorStats"/> for the provided <see cref="UbisoftAccount"/></returns>
public static Task<ILookup<string, LegacyOperatorStats>> GetLegacyOperatorStatsAsync(this Dragon6Client client, IEnumerable<UbisoftAccount> accounts, CancellationToken token = default)
{
return GetLegacyStatsImplAsync(client, accounts,
a => new LegacyStatsRequest(a, LegacyStatTypes.Operators),
LegacyStatsDeserializer.DeserializeOperatorStats, token);
return GetPlatformStatsImplAsync(client, accounts, a => new LegacyStatsRequest(a, LegacyStatTypes.Operators), LegacyStatsDeserializer.DeserializeOperatorStats, token);
}

/// <summary>
Expand Down Expand Up @@ -100,9 +96,7 @@ public static Task<IEnumerable<LegacyWeaponStats>> GetLegacyWeaponStatsAsync(thi
/// <returns><see cref="ILookup{TKey,TElement}"/> of <see cref="LegacyWeaponStats"/> for the provided <see cref="UbisoftAccount"/></returns>
public static Task<ILookup<string, LegacyWeaponStats>> GetLegacyWeaponStatsAsync(this Dragon6Client client, IEnumerable<UbisoftAccount> accounts, CancellationToken token = default)
{
return GetLegacyStatsImplAsync(client, accounts,
a => new LegacyStatsRequest(a, LegacyStatTypes.Weapons),
LegacyStatsDeserializer.DeserializeWeaponStats, token);
return GetPlatformStatsImplAsync(client, accounts, a => new LegacyStatsRequest(a, LegacyStatTypes.Weapons), LegacyStatsDeserializer.DeserializeWeaponStats, token);
}

/// <summary>
Expand All @@ -126,12 +120,12 @@ public static Task<LegacyLevelStats> GetLegacyLevelAsync(this Dragon6Client clie
/// <returns><see cref="IReadOnlyDictionary{TKey,TValue}"/> of <see cref="LegacyWeaponStats"/> for the provided <see cref="UbisoftAccount"/></returns>
public static Task<IReadOnlyDictionary<string, LegacyLevelStats>> GetLegacyLevelAsync(this Dragon6Client client, IEnumerable<UbisoftAccount> accounts, CancellationToken token = default)
{
return GetLegacyStatsImplAsync(client, accounts,
return GetPlatformStatsImplAsync(client, accounts,
a => new PlayerLevelStatsRequest(a),
LegacyStatsDeserializer.DeserializePlayerLevelStats, token);
}

internal static Task<T> GetLegacyStatsImplAsync<T>(ApiClient client, IEnumerable<UbisoftAccount> accounts, Func<IEnumerable<UbisoftAccount>, PlatformSpecificRequest> requestFactory, Func<JObject, T> postProcessor, CancellationToken token)
internal static Task<T> GetPlatformStatsImplAsync<T>(ApiClient client, IEnumerable<UbisoftAccount> accounts, Func<IEnumerable<UbisoftAccount>, PlatformSpecificRequest> requestFactory, Func<JObject, T> postProcessor, CancellationToken token)
{
// LegacyStatsRequest is a PlatformSpecific request, so the accounts need to be split by platform
var requests = accounts.GroupBy(x => x.Platform).Select(x =>
Expand Down
58 changes: 58 additions & 0 deletions DragonFruit.Six.Api/Modern/Entities/ModernOperatorInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Dragon6 API Copyright DragonFruit Network <inbox@dragonfruit.network>
// Licensed under Apache-2. Refer to the LICENSE file for more info

using System;
using DragonFruit.Six.Api.Enums;
using Newtonsoft.Json;

namespace DragonFruit.Six.Api.Modern.Entities
{
/// <summary>
/// Represents a DragonFruit-maintained operator info database entry, compatible with the modern stats api
/// </summary>
[Serializable]
public class ModernOperatorInfo
{
/// <summary>
/// Operator Identifier
/// </summary>
[JsonProperty("id")]
public string OperatorId { get; set; }

/// <summary>
/// Operator name
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

/// <summary>
/// Numeric value representing the relative release order of the operator
/// </summary>
[JsonProperty("ord")]
public ushort Order { get; set; }

/// <summary>
/// Fully qualified operator icon url
/// </summary>
[JsonProperty("img")]
public string ImageUrl { get; set; }

/// <summary>
/// The name of the organisation the operator is from
/// </summary>
[JsonProperty("org")]
public string Organisation { get; set; }

/// <summary>
/// The subtitle, as seen underneath the operator's name in game
/// </summary>
[JsonProperty("sub")]
public string Subtitle { get; set; }

/// <summary>
/// The operator's use, attacker/defender
/// </summary>
[JsonProperty("type")]
public OperatorType Type { get; set; }
}
}
10 changes: 10 additions & 0 deletions DragonFruit.Six.Api/Modern/ModernStatsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using DragonFruit.Data;
using DragonFruit.Six.Api.Accounts.Entities;
using DragonFruit.Six.Api.Enums;
using DragonFruit.Six.Api.Modern.Containers;
Expand Down Expand Up @@ -73,6 +74,15 @@ public static Task<ModernModeStatsContainer<IEnumerable<ModernOperatorStats>>> G
.ContinueWith(t => t.Result.ProcessData<IEnumerable<ModernOperatorStats>>(request), TaskContinuationOptions.OnlyOnRanToCompletion);
}

/// <summary>
/// Gets a copy of the modern operator info database, returned as individual entries for each operator
/// </summary>
/// <param name="client">The <see cref="ApiClient"/> to use</param>
public static Task<ModernOperatorInfo[]> GetModernOperatorInfoAsync(this ApiClient client)
{
return client.PerformAsync<ModernOperatorInfo[]>(new ModernOperatorInfoRequest());
}

/// <summary>
/// Gets the user's seasonal history
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions DragonFruit.Six.Api/Modern/Requests/ModernOperatorInfoRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Dragon6 API Copyright DragonFruit Network <inbox@dragonfruit.network>
// Licensed under Apache-2. Refer to the LICENSE file for more info

using DragonFruit.Data;

namespace DragonFruit.Six.Api.Modern.Requests
{
public class ModernOperatorInfoRequest : ApiRequest
{
public override string Path => $"{Endpoints.AssetsEndpoint}/data/operators-v2.json";
}
}
4 changes: 2 additions & 2 deletions DragonFruit.Six.Api/Seasonal/SeasonStatsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static Task<SeasonalStats> GetSeasonalStatsAsync(this Dragon6Client clien
/// <param name="token">Optional cancellation token</param>
public static Task<SeasonalStatsResponse> GetSeasonalStatsAsync(this Dragon6Client client, IEnumerable<UbisoftAccount> accounts, int seasonId = -1, BoardType board = BoardType.Ranked, Region region = Region.EMEA, CancellationToken token = default)
{
return LegacyStatsExtensions.GetLegacyStatsImplAsync(client, accounts,
return LegacyStatsExtensions.GetPlatformStatsImplAsync(client, accounts,
p => new SeasonalStatsRequest(p, board, seasonId, region),
j => j.ToObject<SeasonalStatsResponse>(), token);
}
Expand All @@ -76,7 +76,7 @@ public static Task<SeasonalStatsResponse> GetSeasonalStatsAsync(this Dragon6Clie
/// </remarks>
public static Task<IEnumerable<SeasonalStats>> GetSeasonalStatsRecordsAsync(this Dragon6Client client, IEnumerable<UbisoftAccount> accounts, IEnumerable<int> seasonIds, BoardType boards, Region regions, CancellationToken token = default)
{
return LegacyStatsExtensions.GetLegacyStatsImplAsync(client, accounts,
return LegacyStatsExtensions.GetPlatformStatsImplAsync(client, accounts,
p => new SeasonalStatsRecordRequest(p, boards, seasonIds, regions),
j => j.SelectTokens("$..players_skill_records[*]").Select(x => x.ToObject<SeasonalStats>()), token);
}
Expand Down

0 comments on commit e4194c5

Please sign in to comment.