mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
Merge pull request #1510 from GoddessLuBoYan/issue1427
This commit is contained in:
@@ -200,6 +200,13 @@ internal static partial class EnumerableExtension
|
||||
return list;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||
public static List<TSource> SortBy<TSource, TKey>(this List<TSource> list, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
|
||||
{
|
||||
list.Sort((left, right) => comparer.Compare(keySelector(left), keySelector(right)));
|
||||
return list;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||
public static List<TSource> SortByDescending<TSource, TKey>(this List<TSource> list, Func<TSource, TKey> keySelector)
|
||||
where TKey : IComparable
|
||||
@@ -207,4 +214,11 @@ internal static partial class EnumerableExtension
|
||||
list.Sort((left, right) => keySelector(right).CompareTo(keySelector(left)));
|
||||
return list;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||
public static List<TSource> SortByDescending<TSource, TKey>(this List<TSource> list, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
|
||||
{
|
||||
list.Sort((left, right) => comparer.Compare(keySelector(right), keySelector(left)));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -126,10 +126,7 @@ internal sealed partial class CultivationService : ICultivationService
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
return resultItems
|
||||
.OrderByDescending(i => i.TotalCount)
|
||||
.ThenByDescending(i => i.Count)
|
||||
.ToObservableCollection();
|
||||
return resultItems.SortBy(item => item.Inner.Id, MaterialIdComparer.Shared).ToObservableCollection();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.ViewModel.Cultivation;
|
||||
|
||||
namespace Snap.Hutao.Service.Cultivation;
|
||||
|
||||
internal sealed class MaterialIdComparer : IComparer<MaterialId>
|
||||
{
|
||||
private static readonly Lazy<MaterialIdComparer> LazyShared = new(() => new());
|
||||
|
||||
public static MaterialIdComparer Shared { get => LazyShared.Value; }
|
||||
|
||||
public int Compare(MaterialId x, MaterialId y)
|
||||
{
|
||||
return Transform(x).CompareTo(Transform(y));
|
||||
}
|
||||
|
||||
private static uint Transform(MaterialId value)
|
||||
{
|
||||
return value.Value switch
|
||||
{
|
||||
// 摩拉
|
||||
202U => 0U,
|
||||
|
||||
// 经验
|
||||
104001U => 1U,
|
||||
104002U => 2U,
|
||||
104003U => 3U,
|
||||
|
||||
// 魔矿
|
||||
104011U => 4U,
|
||||
104012U => 5U,
|
||||
104013U => 6U,
|
||||
|
||||
_ => value,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using Snap.Hutao.Model.Metadata.Avatar;
|
||||
using Snap.Hutao.Model.Metadata.Item;
|
||||
using Snap.Hutao.Model.Metadata.Weapon;
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.Service.Cultivation;
|
||||
|
||||
namespace Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
|
||||
@@ -67,7 +68,7 @@ internal static class MetadataServiceContextExtension
|
||||
#pragma warning disable SH002
|
||||
public static IEnumerable<Material> EnumerateInventoryMaterial(this IMetadataListMaterialSource context)
|
||||
{
|
||||
return context.Materials.Where(m => m.IsInventoryItem()).OrderBy(m => m.Id.Value);
|
||||
return context.Materials.Where(m => m.IsInventoryItem()).OrderBy(m => m.Id, MaterialIdComparer.Shared);
|
||||
}
|
||||
|
||||
public static Avatar GetAvatar(this IMetadataDictionaryIdAvatarSource context, AvatarId id)
|
||||
|
||||
Reference in New Issue
Block a user