From 01fdcda72979c531bbd7899f6ff8831e80ce4918 Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Wed, 19 Jul 2023 16:44:38 +0800 Subject: [PATCH] refactor model --- .../Snap.Hutao/Extension/NullableExtension.cs | 20 ++++++ .../Snap.Hutao/Extension/SpanExtension.cs | 18 +++++ .../Snap.Hutao/Model/Entity/GachaItem.cs | 67 +++---------------- .../Snap.Hutao/Model/Entity/GameAccount.cs | 5 +- .../Snap.Hutao/Model/Entity/InventoryItem.cs | 5 +- .../Model/Entity/SpiralAbyssEntry.cs | 6 +- .../Snap.Hutao/Model/Entity/User.cs | 5 +- .../Model/InterChange/Achievement/UIAF.cs | 3 +- .../Model/InterChange/Achievement/UIAFInfo.cs | 11 ++- .../Model/InterChange/GachaLog/UIGF.cs | 3 +- .../Model/InterChange/GachaLog/UIGFInfo.cs | 13 ++-- .../Model/InterChange/GachaLog/UIGFItem.cs | 31 ++++++++- .../Model/InterChange/Inventory/UIIFInfo.cs | 5 +- .../Intrinsic/Immutable/IntrinsicImmutable.cs | 18 ++--- .../Metadata/Avatar/Avatar.Implementation.cs | 3 +- .../Metadata/Avatar/DescriptionsParameters.cs | 5 +- .../Snap.Hutao/Model/Metadata/AvatarIds.cs | 7 +- .../DescriptionsParametersDescriptor.cs | 36 +++++----- .../Metadata/Converter/FightPropertyFormat.cs | 39 ++++++----- .../PropertiesParametersDescriptor.cs | 8 +-- .../Snap.Hutao/Model/Metadata/GrowCurve.cs | 6 +- .../Resource/Localization/SH.Designer.cs | 27 ++++++++ .../Snap.Hutao/Resource/Localization/SH.resx | 9 +++ .../AchievementService.Interchange.cs | 3 +- .../Service/Achievement/AchievementService.cs | 8 +-- .../Service/Cultivation/CultivationService.cs | 2 +- .../Service/GachaLog/GachaLogFetchContext.cs | 2 +- .../Service/GachaLog/HutaoCloudService.cs | 2 +- .../GachaLogQueryWebCacheProvider.cs | 48 ++++++------- .../Service/GachaLog/UIGFExportService.cs | 4 +- .../Service/GachaLog/UIGFImportService.cs | 4 +- .../Snap.Hutao/Service/Game/GameService.cs | 2 +- .../Snap.Hutao/Service/Hutao/HutaoCache.cs | 2 +- .../Metadata/MetadataService.Indexing.cs | 6 +- .../SpiralAbyss/SpiralAbyssRecordService.cs | 2 +- .../SpiralAbyss/SpiralAbyssRecordViewModel.cs | 2 +- .../Snap.Hutao/ViewModel/User/User.cs | 2 +- .../GachaInfo/GachaConfigTypeExtension.cs | 21 ++++++ 38 files changed, 280 insertions(+), 180 deletions(-) create mode 100644 src/Snap.Hutao/Snap.Hutao/Extension/NullableExtension.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Hk4e/Event/GachaInfo/GachaConfigTypeExtension.cs diff --git a/src/Snap.Hutao/Snap.Hutao/Extension/NullableExtension.cs b/src/Snap.Hutao/Snap.Hutao/Extension/NullableExtension.cs new file mode 100644 index 00000000..85f31b64 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Extension/NullableExtension.cs @@ -0,0 +1,20 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Extension; + +internal static class NullableExtension +{ + public static bool TryGetValue(this in T? nullable, out T value) + where T : struct + { + if (nullable.HasValue) + { + value = nullable.Value; + return true; + } + + value = default; + return false; + } +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Extension/SpanExtension.cs b/src/Snap.Hutao/Snap.Hutao/Extension/SpanExtension.cs index ce728bd1..eec2f361 100644 --- a/src/Snap.Hutao/Snap.Hutao/Extension/SpanExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Extension/SpanExtension.cs @@ -33,4 +33,22 @@ internal static class SpanExtension return maxIndex; } + + public static bool TrySplitIntoTwo(this in ReadOnlySpan span, T separator, out ReadOnlySpan left, out ReadOnlySpan right) + where T : IEquatable? + { + int indexOfSeparator = span.IndexOf(separator); + + if (indexOfSeparator > 0) + { + left = span[..indexOfSeparator]; + right = span[(indexOfSeparator + 1)..]; + + return true; + } + + left = default; + right = default; + return false; + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Entity/GachaItem.cs b/src/Snap.Hutao/Snap.Hutao/Model/Entity/GachaItem.cs index 85799237..18cca2f4 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Entity/GachaItem.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Entity/GachaItem.cs @@ -1,6 +1,7 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using Snap.Hutao.Model.Entity.Abstraction; using Snap.Hutao.Model.InterChange.GachaLog; using Snap.Hutao.Model.Metadata.Abstraction; using Snap.Hutao.Web.Hoyolab.Hk4e.Event.GachaInfo; @@ -14,7 +15,11 @@ namespace Snap.Hutao.Model.Entity; /// [HighQuality] [Table("gacha_items")] -internal sealed class GachaItem +internal sealed partial class GachaItem + : IDbMappingForeignKeyFrom, + IDbMappingForeignKeyFrom, + IDbMappingForeignKeyFrom, + IDbMappingForeignKeyFrom { /// /// 内部Id @@ -61,21 +66,6 @@ internal sealed class GachaItem /// public long Id { get; set; } - /// - /// 获取物品类型字符串 - /// - /// 物品Id - /// 物品类型字符串 - public static string GetItemTypeStringByItemId(uint itemId) - { - return itemId.Place() switch - { - 8U => "角色", - 5U => "武器", - _ => "未知", - }; - } - /// /// 构造一个新的数据库祈愿物品 /// @@ -83,13 +73,13 @@ internal sealed class GachaItem /// 祈愿物品 /// 物品Id /// 新的祈愿物品 - public static GachaItem Create(in Guid archiveId, GachaLogItem item, uint itemId) + public static GachaItem From(in Guid archiveId, in GachaLogItem item, in uint itemId) { return new() { ArchiveId = archiveId, GachaType = item.GachaType, - QueryType = ToQueryType(item.GachaType), + QueryType = item.GachaType.ToQueryType(), ItemId = itemId, Time = item.Time, Id = item.Id, @@ -103,7 +93,7 @@ internal sealed class GachaItem /// 祈愿物品 /// 物品Id /// 新的祈愿物品 - public static GachaItem CreateForMajor2Minor2OrLower(in Guid archiveId, UIGFItem item, uint itemId) + public static GachaItem From(in Guid archiveId, in UIGFItem item, in uint itemId) { return new() { @@ -122,7 +112,7 @@ internal sealed class GachaItem /// 存档Id /// 祈愿物品 /// 新的祈愿物品 - public static GachaItem CreateForMajor2Minor3OrHigher(in Guid archiveId, UIGFItem item) + public static GachaItem From(in Guid archiveId, in UIGFItem item) { return new() { @@ -141,7 +131,7 @@ internal sealed class GachaItem /// 存档Id /// 祈愿物品 /// 新的祈愿物品 - public static GachaItem Create(in Guid archiveId, Web.Hutao.GachaLog.GachaItem item) + public static GachaItem From(in Guid archiveId, in Web.Hutao.GachaLog.GachaItem item) { return new() { @@ -153,39 +143,4 @@ internal sealed class GachaItem Id = item.Id, }; } - - /// - /// 将祈愿配置类型转换到祈愿查询类型 - /// - /// 配置类型 - /// 祈愿查询类型 - public static GachaConfigType ToQueryType(GachaConfigType configType) - { - return configType switch - { - GachaConfigType.AvatarEventWish2 => GachaConfigType.AvatarEventWish, - _ => configType, - }; - } - - /// - /// 转换到UIGF物品 - /// - /// 物品 - /// UIGF 物品 - public UIGFItem ToUIGFItem(INameQuality nameQuality) - { - return new() - { - GachaType = GachaType, - ItemId = $"{ItemId}", - Count = 1, - Time = Time, - Name = nameQuality.Name, - ItemType = GetItemTypeStringByItemId(ItemId), - Rank = nameQuality.Quality, - Id = Id, - UIGFGachaType = QueryType, - }; - } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Entity/GameAccount.cs b/src/Snap.Hutao/Snap.Hutao/Model/Entity/GameAccount.cs index 5b77aa5b..37392737 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Entity/GameAccount.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Entity/GameAccount.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using CommunityToolkit.Mvvm.ComponentModel; +using Snap.Hutao.Core.Abstraction; using Snap.Hutao.Model.Entity.Primitive; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -13,7 +14,7 @@ namespace Snap.Hutao.Model.Entity; /// [HighQuality] [Table("game_accounts")] -internal sealed class GameAccount : ObservableObject +internal sealed class GameAccount : ObservableObject, IMappingFrom { /// /// 内部Id @@ -48,7 +49,7 @@ internal sealed class GameAccount : ObservableObject /// 名称 /// sdk /// 游戏内账号 - public static GameAccount Create(string name, string sdk) + public static GameAccount From(string name, string sdk) { return new() { diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Entity/InventoryItem.cs b/src/Snap.Hutao/Snap.Hutao/Model/Entity/InventoryItem.cs index 50f4e8b3..4959215d 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Entity/InventoryItem.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Entity/InventoryItem.cs @@ -1,6 +1,7 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using Snap.Hutao.Model.Entity.Abstraction; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -11,7 +12,7 @@ namespace Snap.Hutao.Model.Entity; /// [HighQuality] [Table("inventory_items")] -internal sealed class InventoryItem +internal sealed class InventoryItem : IDbMappingForeignKeyFrom { /// /// 内部Id @@ -47,7 +48,7 @@ internal sealed class InventoryItem /// 项目Id /// 物品Id /// 新的个数为0的物品 - public static InventoryItem Create(in Guid projectId, uint itemId) + public static InventoryItem From(in Guid projectId, in uint itemId) { return new() { diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Entity/SpiralAbyssEntry.cs b/src/Snap.Hutao/Snap.Hutao/Model/Entity/SpiralAbyssEntry.cs index 9ecf4261..598123b1 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Entity/SpiralAbyssEntry.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Entity/SpiralAbyssEntry.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using CommunityToolkit.Mvvm.ComponentModel; +using Snap.Hutao.Core.Abstraction; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -12,7 +13,8 @@ namespace Snap.Hutao.Model.Entity; /// [HighQuality] [Table("spiral_abysses")] -internal sealed class SpiralAbyssEntry : ObservableObject +internal sealed class SpiralAbyssEntry : ObservableObject, + IMappingFrom { /// /// 内部Id @@ -48,7 +50,7 @@ internal sealed class SpiralAbyssEntry : ObservableObject /// uid /// 深渊信息 /// 新的深渊信息 - public static SpiralAbyssEntry Create(string uid, Web.Hoyolab.Takumi.GameRecord.SpiralAbyss.SpiralAbyss spiralAbyss) + public static SpiralAbyssEntry From(string uid, Web.Hoyolab.Takumi.GameRecord.SpiralAbyss.SpiralAbyss spiralAbyss) { return new() { diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Entity/User.cs b/src/Snap.Hutao/Snap.Hutao/Model/Entity/User.cs index a5dc27ce..9a45b4ef 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Entity/User.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Entity/User.cs @@ -1,6 +1,7 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using Snap.Hutao.Core.Abstraction; using Snap.Hutao.Core.Database; using Snap.Hutao.Web.Hoyolab; using System.ComponentModel.DataAnnotations; @@ -13,7 +14,7 @@ namespace Snap.Hutao.Model.Entity; /// [HighQuality] [Table("users")] -internal sealed class User : ISelectable +internal sealed class User : ISelectable, IMappingFrom { /// /// 内部Id @@ -65,7 +66,7 @@ internal sealed class User : ISelectable /// cookie /// 是否为国际服 /// 新创建的用户 - public static User Create(Cookie cookie, bool isOversea) + public static User From(Cookie cookie, bool isOversea) { _ = cookie.TryGetSToken(isOversea, out Cookie? sToken); _ = cookie.TryGetLToken(out Cookie? lToken); diff --git a/src/Snap.Hutao/Snap.Hutao/Model/InterChange/Achievement/UIAF.cs b/src/Snap.Hutao/Snap.Hutao/Model/InterChange/Achievement/UIAF.cs index cc5d324d..fe1de58b 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/InterChange/Achievement/UIAF.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/InterChange/Achievement/UIAF.cs @@ -24,8 +24,7 @@ internal sealed class UIAF /// 信息 /// [JsonPropertyName("info")] - [JsonIgnore(Condition = JsonIgnoreCondition.Never)] - public UIAFInfo Info { get; set; } = default!; + public required UIAFInfo Info { get; set; } = default!; /// /// 列表 diff --git a/src/Snap.Hutao/Snap.Hutao/Model/InterChange/Achievement/UIAFInfo.cs b/src/Snap.Hutao/Snap.Hutao/Model/InterChange/Achievement/UIAFInfo.cs index 73be152c..276de372 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/InterChange/Achievement/UIAFInfo.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/InterChange/Achievement/UIAFInfo.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using Snap.Hutao.Core; +using Snap.Hutao.Core.Abstraction; namespace Snap.Hutao.Model.InterChange.Achievement; @@ -9,7 +10,7 @@ namespace Snap.Hutao.Model.InterChange.Achievement; /// UIAF格式的信息 /// [HighQuality] -internal sealed class UIAFInfo +internal sealed class UIAFInfo : IMappingFrom { /// /// 导出的 App 名称 @@ -47,17 +48,15 @@ internal sealed class UIAFInfo /// /// 构造一个新的专用 UIAF 信息 /// - /// 服务提供器 + /// 运行时信息 /// 专用 UIAF 信息 - public static UIAFInfo Create(IServiceProvider serviceProvider) + public static UIAFInfo From(RuntimeOptions runtimeOptions) { - RuntimeOptions hutaoOptions = serviceProvider.GetRequiredService(); - return new() { ExportTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds(), ExportApp = SH.AppName, - ExportAppVersion = hutaoOptions.Version.ToString(), + ExportAppVersion = runtimeOptions.Version.ToString(), UIAFVersion = UIAF.CurrentVersion, }; } diff --git a/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGF.cs b/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGF.cs index 88379526..1d30ee76 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGF.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGF.cs @@ -53,8 +53,7 @@ internal sealed class UIGF { foreach (UIGFItem item in List) { - // Hard coded type name - if (item.ItemType != "角色" && item.ItemType != "武器") + if (item.ItemType != SH.ModelInterchangeUIGFItemTypeAvatar && item.ItemType != SH.ModelInterchangeUIGFItemTypeWeapon) { return false; } diff --git a/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGFInfo.cs b/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGFInfo.cs index 0ddb58a6..0d4e8511 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGFInfo.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGFInfo.cs @@ -2,6 +2,8 @@ // Licensed under the MIT license. using Snap.Hutao.Core; +using Snap.Hutao.Core.Abstraction; +using Snap.Hutao.Service.Metadata; namespace Snap.Hutao.Model.InterChange.GachaLog; @@ -9,7 +11,7 @@ namespace Snap.Hutao.Model.InterChange.GachaLog; /// UIGF格式的信息 /// [HighQuality] -internal sealed class UIGFInfo +internal sealed class UIGFInfo : IMappingFrom { /// /// 用户Uid @@ -62,17 +64,18 @@ internal sealed class UIGFInfo /// 服务提供器 /// uid /// 专用 UIGF 信息 - public static UIGFInfo Create(IServiceProvider serviceProvider, string uid) + public static UIGFInfo From(IServiceProvider serviceProvider, string uid) { - RuntimeOptions hutaoOptions = serviceProvider.GetRequiredService(); + RuntimeOptions runtimeOptions = serviceProvider.GetRequiredService(); + MetadataOptions metadataOptions = serviceProvider.GetRequiredService(); return new() { Uid = uid, - Language = "zh-cn", + Language = metadataOptions.LanguageCode, ExportTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds(), ExportApp = SH.AppName, - ExportAppVersion = hutaoOptions.Version.ToString(), + ExportAppVersion = runtimeOptions.Version.ToString(), UIGFVersion = UIGF.CurrentVersion, }; } diff --git a/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGFItem.cs b/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGFItem.cs index 3c7ca2f8..5538f97e 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGFItem.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGFItem.cs @@ -1,7 +1,10 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using Snap.Hutao.Core.Abstraction; using Snap.Hutao.Core.Json.Annotation; +using Snap.Hutao.Model.Entity; +using Snap.Hutao.Model.Metadata.Abstraction; using Snap.Hutao.Web.Hoyolab.Hk4e.Event.GachaInfo; namespace Snap.Hutao.Model.InterChange.GachaLog; @@ -10,7 +13,7 @@ namespace Snap.Hutao.Model.InterChange.GachaLog; /// UIGF物品 /// [HighQuality] -internal sealed class UIGFItem : GachaLogItem +internal sealed class UIGFItem : GachaLogItem, IMappingFrom { /// /// 额外祈愿映射 @@ -18,4 +21,30 @@ internal sealed class UIGFItem : GachaLogItem [JsonPropertyName("uigf_gacha_type")] [JsonEnum(JsonSerializeType.NumberString)] public GachaConfigType UIGFGachaType { get; set; } = default!; + + public static UIGFItem From(GachaItem item, INameQuality nameQuality) + { + return new() + { + GachaType = item.GachaType, + ItemId = $"{item.ItemId:D}", + Count = 1, + Time = item.Time, + Name = nameQuality.Name, + ItemType = GetItemTypeStringByItemId(item.ItemId), + Rank = nameQuality.Quality, + Id = item.Id, + UIGFGachaType = item.QueryType, + }; + } + + private static string GetItemTypeStringByItemId(uint itemId) + { + return itemId.Place() switch + { + 8U => SH.ModelInterchangeUIGFItemTypeAvatar, + 5U => SH.ModelInterchangeUIGFItemTypeWeapon, + _ => SH.ModelInterchangeUIGFItemTypeUnknown, + }; + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Model/InterChange/Inventory/UIIFInfo.cs b/src/Snap.Hutao/Snap.Hutao/Model/InterChange/Inventory/UIIFInfo.cs index 81a4e6f4..7ba2295c 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/InterChange/Inventory/UIIFInfo.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/InterChange/Inventory/UIIFInfo.cs @@ -62,16 +62,15 @@ internal sealed class UIIFInfo /// 服务提供器 /// uid /// 专用 UIGF 信息 - public static UIIFInfo Create(IServiceProvider serviceProvider, string uid) + public static UIIFInfo From(IServiceProvider serviceProvider, string uid) { RuntimeOptions hutaoOptions = serviceProvider.GetRequiredService(); return new() { Uid = uid, - Language = "zh-cn", ExportTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds(), - ExportApp = "胡桃", + ExportApp = SH.AppName, ExportAppVersion = hutaoOptions.Version.ToString(), UIIFVersion = UIIF.CurrentVersion, }; diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/Immutable/IntrinsicImmutable.cs b/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/Immutable/IntrinsicImmutable.cs index b0e37c03..30677afc 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/Immutable/IntrinsicImmutable.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/Immutable/IntrinsicImmutable.cs @@ -51,13 +51,13 @@ internal static class IntrinsicImmutable }.ToImmutableHashSet(); public static readonly ImmutableHashSet MaterialTypeDescriptions = new HashSet(7) - { - SH.ModelMetadataMaterialCharacterAndWeaponEnhancementMaterial, - SH.ModelMetadataMaterialCharacterEXPMaterial, - SH.ModelMetadataMaterialCharacterAscensionMaterial, - SH.ModelMetadataMaterialCharacterTalentMaterial, - SH.ModelMetadataMaterialCharacterLevelUpMaterial, - SH.ModelMetadataMaterialWeaponEnhancementMaterial, - SH.ModelMetadataMaterialWeaponAscensionMaterial, - }.ToImmutableHashSet(); + { + SH.ModelMetadataMaterialCharacterAndWeaponEnhancementMaterial, + SH.ModelMetadataMaterialCharacterEXPMaterial, + SH.ModelMetadataMaterialCharacterAscensionMaterial, + SH.ModelMetadataMaterialCharacterTalentMaterial, + SH.ModelMetadataMaterialCharacterLevelUpMaterial, + SH.ModelMetadataMaterialWeaponEnhancementMaterial, + SH.ModelMetadataMaterialWeaponAscensionMaterial, + }.ToImmutableHashSet(); } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Avatar/Avatar.Implementation.cs b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Avatar/Avatar.Implementation.cs index 4788d149..149f31d6 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Avatar/Avatar.Implementation.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Avatar/Avatar.Implementation.cs @@ -30,8 +30,9 @@ internal partial class Avatar : IStatisticsItemSource, ISummaryItemSource, IName public CookBonusView? CookBonusView { get; set; } /// - /// 养成物品视图 + /// [非元数据] 养成物品视图 /// + [JsonIgnore] public List? CultivationItemsView { get; set; } /// diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Avatar/DescriptionsParameters.cs b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Avatar/DescriptionsParameters.cs index 828bc3a5..5c488f37 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Avatar/DescriptionsParameters.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Avatar/DescriptionsParameters.cs @@ -1,10 +1,13 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using Snap.Hutao.Model.Primitive; + namespace Snap.Hutao.Model.Metadata.Avatar; /// /// 描述与参数 +/// 通常用于技能 /// [HighQuality] internal sealed class DescriptionsParameters @@ -17,5 +20,5 @@ internal sealed class DescriptionsParameters /// /// 参数 /// - public List> Parameters { get; set; } = default!; + public List> Parameters { get; set; } = default!; } diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/AvatarIds.cs b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/AvatarIds.cs index f01d436f..4558fa80 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/AvatarIds.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/AvatarIds.cs @@ -101,7 +101,12 @@ internal static class AvatarIds return avatarId == PlayerBoy || avatarId == PlayerGirl; } - public static Dictionary InsertPlayers(Dictionary idAvatarMap) + /// + /// 复制一个映射并加入旅行者的基本信息 + /// + /// 映射 + /// 加入旅行者基本信息的映射 + public static Dictionary WithPlayers(Dictionary idAvatarMap) { return new(idAvatarMap) { diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/DescriptionsParametersDescriptor.cs b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/DescriptionsParametersDescriptor.cs index cce1db7d..adf0e4bb 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/DescriptionsParametersDescriptor.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/DescriptionsParametersDescriptor.cs @@ -2,7 +2,9 @@ // Licensed under the MIT license. using Snap.Hutao.Control; +using Snap.Hutao.Core.ExceptionService; using Snap.Hutao.Model.Metadata.Avatar; +using Snap.Hutao.Model.Primitive; using System.Runtime.InteropServices; using System.Text.RegularExpressions; @@ -22,8 +24,8 @@ internal sealed partial class DescriptionsParametersDescriptor : ValueConverter< /// 特定等级的解释 public static LevelParameters Convert(DescriptionsParameters from, uint level) { - LevelParameters param = from.Parameters.Single(param => param.Level == level); - return new LevelParameters($"Lv.{param.Level}", GetParameterDescription(from.Descriptions, param.Parameters)); + LevelParameters param = from.Parameters.Single(param => param.Level == level); + return new LevelParameters($"Lv.{param.Level.Value}", GetParameterDescription(from.Descriptions, param.Parameters)); } /// @@ -35,36 +37,36 @@ internal sealed partial class DescriptionsParametersDescriptor : ValueConverter< return parameters; } - [GeneratedRegex("{param[0-9]+.*?}")] + [GeneratedRegex("{param([1-9][0-9]*?):(.+?)}")] private static partial Regex ParamRegex(); - private static List GetParameterDescription(List descriptions, List param) + private static List GetParameterDescription(List descriptions, List paramList) { Span span = CollectionsMarshal.AsSpan(descriptions); List results = new(span.Length); - foreach (ReadOnlySpan desc in span) + foreach (string desc in span) { - int indexOfSeparator = desc.IndexOf('|'); - ReadOnlySpan description = desc[..indexOfSeparator]; - ReadOnlySpan format = desc[(indexOfSeparator + 1)..]; - - string resultFormatted = ParamRegex().Replace(format.ToString(), match => ReplaceParamInMatch(match, param)); - results.Add(new ParameterDescription { Description = description.ToString(), Parameter = resultFormatted }); + if (desc.AsSpan().TrySplitIntoTwo('|', out ReadOnlySpan description, out ReadOnlySpan format)) + { + string resultFormatted = ParamRegex().Replace(format.ToString(), match => ReplaceParamInMatch(match, paramList)); + results.Add(new ParameterDescription { Description = description.ToString(), Parameter = resultFormatted }); + } + else + { + ThrowHelper.InvalidOperation($"ParameterFormat failed, value: `{desc}`", default); + } } return results; } - private static string ReplaceParamInMatch(Match match, List param) + private static string ReplaceParamInMatch(Match match, List paramList) { if (match.Success) { - // remove parentheses and split by {value:format} like {param1:F} - string[] parts = match.Value[1..^1].Split(':', 2); - - int index = int.Parse(parts[0]["param".Length..]) - 1; - return ParameterFormat.Format($"{{0:{parts[1]}}}", param[index]); + int index = int.Parse(match.Groups[1].Value) - 1; + return ParameterFormat.Format($"{{0:{match.Groups[2].Value}}}", paramList[index]); } else { diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/FightPropertyFormat.cs b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/FightPropertyFormat.cs index 272541a2..4988078f 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/FightPropertyFormat.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/FightPropertyFormat.cs @@ -34,22 +34,13 @@ internal static class FightPropertyFormat return new(property.GetLocalizedDescription(), FormatValue(property, value)); } - /// - /// 格式化有绿字的角色属性 - /// - /// 战斗属性 - /// 白字 - /// 绿字 - /// 对2 - public static AvatarProperty ToAvatarProperty(FightProperty property, float baseValue, float addValue) + public static ParameterDescription ToParameterDescription(FightProperty property, float value) { - string name = property.GetLocalizedDescription(); - FormatMethod method = property.GetFormatMethod(); - - string value = FormatValue(method, baseValue + addValue); - string addedValue = $"[{FormatValue(method, baseValue)}+{FormatValue(method, addValue)}]"; - - return new(property, name, value, addedValue); + return new() + { + Description = property.GetLocalizedDescription(), + Parameter = FormatValue(property, value), + }; } /// @@ -82,6 +73,24 @@ internal static class FightPropertyFormat return new(property, name, FormatValue(method, value)); } + /// + /// 格式化有绿字的角色属性 + /// + /// 战斗属性 + /// 白字 + /// 绿字 + /// 对2 + public static AvatarProperty ToAvatarProperty(FightProperty property, float baseValue, float addValue) + { + string name = property.GetLocalizedDescription(); + FormatMethod method = property.GetFormatMethod(); + + string value = FormatValue(method, baseValue + addValue); + string addedValue = $"[{FormatValue(method, baseValue)}+{FormatValue(method, addValue)}]"; + + return new(property, name, value, addedValue); + } + /// /// 格式化战斗属性 /// diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/PropertiesParametersDescriptor.cs b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/PropertiesParametersDescriptor.cs index 710dbd0c..dba16ac2 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/PropertiesParametersDescriptor.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/PropertiesParametersDescriptor.cs @@ -24,15 +24,11 @@ internal sealed class PropertiesParametersDescriptor : ValueConverter GetParameterDescriptions(List parameters, List properties) { - List results = new(); + List results = new(parameters.Count); foreach ((float param, FightProperty property) in parameters.Zip(properties)) { - results.Add(new ParameterDescription - { - Description = property.GetLocalizedDescription(), - Parameter = FightPropertyFormat.FormatValue(property, param), - }); + results.Add(FightPropertyFormat.ToParameterDescription(property, param)); } return results; diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/GrowCurve.cs b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/GrowCurve.cs index e11e55ea..0daf1072 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/GrowCurve.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/GrowCurve.cs @@ -12,7 +12,7 @@ namespace Snap.Hutao.Model.Metadata; [HighQuality] internal sealed class GrowCurve { - private Dictionary? curveMap; + private Dictionary? map; /// /// 等级 @@ -27,8 +27,8 @@ internal sealed class GrowCurve /// /// 曲线映射 /// - public Dictionary CurveMap + public Dictionary Map { - get => curveMap ??= Curves.ToDictionary(v => v.Type, v => v.Value); + get => map ??= Curves.ToDictionary(v => v.Type, v => v.Value); } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.Designer.cs b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.Designer.cs index 749a23b8..07d2f9ad 100644 --- a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.Designer.cs +++ b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.Designer.cs @@ -420,6 +420,33 @@ namespace Snap.Hutao.Resource.Localization { } } + /// + /// 查找类似 角色 的本地化字符串。 + /// + internal static string ModelInterchangeUIGFItemTypeAvatar { + get { + return ResourceManager.GetString("ModelInterchangeUIGFItemTypeAvatar", resourceCulture); + } + } + + /// + /// 查找类似 未知 的本地化字符串。 + /// + internal static string ModelInterchangeUIGFItemTypeUnknown { + get { + return ResourceManager.GetString("ModelInterchangeUIGFItemTypeUnknown", resourceCulture); + } + } + + /// + /// 查找类似 武器 的本地化字符串。 + /// + internal static string ModelInterchangeUIGFItemTypeWeapon { + get { + return ResourceManager.GetString("ModelInterchangeUIGFItemTypeWeapon", resourceCulture); + } + } + /// /// 查找类似 愚人众 的本地化字符串。 /// diff --git a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx index 2d6c2b45..2ca3149f 100644 --- a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx +++ b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx @@ -2063,4 +2063,13 @@ Url 中的语言:{0} 与胡桃的语言:{1} 不匹配,请切换到对应语言重试 + + 角色 + + + 武器 + + + 未知 + \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.Interchange.cs b/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.Interchange.cs index 36d19d55..0c55a7a5 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.Interchange.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.Interchange.cs @@ -1,6 +1,7 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using Snap.Hutao.Core; using Snap.Hutao.Model.Entity; using Snap.Hutao.Model.Entity.Database; using Snap.Hutao.Model.InterChange.Achievement; @@ -63,7 +64,7 @@ internal sealed partial class AchievementService return new() { - Info = UIAFInfo.Create(serviceProvider), + Info = UIAFInfo.From(scope.ServiceProvider.GetRequiredService()), List = list, }; } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.cs index 2b1e6f20..35b674a4 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.cs @@ -68,16 +68,16 @@ internal sealed partial class AchievementService : IAchievementService List results = new(); foreach (AchievementArchive archive in appDbContext.AchievementArchives) { - int finished = await appDbContext.Achievements + int finishedCount = await appDbContext.Achievements .Where(a => a.ArchiveId == archive.InnerId) - .Where(a => (int)a.Status >= (int)Model.Intrinsic.AchievementStatus.STATUS_FINISHED) + .Where(a => a.Status >= Model.Intrinsic.AchievementStatus.STATUS_FINISHED) .CountAsync() .ConfigureAwait(false); int totalCount = achievementMap.Count; List achievements = await appDbContext.Achievements .Where(a => a.ArchiveId == archive.InnerId) - .Where(a => (int)a.Status >= (int)Model.Intrinsic.AchievementStatus.STATUS_FINISHED) + .Where(a => a.Status >= Model.Intrinsic.AchievementStatus.STATUS_FINISHED) .OrderByDescending(a => a.Time.ToString()) .Take(2) .ToListAsync() @@ -86,7 +86,7 @@ internal sealed partial class AchievementService : IAchievementService results.Add(new() { DisplayName = archive.Name, - FinishDescription = AchievementStatistics.Format(finished, totalCount, out _), + FinishDescription = AchievementStatistics.Format(finishedCount, totalCount, out _), Achievements = achievements.SelectList(entity => new AchievementView(entity, achievementMap[entity.Id])), }); } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs index 2b074172..86c26c1c 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs @@ -45,7 +45,7 @@ internal sealed partial class CultivationService : ICultivationService List results = new(); foreach (Material meta in metadata.Where(m => m.IsInventoryItem()).OrderBy(m => m.Id.Value)) { - InventoryItem entity = entities.SingleOrDefault(e => e.ItemId == meta.Id) ?? InventoryItem.Create(projectId, meta.Id); + InventoryItem entity = entities.SingleOrDefault(e => e.ItemId == meta.Id) ?? InventoryItem.From(projectId, meta.Id); results.Add(new(entity, meta, saveCommand)); } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/GachaLogFetchContext.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/GachaLogFetchContext.cs index 13100756..d2efc450 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/GachaLogFetchContext.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/GachaLogFetchContext.cs @@ -131,7 +131,7 @@ internal struct GachaLogFetchContext /// 物品 public void AddItem(GachaLogItem item) { - ItemsToAdd.Add(GachaItem.Create(TargetArchive!.InnerId, item, serviceContext.GetItemId(item))); + ItemsToAdd.Add(GachaItem.From(TargetArchive!.InnerId, item, serviceContext.GetItemId(item))); FetchStatus.Items.Add(serviceContext.GetItemByNameAndType(item.Name, item.ItemType)); QueryOptions.EndId = item.Id; } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/HutaoCloudService.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/HutaoCloudService.cs index 543df1cf..63fadd86 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/HutaoCloudService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/HutaoCloudService.cs @@ -80,7 +80,7 @@ internal sealed partial class HutaoCloudService : IHutaoCloudService await appDbContext.GachaArchives.AddAndSaveAsync(archive).ConfigureAwait(false); } - List gachaItems = resp.Data.SelectList(i => Model.Entity.GachaItem.Create(archive.InnerId, i)); + List gachaItems = resp.Data.SelectList(i => Model.Entity.GachaItem.From(archive.InnerId, i)); await appDbContext.GachaItems.AddRangeAndSaveAsync(gachaItems).ConfigureAwait(false); return new(true, archive); } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryWebCacheProvider.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryWebCacheProvider.cs index 27528e98..832e066c 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryWebCacheProvider.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryWebCacheProvider.cs @@ -53,41 +53,41 @@ internal sealed partial class GachaLogQueryWebCacheProvider : IGachaLogQueryProv using (TempFile? tempFile = TempFile.CopyFrom(cacheFile)) { - if (tempFile == null) + if (tempFile.TryGetValue(out TempFile file)) { - return new(false, string.Format(Regex.Unescape(SH.ServiceGachaLogUrlProviderCachePathNotFound), cacheFile)); - } - - using (FileStream fileStream = new(tempFile.Path, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - using (MemoryStream memoryStream = new()) + using (FileStream fileStream = new(file.Path, FileMode.Open, FileAccess.Read, FileShare.Read)) { - await fileStream.CopyToAsync(memoryStream).ConfigureAwait(false); - string? result = Match(memoryStream, cacheFile.Contains(GameConstants.GenshinImpactData)); - - if (!string.IsNullOrEmpty(result)) + using (MemoryStream memoryStream = new()) { - QueryString query = QueryString.Parse(result.TrimEnd("#/log")); - string queryLanguageCode = query["lang"]; - if (metadataOptions.IsCurrentLocale(queryLanguageCode)) + await fileStream.CopyToAsync(memoryStream).ConfigureAwait(false); + string? result = Match(memoryStream, cacheFile.Contains(GameConstants.GenshinImpactData)); + + if (!string.IsNullOrEmpty(result)) { - return new(true, new(result)); + QueryString query = QueryString.Parse(result.TrimEnd("#/log")); + string queryLanguageCode = query["lang"]; + if (metadataOptions.IsCurrentLocale(queryLanguageCode)) + { + return new(true, new(result)); + } + else + { + string message = string.Format( + SH.ServiceGachaLogUrlProviderUrlLanguageNotMatchCurrentLocale, + queryLanguageCode, + metadataOptions.LocaleName); + return new(false, message); + } } else { - string message = string.Format( - SH.ServiceGachaLogUrlProviderUrlLanguageNotMatchCurrentLocale, - queryLanguageCode, - metadataOptions.LocaleName); - return new(false, message); + return new(false, SH.ServiceGachaLogUrlProviderCacheUrlNotFound); } } - else - { - return new(false, SH.ServiceGachaLogUrlProviderCacheUrlNotFound); - } } } + + return new(false, string.Format(Regex.Unescape(SH.ServiceGachaLogUrlProviderCachePathNotFound), cacheFile)); } } else diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/UIGFExportService.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/UIGFExportService.cs index 0f026b3e..5a6ec3df 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/UIGFExportService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/UIGFExportService.cs @@ -28,12 +28,12 @@ internal sealed partial class UIGFExportService : IUIGFExportService List list = appDbContext.GachaItems .Where(i => i.ArchiveId == archive.InnerId) .AsEnumerable() - .Select(i => i.ToUIGFItem(context.GetNameQualityByItemId(i.ItemId))) + .Select(i => UIGFItem.From(i, context.GetNameQualityByItemId(i.ItemId))) .ToList(); UIGF uigf = new() { - Info = UIGFInfo.Create(serviceProvider, archive.Uid), + Info = UIGFInfo.From(serviceProvider, archive.Uid), List = list, }; diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/UIGFImportService.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/UIGFImportService.cs index f4eab009..10579235 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/UIGFImportService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/UIGFImportService.cs @@ -45,11 +45,11 @@ internal sealed partial class UIGFImportService : IUIGFImportService UIGFVersion.Major2Minor3OrHigher => uigf.List .OrderByDescending(i => i.Id) .Where(i => i.Id < trimId) - .Select(i => GachaItem.CreateForMajor2Minor3OrHigher(archiveId, i)), + .Select(i => GachaItem.From(archiveId, i)), UIGFVersion.Major2Minor2OrLower => uigf.List .OrderByDescending(i => i.Id) .Where(i => i.Id < trimId) - .Select(i => GachaItem.CreateForMajor2Minor2OrLower(archiveId, i, context.GetItemId(i))), + .Select(i => GachaItem.From(archiveId, i, context.GetItemId(i))), _ => Enumerable.Empty(), }; diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/GameService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/GameService.cs index 1e9bdc2e..0a856dee 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/GameService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/GameService.cs @@ -326,7 +326,7 @@ internal sealed partial class GameService : IGameService if (isOk) { - account = GameAccount.Create(name, registrySdk); + account = GameAccount.From(name, registrySdk); // sync database await taskContext.SwitchToBackgroundAsync(); diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Hutao/HutaoCache.cs b/src/Snap.Hutao/Snap.Hutao/Service/Hutao/HutaoCache.cs index a8391d8f..1b49d828 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Hutao/HutaoCache.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Hutao/HutaoCache.cs @@ -158,7 +158,7 @@ internal sealed partial class HutaoCache : IHutaoCache if (idAvatarExtendedMap == null) { Dictionary idAvatarMap = await metadataService.GetIdToAvatarMapAsync().ConfigureAwait(false); - idAvatarExtendedMap = AvatarIds.InsertPlayers(idAvatarMap); + idAvatarExtendedMap = AvatarIds.WithPlayers(idAvatarMap); } return idAvatarExtendedMap; diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Metadata/MetadataService.Indexing.cs b/src/Snap.Hutao/Snap.Hutao/Service/Metadata/MetadataService.Indexing.cs index 14dca10e..40b89528 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Metadata/MetadataService.Indexing.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Metadata/MetadataService.Indexing.cs @@ -94,19 +94,19 @@ internal sealed partial class MetadataService /// public ValueTask>> GetLevelToAvatarCurveMapAsync(CancellationToken token = default) { - return FromCacheAsDictionaryAsync, GrowCurve>(FileNameAvatarCurve, a => a.Level, a => a.CurveMap, token); + return FromCacheAsDictionaryAsync, GrowCurve>(FileNameAvatarCurve, a => a.Level, a => a.Map, token); } /// public ValueTask>> GetLevelToMonsterCurveMapAsync(CancellationToken token = default) { - return FromCacheAsDictionaryAsync, GrowCurve>(FileNameMonsterCurve, m => m.Level, m => m.CurveMap, token); + return FromCacheAsDictionaryAsync, GrowCurve>(FileNameMonsterCurve, m => m.Level, m => m.Map, token); } /// public ValueTask>> GetLevelToWeaponCurveMapAsync(CancellationToken token = default) { - return FromCacheAsDictionaryAsync, GrowCurve>(FileNameWeaponCurve, w => w.Level, w => w.CurveMap, token); + return FromCacheAsDictionaryAsync, GrowCurve>(FileNameWeaponCurve, w => w.Level, w => w.Map, token); } /// diff --git a/src/Snap.Hutao/Snap.Hutao/Service/SpiralAbyss/SpiralAbyssRecordService.cs b/src/Snap.Hutao/Snap.Hutao/Service/SpiralAbyss/SpiralAbyssRecordService.cs index 272a23aa..85bd442a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/SpiralAbyss/SpiralAbyssRecordService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/SpiralAbyss/SpiralAbyssRecordService.cs @@ -88,7 +88,7 @@ internal sealed partial class SpiralAbyssRecordService : ISpiralAbyssRecordServi } else { - SpiralAbyssEntry newEntry = SpiralAbyssEntry.Create(userAndUid.Uid.Value, webSpiralAbyss); + SpiralAbyssEntry newEntry = SpiralAbyssEntry.From(userAndUid.Uid.Value, webSpiralAbyss); await taskContext.SwitchToMainThreadAsync(); spiralAbysses!.Insert(0, newEntry); diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/SpiralAbyssRecordViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/SpiralAbyssRecordViewModel.cs index ced04fb8..b5c3c2d4 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/SpiralAbyssRecordViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/SpiralAbyssRecordViewModel.cs @@ -82,7 +82,7 @@ internal sealed partial class SpiralAbyssRecordViewModel : Abstraction.ViewModel if (await metadataService.InitializeAsync().ConfigureAwait(false)) { idAvatarMap = await metadataService.GetIdToAvatarMapAsync().ConfigureAwait(false); - idAvatarMap = AvatarIds.InsertPlayers(idAvatarMap); + idAvatarMap = AvatarIds.WithPlayers(idAvatarMap); if (UserAndUid.TryFromUser(userService.Current, out UserAndUid? userAndUid)) { diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/User/User.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/User/User.cs index 097c6aa7..add502d1 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/User/User.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/User/User.cs @@ -126,7 +126,7 @@ internal sealed class User : ObservableObject internal static async Task CreateAsync(Cookie cookie, bool isOversea, CancellationToken token = default) { // 这里只负责创建实体用户,稍后在用户服务中保存到数据库 - EntityUser entity = EntityUser.Create(cookie, isOversea); + EntityUser entity = EntityUser.From(cookie, isOversea); entity.Aid = cookie.GetValueOrDefault(Cookie.STUID); entity.Mid = isOversea ? entity.Aid : cookie.GetValueOrDefault(Cookie.MID); diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Hk4e/Event/GachaInfo/GachaConfigTypeExtension.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Hk4e/Event/GachaInfo/GachaConfigTypeExtension.cs new file mode 100644 index 00000000..ddda41be --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Hk4e/Event/GachaInfo/GachaConfigTypeExtension.cs @@ -0,0 +1,21 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.Hk4e.Event.GachaInfo; + +internal static class GachaConfigTypeExtension +{ + /// + /// 将祈愿配置类型转换到祈愿查询类型 + /// + /// 配置类型 + /// 祈愿查询类型 + public static GachaConfigType ToQueryType(this GachaConfigType configType) + { + return configType switch + { + GachaConfigType.AvatarEventWish2 => GachaConfigType.AvatarEventWish, + _ => configType, + }; + } +} \ No newline at end of file