mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
use list instead of mappppps
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
|
||||
namespace Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
|
||||
internal interface IMetadataDictionaryAvatarIdProfilePictureSource
|
||||
{
|
||||
public Dictionary<AvatarId, Model.Metadata.Avatar.ProfilePicture> AvatarIdProfilePictureMap { get; set; }
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
|
||||
namespace Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
|
||||
internal interface IMetadataDictionaryCostumeIdProfilePictureSource
|
||||
{
|
||||
public Dictionary<CostumeId, Model.Metadata.Avatar.ProfilePicture> CostumeIdProfilePictureMap { get; set; }
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
|
||||
namespace Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
|
||||
internal interface IMetadataDictionaryIdProfilePictureSource
|
||||
{
|
||||
public Dictionary<ProfilePictureId, Model.Metadata.Avatar.ProfilePicture> IdProfilePictureMap { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Metadata.Avatar;
|
||||
|
||||
namespace Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
|
||||
internal interface IMetadataListProfilePictureSource
|
||||
{
|
||||
public List<ProfilePicture> ProfilePictures { get; set; }
|
||||
}
|
||||
@@ -38,6 +38,11 @@ internal static class MetadataServiceContextExtension
|
||||
listMaterialSource.Materials = await metadataService.GetMaterialListAsync(token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (context is IMetadataListProfilePictureSource dictionaryIdProfilePictureSource)
|
||||
{
|
||||
dictionaryIdProfilePictureSource.ProfilePictures = await metadataService.GetProfilePictureListAsync(token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (context is IMetadataListReliquaryMainAffixLevelSource listReliquaryMainAffixLevelSource)
|
||||
{
|
||||
listReliquaryMainAffixLevelSource.ReliquaryMainAffixLevels = await metadataService.GetReliquaryMainAffixLevelListAsync(token).ConfigureAwait(false);
|
||||
@@ -66,21 +71,6 @@ internal static class MetadataServiceContextExtension
|
||||
dictionaryIdMaterialSource.IdMaterialMap = await metadataService.GetIdToMaterialMapAsync(token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (context is IMetadataDictionaryIdProfilePictureSource dictionaryIdProfilePictureSource)
|
||||
{
|
||||
dictionaryIdProfilePictureSource.IdProfilePictureMap = await metadataService.GetIdToProfilePictureMapAsync(token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (context is IMetadataDictionaryAvatarIdProfilePictureSource dictionaryAvatarIdProfilePictureSource)
|
||||
{
|
||||
dictionaryAvatarIdProfilePictureSource.AvatarIdProfilePictureMap = await metadataService.GetAvatarIdToProfilePictureMapAsync(token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (context is IMetadataDictionaryCostumeIdProfilePictureSource dictionaryCostumeIdProfilePictureSource)
|
||||
{
|
||||
dictionaryCostumeIdProfilePictureSource.CostumeIdProfilePictureMap = await metadataService.GetCostumeIdToProfilePictureMapAsync(token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (context is IMetadataDictionaryIdReliquarySource dictionaryIdReliquarySource)
|
||||
{
|
||||
dictionaryIdReliquarySource.IdReliquaryMap = await metadataService.GetIdToReliquaryMapAsync(token).ConfigureAwait(false);
|
||||
|
||||
@@ -71,21 +71,6 @@ internal static class MetadataServiceDictionaryExtension
|
||||
return metadataService.FromCacheAsDictionaryAsync<MaterialId, Material>(FileNameMaterial, a => a.Id, token);
|
||||
}
|
||||
|
||||
public static ValueTask<Dictionary<ProfilePictureId, ProfilePicture>> GetIdToProfilePictureMapAsync(this IMetadataService metadataService, CancellationToken token = default)
|
||||
{
|
||||
return metadataService.FromCacheAsDictionaryAsync<ProfilePictureId, ProfilePicture>(FileNameProfilePicture, p => p.Id, token);
|
||||
}
|
||||
|
||||
public static ValueTask<Dictionary<AvatarId, ProfilePicture>> GetAvatarIdToProfilePictureMapAsync(this IMetadataService metadataService, CancellationToken token = default)
|
||||
{
|
||||
return metadataService.FromCacheAsDictionaryAsync(FileNameProfilePicture, (List<ProfilePicture> list) => list.Where(p => p.UnlockType is ProfilePictureUnlockType.Avatar).Select(p => ((AvatarId)p.UnlockParameter, p)), token);
|
||||
}
|
||||
|
||||
public static ValueTask<Dictionary<CostumeId, ProfilePicture>> GetCostumeIdToProfilePictureMapAsync(this IMetadataService metadataService, CancellationToken token = default)
|
||||
{
|
||||
return metadataService.FromCacheAsDictionaryAsync(FileNameProfilePicture, (List<ProfilePicture> list) => list.Where(p => p.UnlockType is ProfilePictureUnlockType.Costume).Select(p => ((CostumeId)p.UnlockParameter, p)), token);
|
||||
}
|
||||
|
||||
public static ValueTask<Dictionary<ReliquaryId, Reliquary>> GetIdToReliquaryMapAsync(this IMetadataService metadataService, CancellationToken token = default)
|
||||
{
|
||||
return metadataService.FromCacheAsDictionaryAsync(FileNameReliquary, (List<Reliquary> list) => list.SelectMany(r => r.Ids, (r, i) => (Index: i, Reliquary: r)), token);
|
||||
|
||||
@@ -70,6 +70,11 @@ internal static class MetadataServiceListExtension
|
||||
return metadataService.FromCacheOrFileAsync<List<GrowCurve>>(FileNameMonsterCurve, token);
|
||||
}
|
||||
|
||||
public static ValueTask<List<ProfilePicture>> GetProfilePictureListAsync(this IMetadataService metadataService, CancellationToken token = default)
|
||||
{
|
||||
return metadataService.FromCacheOrFileAsync<List<ProfilePicture>>(FileNameProfilePicture, token);
|
||||
}
|
||||
|
||||
public static ValueTask<List<Reliquary>> GetReliquaryListAsync(this IMetadataService metadataService, CancellationToken token = default)
|
||||
{
|
||||
return metadataService.FromCacheOrFileAsync<List<Reliquary>>(FileNameReliquary, token);
|
||||
|
||||
@@ -6,6 +6,4 @@ using Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
namespace Snap.Hutao.Service.User;
|
||||
|
||||
internal interface IUserMetadataContext : IMetadataContext,
|
||||
IMetadataDictionaryIdProfilePictureSource,
|
||||
IMetadataDictionaryAvatarIdProfilePictureSource,
|
||||
IMetadataDictionaryCostumeIdProfilePictureSource;
|
||||
IMetadataListProfilePictureSource;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
using Snap.Hutao.Core.DependencyInjection.Abstraction;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Model.Entity.Extension;
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.Service.Metadata;
|
||||
using Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
using Snap.Hutao.Web.Enka;
|
||||
@@ -294,21 +295,30 @@ internal sealed partial class UserInitializationService : IUserInitializationSer
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (context.IdProfilePictureMap.TryGetValue(profilePicture.ProfilePictureId, out MetadataProfilePicture? metadataProfilePicture))
|
||||
if (profilePicture.ProfilePictureId is not 0U)
|
||||
{
|
||||
userGameRole.ProfilePictureIcon = metadataProfilePicture.Icon;
|
||||
userGameRole.ProfilePictureIcon = context.ProfilePictures
|
||||
.Single(p => p.Id == profilePicture.ProfilePictureId)
|
||||
.Icon;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (context.CostumeIdProfilePictureMap.TryGetValue(profilePicture.CostumeId, out metadataProfilePicture))
|
||||
if (profilePicture.CostumeId is not 0U)
|
||||
{
|
||||
userGameRole.ProfilePictureIcon = metadataProfilePicture.Icon;
|
||||
userGameRole.ProfilePictureIcon = context.ProfilePictures
|
||||
.Single(p => p.UnlockType is ProfilePictureUnlockType.Costume && p.UnlockParameter == profilePicture.CostumeId)
|
||||
.Icon;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (context.AvatarIdProfilePictureMap.TryGetValue(profilePicture.AvatarId, out metadataProfilePicture))
|
||||
if (profilePicture.AvatarId is not 0U)
|
||||
{
|
||||
userGameRole.ProfilePictureIcon = metadataProfilePicture.Icon;
|
||||
userGameRole.ProfilePictureIcon = context.ProfilePictures
|
||||
.Single(p => p.UnlockType is ProfilePictureUnlockType.Avatar && p.UnlockParameter == profilePicture.AvatarId)
|
||||
.Icon;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,10 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Metadata.Avatar;
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
|
||||
namespace Snap.Hutao.Service.User;
|
||||
|
||||
internal class UserMetadataContext : IUserMetadataContext
|
||||
{
|
||||
public Dictionary<ProfilePictureId, ProfilePicture> IdProfilePictureMap { get; set; } = default!;
|
||||
|
||||
public Dictionary<AvatarId, ProfilePicture> AvatarIdProfilePictureMap { get; set; } = default!;
|
||||
|
||||
public Dictionary<CostumeId, ProfilePicture> CostumeIdProfilePictureMap { get; set; } = default!;
|
||||
public List<ProfilePicture> ProfilePictures { get; set; } = default!;
|
||||
}
|
||||
|
||||
@@ -29,8 +29,7 @@ internal sealed partial class EnkaClient
|
||||
|
||||
public ValueTask<EnkaResponse?> GetForwardPlayerInfoAsync(in PlayerUid playerUid, CancellationToken token = default)
|
||||
{
|
||||
// TODO
|
||||
return TryGetEnkaResponseCoreAsync($"https://enka-api.hut.ao/{playerUid}?info", token);
|
||||
return TryGetEnkaResponseCoreAsync(HutaoEndpoints.EnkaPlayerInfo(playerUid), token);
|
||||
}
|
||||
|
||||
public ValueTask<EnkaResponse?> GetPlayerInfoAsync(in PlayerUid playerUid, CancellationToken token = default)
|
||||
|
||||
@@ -297,5 +297,4 @@ internal static class HutaoEndpoints
|
||||
private const string ApiSnapGenshinStaticZip = $"{ApiSnapGenshin}/static/zip";
|
||||
private const string ApiSnapGenshinEnka = $"{ApiSnapGenshin}/enka";
|
||||
private const string HomaSnapGenshin = "https://homa.snapgenshin.com";
|
||||
private const string EnkaHutao = "https://enka-api.hut.ao";
|
||||
}
|
||||
Reference in New Issue
Block a user