-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
114 changed files
with
1,280 additions
and
1,219 deletions.
There are no files selected for viewing
Binary file not shown.
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,8 @@ | ||
namespace Sidekick.Apis.Poe.Filters.Models; | ||
|
||
public class ApiFilter | ||
{ | ||
public string? Id { get; set; } | ||
public string? Title { get; set; } | ||
public List<ApiFilters> Filters { get; set; } = new(); | ||
} |
6 changes: 2 additions & 4 deletions
6
...s.Poe/Metadata/Models/ApiFilterFilters.cs → ...ick.Apis.Poe/Filters/Models/ApiFilters.cs
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,86 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Sidekick.Apis.Poe.Clients; | ||
using Sidekick.Apis.Poe.Items.Models; | ||
using Sidekick.Common.Cache; | ||
using Sidekick.Common.Enums; | ||
using Sidekick.Common.Extensions; | ||
using Sidekick.Common.Game; | ||
using Sidekick.Common.Game.Items; | ||
using Sidekick.Common.Game.Languages; | ||
using Sidekick.Common.Settings; | ||
|
||
namespace Sidekick.Apis.Poe.Items | ||
{ | ||
public class ApiInvariantItemProvider | ||
( | ||
ICacheProvider cacheProvider, | ||
IPoeTradeClient poeTradeClient, | ||
ILogger<ApiInvariantItemProvider> logger, | ||
IGameLanguageProvider gameLanguageProvider, | ||
ISettingsService settingsService | ||
) : IApiInvariantItemProvider | ||
{ | ||
public Dictionary<string, ApiItem> IdDictionary { get; } = new(); | ||
|
||
public List<string> UncutGemIds { get; } = []; | ||
|
||
/// <inheritdoc/> | ||
public int Priority => 100; | ||
|
||
/// <inheritdoc/> | ||
public async Task Initialize() | ||
{ | ||
IdDictionary.Clear(); | ||
|
||
var leagueId = await settingsService.GetString(SettingKeys.LeagueId); | ||
var game = leagueId.GetGameFromLeagueId(); | ||
var cacheKey = $"{game.GetValueAttribute()}_InvariantItems"; | ||
|
||
var result = await cacheProvider.GetOrSet(cacheKey, () => poeTradeClient.Fetch<ApiCategory>(game, gameLanguageProvider.InvariantLanguage, "data/items"), (cache) => cache.Result.Any()); | ||
|
||
var categories = game switch | ||
{ | ||
GameType.PathOfExile2 => ApiItemConstants.Poe2Categories, | ||
_ => ApiItemConstants.Poe1Categories, | ||
}; | ||
foreach (var category in categories) | ||
{ | ||
FillCategoryItems(game, result.Result, category.Key, category.Value.Category); | ||
} | ||
|
||
InitializeUncutGemIds(); | ||
} | ||
|
||
private void FillCategoryItems(GameType game, List<ApiCategory> categories, string categoryId, Category category) | ||
{ | ||
var categoryItems = categories.SingleOrDefault(x => x.Id == categoryId); | ||
if (categoryItems == null) | ||
{ | ||
logger.LogWarning($"[MetadataProvider] The category '{categoryId}' could not be found in the metadata from the API."); | ||
return; | ||
} | ||
|
||
for (var i = 0; i < categoryItems.Entries.Count; i++) | ||
{ | ||
var entry = categoryItems.Entries[i]; | ||
entry.Id = $"{categoryId}.{i}"; | ||
entry.Game = game; | ||
entry.Category = category; | ||
IdDictionary.Add(entry.Id, entry); | ||
} | ||
} | ||
|
||
private void InitializeUncutGemIds() | ||
{ | ||
UncutGemIds.Clear(); | ||
|
||
foreach (var item in IdDictionary) | ||
{ | ||
if(item.Value.Type == "Uncut Skill Gem" || item.Value.Type == "Uncut Spirit Gem" || item.Value.Type == "Uncut Support Gem") | ||
{ | ||
UncutGemIds.Add(item.Key); | ||
} | ||
} | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...ck.Apis.Poe/Metadata/MetadataConstants.cs → ...dekick.Apis.Poe/Items/ApiItemConstants.cs
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,101 @@ | ||
using System.Text.RegularExpressions; | ||
using Microsoft.Extensions.Logging; | ||
using Sidekick.Apis.Poe.Clients; | ||
using Sidekick.Apis.Poe.Items.Models; | ||
using Sidekick.Common.Cache; | ||
using Sidekick.Common.Enums; | ||
using Sidekick.Common.Extensions; | ||
using Sidekick.Common.Game; | ||
using Sidekick.Common.Game.Items; | ||
using Sidekick.Common.Game.Languages; | ||
using Sidekick.Common.Settings; | ||
|
||
namespace Sidekick.Apis.Poe.Items; | ||
|
||
public class ApiItemProvider | ||
( | ||
ICacheProvider cacheProvider, | ||
IPoeTradeClient poeTradeClient, | ||
ILogger<ApiItemProvider> logger, | ||
IGameLanguageProvider gameLanguageProvider, | ||
ISettingsService settingsService | ||
) : IApiItemProvider | ||
{ | ||
public Dictionary<string, List<ApiItem>> NameAndTypeDictionary { get; } = new(); | ||
|
||
public List<(Regex Regex, ApiItem Item)> NameAndTypeRegex { get; } = new(); | ||
|
||
/// <inheritdoc/> | ||
public int Priority => 100; | ||
|
||
/// <inheritdoc/> | ||
public async Task Initialize() | ||
{ | ||
NameAndTypeDictionary.Clear(); | ||
NameAndTypeRegex.Clear(); | ||
|
||
var leagueId = await settingsService.GetString(SettingKeys.LeagueId); | ||
var game = leagueId.GetGameFromLeagueId(); | ||
var cacheKey = $"{game.GetValueAttribute()}_Items"; | ||
|
||
var result = await cacheProvider.GetOrSet(cacheKey, () => poeTradeClient.Fetch<ApiCategory>(game, gameLanguageProvider.Language, "data/items"), (cache) => cache.Result.Any()); | ||
|
||
var categories = game switch | ||
{ | ||
GameType.PathOfExile2 => ApiItemConstants.Poe2Categories, | ||
_ => ApiItemConstants.Poe1Categories, | ||
}; | ||
|
||
foreach (var category in categories) | ||
{ | ||
FillCategoryItems(game, result.Result, category.Key, category.Value.Category, category.Value.UseRegex); | ||
} | ||
} | ||
|
||
private void FillCategoryItems(GameType game, List<ApiCategory> categories, string categoryId, Category category, bool useRegex = false) | ||
{ | ||
var categoryItems = categories.SingleOrDefault(x => x.Id == categoryId); | ||
if (categoryItems == null) | ||
{ | ||
logger.LogWarning($"[MetadataProvider] The category '{categoryId}' could not be found in the metadata from the API."); | ||
return; | ||
} | ||
|
||
for (var i = 0; i < categoryItems.Entries.Count; i++) | ||
{ | ||
var entry = categoryItems.Entries[i]; | ||
entry.Id = $"{categoryId}.{i}"; | ||
entry.Game = game; | ||
entry.Category = category; | ||
|
||
if (!string.IsNullOrEmpty(entry.Name)) | ||
{ | ||
FillDictionary(entry.Name, entry); | ||
if (!entry.IsUnique && useRegex) NameAndTypeRegex.Add((new Regex(Regex.Escape(entry.Name)), entry)); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(entry.Type)) | ||
{ | ||
FillDictionary(entry.Type, entry); | ||
if (!entry.IsUnique && useRegex) NameAndTypeRegex.Add((new Regex(Regex.Escape(entry.Type)), entry)); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(entry.Text)) | ||
{ | ||
FillDictionary(entry.Text, entry); | ||
if (!entry.IsUnique && useRegex) NameAndTypeRegex.Add((new Regex(Regex.Escape(entry.Text)), entry)); | ||
} | ||
} | ||
} | ||
|
||
private void FillDictionary(string key, ApiItem metadata) | ||
{ | ||
if (!NameAndTypeDictionary.TryGetValue(key, out var dictionaryEntry)) | ||
{ | ||
dictionaryEntry = new List<ApiItem>(); | ||
NameAndTypeDictionary.Add(key, dictionaryEntry); | ||
} | ||
|
||
dictionaryEntry.Add(metadata); | ||
} | ||
} |
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,11 @@ | ||
using Sidekick.Apis.Poe.Items.Models; | ||
using Sidekick.Common.Initialization; | ||
|
||
namespace Sidekick.Apis.Poe.Items; | ||
|
||
public interface IApiInvariantItemProvider : IInitializableService | ||
{ | ||
Dictionary<string, ApiItem> IdDictionary { get; } | ||
|
||
List<string> UncutGemIds { get; } | ||
} |
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,12 @@ | ||
using System.Text.RegularExpressions; | ||
using Sidekick.Apis.Poe.Items.Models; | ||
using Sidekick.Common.Initialization; | ||
|
||
namespace Sidekick.Apis.Poe.Items; | ||
|
||
public interface IApiItemProvider : IInitializableService | ||
{ | ||
Dictionary<string, List<ApiItem>> NameAndTypeDictionary { get; } | ||
|
||
List<(Regex Regex, ApiItem Item)> NameAndTypeRegex { get; } | ||
} |
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,13 @@ | ||
namespace Sidekick.Apis.Poe.Items.Models; | ||
|
||
/// <summary> | ||
/// Items from /trade/data/items. | ||
/// </summary> | ||
public class ApiCategory | ||
{ | ||
public string? Id { get; set; } | ||
public string? Label { get; set; } | ||
public List<ApiItem> Entries { get; set; } = new(); | ||
|
||
public override string ToString() => $"{Label} - {Entries.Count} entries"; | ||
} |
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,56 @@ | ||
using System.Text.Json.Serialization; | ||
using Sidekick.Common.Game; | ||
using Sidekick.Common.Game.Items; | ||
|
||
namespace Sidekick.Apis.Poe.Items.Models; | ||
|
||
public class ApiItem | ||
{ | ||
public string? Name { get; init; } | ||
|
||
public string? Type { get; init; } | ||
|
||
public string? Text { get; init; } | ||
|
||
[JsonPropertyName("disc")] | ||
public string? Discriminator { get; init; } | ||
|
||
public ApiItemFlags? Flags { get; init; } | ||
|
||
[JsonIgnore] | ||
public string? Id { get; set; } | ||
|
||
[JsonIgnore] | ||
public GameType Game { get; set; } | ||
|
||
[JsonIgnore] | ||
public Category? Category { get; set; } | ||
|
||
[JsonIgnore] | ||
public bool IsUnique => Flags?.Unique ?? false; | ||
|
||
public Header ToHeader() | ||
{ | ||
var categoryRarity = Category switch | ||
{ | ||
Common.Game.Items.Category.DivinationCard => Rarity.DivinationCard, | ||
Common.Game.Items.Category.Gem => Rarity.Gem, | ||
Common.Game.Items.Category.Currency => Rarity.Currency, | ||
_ => Rarity.Unknown | ||
}; | ||
|
||
return new Header() | ||
{ | ||
Name = Name, | ||
Type = Text ?? Type, | ||
ApiItemId = Id ?? string.Empty, | ||
ApiName = Name, | ||
ApiType = Type, | ||
ApiText = Text, | ||
ApiDiscriminator = Discriminator, | ||
Game = Game, | ||
Category = Category ?? Common.Game.Items.Category.Unknown, | ||
Rarity = IsUnique ? Rarity.Unique : categoryRarity, | ||
}; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
....Apis.Poe/Metadata/Models/ApiItemFlags.cs → ...ick.Apis.Poe/Items/Models/ApiItemFlags.cs
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
Oops, something went wrong.