Compare commits

..

37 Commits

Author SHA1 Message Date
qhy040404
8fbd648b1b add profile picture for each game role 2024-06-14 01:09:32 +08:00
qhy040404
107963b7ac Update issue template 2024-06-13 18:39:03 +08:00
DismissedLight
4e89406f2f Merge pull request #1721 from DGP-Studio/feat/1715 2024-06-13 16:15:21 +08:00
Lightczx
8119de3fa9 code style 2024-06-13 16:15:08 +08:00
qhy040404
7a8c233b10 review requests 2024-06-13 15:36:50 +08:00
qhy040404
cc71aa9c82 impl #1715 2024-06-13 12:51:22 +08:00
DismissedLight
4276481284 Add CachedImage Debug Layer 2024-06-11 21:05:24 +08:00
Lightczx
6f3159ae0c [skip ci] QA announcement name 2024-06-11 17:01:14 +08:00
Lightczx
c1b3412ba1 fix QA ComboBox width issue 2024-06-11 16:56:33 +08:00
Lightczx
99b3613319 fix #1688 2024-06-11 15:42:23 +08:00
Lightczx
069407abbc use weapon sort 2024-06-11 15:06:15 +08:00
DismissedLight
98c8df5c8e Merge pull request #1712 from DGP-Studio/feat/v3_cultivation 2024-06-11 14:04:49 +08:00
Lightczx
7cfcc17763 refactor 2024-06-11 14:00:48 +08:00
qhy040404
23741c4e48 exclude unavailable avatars 2024-06-11 13:12:37 +08:00
qhy040404
5f4b68d538 add cache to minimal deltas 2024-06-11 12:55:54 +08:00
Lightczx
9ef0d8c57d add SCIP solver 2024-06-11 12:31:51 +08:00
qhy040404
f0bfea51cf move to inventory service 2024-06-11 00:06:01 +08:00
DismissedLight
905454eb02 refactor 2024-06-10 23:31:38 +08:00
DismissedLight
05c3a575bc adjust db service parameter 2024-06-10 23:03:23 +08:00
DismissedLight
3e26e247cd refactor metadata abstraction 2024-06-10 22:43:50 +08:00
qhy040404
293b1e214d migrate all v2 api to v3 api 2024-06-10 22:37:56 +08:00
qhy040404
063665e77e refresh inventory 2024-06-10 22:37:55 +08:00
DismissedLight
50389ac06c Merge pull request #1713 from DGP-Studio/fix/dailynote 2024-06-10 22:12:57 +08:00
qhy040404
b99b34945e fix #1711 2024-06-10 11:05:58 +08:00
qhy040404
94a96c76bc fix #1710 2024-06-10 10:57:29 +08:00
DismissedLight
5cf3046257 Merge pull request #1694 from Mikachu2333/develop 2024-06-06 15:16:22 +08:00
Lightczx
89f8dedb57 fix url protocol launch lock 2024-06-06 13:11:24 +08:00
LinkChou
3c1e9237aa replace Uid to UID 2024-06-06 11:54:11 +08:00
LinkChou
e7cb01b302 Merge branch 'develop' of https://github.com/Mikachu2333/Snap.Hutao into develop 2024-06-06 11:48:03 +08:00
LinkChou
4cd971e166 Add some 2024-06-06 11:47:37 +08:00
Mikachu2333
7a9657f0cb Merge branch 'DGP-Studio:develop' into develop 2024-06-06 11:44:31 +08:00
Lightczx
82e6b62231 correctly free library 2024-06-06 09:29:50 +08:00
LinkChou
374c4d796d reformat 2024-06-06 07:25:11 +08:00
Mikachu2333
6e149a5be3 Update SH.resx 2024-06-06 01:44:32 +08:00
Mikachu2333
00ad0ef346 correct format 2024-06-06 01:39:10 +08:00
Mikachu2333
f22f165592 Merge branch 'develop' into develop 2024-06-06 01:33:09 +08:00
LinkChou
49c75dde2a Chinese text improve 2024-06-05 18:43:45 +08:00
97 changed files with 2118 additions and 704 deletions

View File

@@ -1,7 +1,7 @@
name: 功能请求
description: 通过这个议题来向开发团队分享你的想法
title: "[Feat]: 在这里填写一个合适的标题"
labels: ["功能", "needs-triage", "priority:none"]
labels: ["feature request", "needs-triage", "priority:none"]
assignees:
- Lightczx
body:

View File

@@ -1,7 +1,7 @@
name: Feature Request [English Form]
description: Tell us about your thought
title: "[Feat]: Place your title here"
labels: ["功能", "needs-triage", "priority:none"]
labels: ["feature request", "needs-triage", "priority:none"]
assignees:
- Lightczx
body:

View File

@@ -0,0 +1,51 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using CommunityToolkit.WinUI.Behaviors;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace Snap.Hutao.Control.Behavior;
[SuppressMessage("", "CA1001")]
[DependencyProperty("MilliSecondsDelay", typeof(int))]
internal sealed partial class InfoBarDelayCloseBehavior : BehaviorBase<InfoBar>
{
private readonly CancellationTokenSource closeTokenSource = new();
protected override void OnAssociatedObjectLoaded()
{
AssociatedObject.Closed += OnInfoBarClosed;
if (MilliSecondsDelay > 0)
{
DelayCoreAsync().SafeForget();
}
}
private async ValueTask DelayCoreAsync()
{
try
{
await Task.Delay(MilliSecondsDelay, closeTokenSource.Token).ConfigureAwait(true);
}
catch
{
return;
}
if (AssociatedObject is not null)
{
AssociatedObject.IsOpen = false;
}
}
private void OnInfoBarClosed(InfoBar infoBar, InfoBarClosedEventArgs args)
{
if (args.Reason is InfoBarCloseReason.CloseButton)
{
closeTokenSource.Cancel();
}
AssociatedObject.Closed -= OnInfoBarClosed;
}
}

View File

@@ -1,10 +1,15 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.UI.Xaml.Media.Imaging;
using Snap.Hutao.Control.Extension;
using Snap.Hutao.Core.Caching;
using Snap.Hutao.Core.ExceptionService;
using Snap.Hutao.Core.IO.DataTransfer;
using System.IO;
using System.Runtime.InteropServices;
using Windows.Graphics.Imaging;
using Windows.Storage.Streams;
namespace Snap.Hutao.Control.Image;
@@ -12,8 +17,12 @@ namespace Snap.Hutao.Control.Image;
/// 缓存图像
/// </summary>
[HighQuality]
internal sealed class CachedImage : Implementation.ImageEx
[DependencyProperty("SourceName", typeof(string), "Unknown")]
[DependencyProperty("CachedName", typeof(string), "Unknown")]
internal sealed partial class CachedImage : Implementation.ImageEx
{
private string? file;
/// <summary>
/// 构造一个新的缓存图像
/// </summary>
@@ -26,12 +35,15 @@ internal sealed class CachedImage : Implementation.ImageEx
/// <inheritdoc/>
protected override async Task<Uri?> ProvideCachedResourceAsync(Uri imageUri, CancellationToken token)
{
SourceName = Path.GetFileName(imageUri.ToString());
IImageCache imageCache = this.ServiceProvider().GetRequiredService<IImageCache>();
try
{
HutaoException.ThrowIf(string.IsNullOrEmpty(imageUri.Host), SH.ControlImageCachedImageInvalidResourceUri);
string file = await imageCache.GetFileFromCacheAsync(imageUri).ConfigureAwait(true); // BitmapImage need to be created by main thread.
CachedName = Path.GetFileName(file);
this.file = file;
token.ThrowIfCancellationRequested(); // check token state to determine whether the operation should be canceled.
return file.ToUri();
}
@@ -42,4 +54,27 @@ internal sealed class CachedImage : Implementation.ImageEx
return default;
}
}
[Command("CopyToClipboardCommand")]
private async Task CopyToClipboard()
{
if (Image is Microsoft.UI.Xaml.Controls.Image { Source: BitmapImage bitmap })
{
using (FileStream netStream = File.OpenRead(bitmap.UriSource.LocalPath))
{
using (IRandomAccessStream fxStream = netStream.AsRandomAccessStream())
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fxStream);
SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
using (InMemoryRandomAccessStream memory = new())
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, memory);
encoder.SetSoftwareBitmap(softwareBitmap);
await encoder.FlushAsync();
Ioc.Default.GetRequiredService<IClipboardProvider>().SetBitmap(memory);
}
}
}
}
}
}

View File

@@ -1,4 +1,4 @@
<ResourceDictionary
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shci="using:Snap.Hutao.Control.Image">
@@ -14,6 +14,13 @@
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Grid.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem IsEnabled="False" Text="{TemplateBinding SourceName}"/>
<MenuFlyoutItem IsEnabled="False" Text="{TemplateBinding CachedName}"/>
<MenuFlyoutItem Command="{Binding CopyToClipboardCommand, RelativeSource={RelativeSource TemplatedParent}}" Text="复制图像"/>
</MenuFlyout>
</Grid.ContextFlyout>
<Image
Name="PlaceholderImage"
Margin="{TemplateBinding PlaceholderMargin}"

View File

@@ -5,7 +5,6 @@ using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Markup;
using Microsoft.UI.Xaml.Navigation;
using Snap.Hutao.Core.Abstraction;
using Snap.Hutao.Service.Navigation;
using Snap.Hutao.View.Helper;
using Snap.Hutao.ViewModel.Abstraction;

View File

@@ -0,0 +1,25 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Snap.Hutao.Service.Notification;
namespace Snap.Hutao.Control.Selector;
internal sealed class InfoBarTemplateSelector : DataTemplateSelector
{
public DataTemplate ActionButtonEnabled { get; set; } = default!;
public DataTemplate ActionButtonDisabled { get; set; } = default!;
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
{
if (item is InfoBarOptions { ActionButtonContent: { }, ActionButtonCommand: { } })
{
return ActionButtonEnabled;
}
return ActionButtonDisabled;
}
}

View File

@@ -21,8 +21,8 @@ internal sealed partial class SizeRestrictedContentControl : ContentControl
element.Measure(availableSize);
Size contentDesiredSize = element.DesiredSize;
Size contentActualOrDesiredSize = new(
Math.Max(element.ActualWidth, contentDesiredSize.Width),
Math.Max(element.ActualHeight, contentDesiredSize.Height));
Math.Min(Math.Max(element.ActualWidth, contentDesiredSize.Width), availableSize.Width),
Math.Min(Math.Max(element.ActualHeight, contentDesiredSize.Height), availableSize.Height));
if (IsWidthRestricted)
{

View File

@@ -10,6 +10,7 @@
<shmmc:AchievementIconConverter x:Key="AchievementIconConverter"/>
<shmmc:AvatarCardConverter x:Key="AvatarCardConverter"/>
<shmmc:AvatarIconConverter x:Key="AvatarIconConverter"/>
<shmmc:AvatarIconCircleConverter x:Key="AvatarIconCircleConverter"/>
<shmmc:AvatarNameCardPicConverter x:Key="AvatarNameCardPicConverter"/>
<shmmc:AvatarSideIconConverter x:Key="AvatarSideIconConverter"/>
<shmmc:DescriptionsParametersDescriptor x:Key="DescParamDescriptor"/>

View File

@@ -3,7 +3,6 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Snap.Hutao.Win32.Registry;
using System.Linq.Expressions;
using System.Net;
using System.Reflection;

View File

@@ -56,30 +56,39 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi
/// <inheritdoc/>
public void PostInitialization()
{
serviceProvider.GetRequiredService<PrivateNamedPipeServer>().RunAsync().SafeForget();
ToastNotificationManagerCompat.OnActivated += NotificationActivate;
RunPostInitializationAsync().SafeForget();
using (activateSemaphore.Enter())
async ValueTask RunPostInitializationAsync()
{
// TODO: Introduced in 1.10.2, remove in later version
serviceProvider.GetRequiredService<IJumpListInterop>().ClearAsync().SafeForget();
serviceProvider.GetRequiredService<IScheduleTaskInterop>().UnregisterAllTasks();
await taskContext.SwitchToBackgroundAsync();
if (UnsafeLocalSetting.Get(SettingKeys.Major1Minor10Revision0GuideState, GuideState.Language) < GuideState.Completed)
serviceProvider.GetRequiredService<PrivateNamedPipeServer>().RunAsync().SafeForget();
ToastNotificationManagerCompat.OnActivated += NotificationActivate;
using (await activateSemaphore.EnterAsync().ConfigureAwait(false))
{
return;
// TODO: Introduced in 1.10.2, remove in later version
serviceProvider.GetRequiredService<IJumpListInterop>().ClearAsync().SafeForget();
serviceProvider.GetRequiredService<IScheduleTaskInterop>().UnregisterAllTasks();
if (UnsafeLocalSetting.Get(SettingKeys.Major1Minor10Revision0GuideState, GuideState.Language) < GuideState.Completed)
{
return;
}
serviceProvider.GetRequiredService<HotKeyOptions>().RegisterAll();
if (serviceProvider.GetRequiredService<AppOptions>().IsNotifyIconEnabled)
{
XamlLifetime.ApplicationLaunchedWithNotifyIcon = true;
await taskContext.SwitchToMainThreadAsync();
serviceProvider.GetRequiredService<App>().DispatcherShutdownMode = DispatcherShutdownMode.OnExplicitShutdown;
_ = serviceProvider.GetRequiredService<NotifyIconController>();
}
serviceProvider.GetRequiredService<IQuartzService>().StartAsync(default).SafeForget();
}
serviceProvider.GetRequiredService<HotKeyOptions>().RegisterAll();
if (serviceProvider.GetRequiredService<AppOptions>().IsNotifyIconEnabled)
{
XamlLifetime.ApplicationLaunchedWithNotifyIcon = true;
serviceProvider.GetRequiredService<App>().DispatcherShutdownMode = DispatcherShutdownMode.OnExplicitShutdown;
_ = serviceProvider.GetRequiredService<NotifyIconController>();
}
serviceProvider.GetRequiredService<IQuartzService>().StartAsync(default).SafeForget();
}
}
@@ -140,6 +149,8 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi
private async ValueTask HandleActivationAsync(HutaoActivationArguments args)
{
await taskContext.SwitchToBackgroundAsync();
if (activateSemaphore.CurrentCount > 0)
{
using (await activateSemaphore.EnterAsync().ConfigureAwait(false))

View File

@@ -199,6 +199,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, Comparison<TKey> comparison)
{
list.Sort((left, right) => comparison(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
@@ -213,4 +220,11 @@ internal static partial class EnumerableExtension
list.Sort((left, right) => comparer.Compare(keySelector(right), keySelector(left)));
return list;
}
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
public static List<TSource> SortByDescending<TSource, TKey>(this List<TSource> list, Func<TSource, TKey> keySelector, Comparison<TKey> comparison)
{
list.Sort((left, right) => comparison(keySelector(right), keySelector(left)));
return list;
}
}

View File

@@ -0,0 +1,654 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Snap.Hutao.Model.Entity.Database;
#nullable disable
namespace Snap.Hutao.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20240613144942_UserGameRoleProfilePicture")]
partial class UserGameRoleProfilePicture
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
modelBuilder.Entity("Snap.Hutao.Model.Entity.Achievement", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<Guid>("ArchiveId")
.HasColumnType("TEXT");
b.Property<uint>("Current")
.HasColumnType("INTEGER");
b.Property<uint>("Id")
.HasColumnType("INTEGER");
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("Time")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.HasIndex("ArchiveId");
b.ToTable("achievements");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.AchievementArchive", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool>("IsSelected")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("achievement_archives");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.AvatarInfo", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("CalculatorRefreshTime")
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("GameRecordRefreshTime")
.HasColumnType("TEXT");
b.Property<string>("Info")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("ShowcaseRefreshTime")
.HasColumnType("TEXT");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("avatar_infos");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntry", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("Id")
.HasColumnType("INTEGER");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("InnerId");
b.HasIndex("ProjectId");
b.ToTable("cultivate_entries");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntryLevelInformation", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("AvatarLevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("AvatarLevelTo")
.HasColumnType("INTEGER");
b.Property<Guid>("EntryId")
.HasColumnType("TEXT");
b.Property<uint>("SkillALevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("SkillALevelTo")
.HasColumnType("INTEGER");
b.Property<uint>("SkillELevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("SkillELevelTo")
.HasColumnType("INTEGER");
b.Property<uint>("SkillQLevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("SkillQLevelTo")
.HasColumnType("INTEGER");
b.Property<uint>("WeaponLevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("WeaponLevelTo")
.HasColumnType("INTEGER");
b.HasKey("InnerId");
b.HasIndex("EntryId")
.IsUnique();
b.ToTable("cultivate_entry_level_informations");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateItem", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("Count")
.HasColumnType("INTEGER");
b.Property<Guid>("EntryId")
.HasColumnType("TEXT");
b.Property<bool>("IsFinished")
.HasColumnType("INTEGER");
b.Property<uint>("ItemId")
.HasColumnType("INTEGER");
b.HasKey("InnerId");
b.HasIndex("EntryId");
b.ToTable("cultivate_items");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateProject", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("AttachedUid")
.HasColumnType("TEXT");
b.Property<bool>("IsSelected")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("cultivate_projects");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.DailyNoteEntry", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("DailyNote")
.HasColumnType("TEXT");
b.Property<bool>("DailyTaskNotify")
.HasColumnType("INTEGER");
b.Property<bool>("DailyTaskNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<bool>("ExpeditionNotify")
.HasColumnType("INTEGER");
b.Property<bool>("ExpeditionNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<bool>("HomeCoinNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<int>("HomeCoinNotifyThreshold")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("RefreshTime")
.HasColumnType("TEXT");
b.Property<bool>("ResinNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<int>("ResinNotifyThreshold")
.HasColumnType("INTEGER");
b.Property<bool>("TransformerNotify")
.HasColumnType("INTEGER");
b.Property<bool>("TransformerNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.Property<Guid>("UserId")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.HasIndex("UserId");
b.ToTable("daily_notes");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.GachaArchive", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool>("IsSelected")
.HasColumnType("INTEGER");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("gacha_archives");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.GachaItem", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<Guid>("ArchiveId")
.HasColumnType("TEXT");
b.Property<int>("GachaType")
.HasColumnType("INTEGER");
b.Property<long>("Id")
.HasColumnType("INTEGER");
b.Property<uint>("ItemId")
.HasColumnType("INTEGER");
b.Property<int>("QueryType")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("Time")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.HasIndex("ArchiveId");
b.ToTable("gacha_items");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.GameAccount", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("AttachUid")
.HasColumnType("TEXT");
b.Property<int>("Index")
.HasColumnType("INTEGER");
b.Property<string>("MihoyoSDK")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("InnerId");
b.ToTable("game_accounts");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.InventoryItem", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("Count")
.HasColumnType("INTEGER");
b.Property<uint>("ItemId")
.HasColumnType("INTEGER");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.HasIndex("ProjectId");
b.ToTable("inventory_items");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.InventoryReliquary", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("AppendPropIdList")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("ItemId")
.HasColumnType("INTEGER");
b.Property<int>("Level")
.HasColumnType("INTEGER");
b.Property<int>("MainPropId")
.HasColumnType("INTEGER");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.HasIndex("ProjectId");
b.ToTable("inventory_reliquaries");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.InventoryWeapon", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<int>("ItemId")
.HasColumnType("INTEGER");
b.Property<int>("Level")
.HasColumnType("INTEGER");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.Property<int>("PromoteLevel")
.HasColumnType("INTEGER");
b.HasKey("InnerId");
b.HasIndex("ProjectId");
b.ToTable("inventory_weapons");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.ObjectCacheEntry", b =>
{
b.Property<string>("Key")
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("ExpireTime")
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("Key");
b.ToTable("object_cache");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.SettingEntry", b =>
{
b.Property<string>("Key")
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("Key");
b.ToTable("settings");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.SpiralAbyssEntry", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("ScheduleId")
.HasColumnType("INTEGER");
b.Property<string>("SpiralAbyss")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("spiral_abysses");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.User", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Aid")
.HasColumnType("TEXT");
b.Property<string>("CookieToken")
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("CookieTokenLastUpdateTime")
.HasColumnType("TEXT");
b.Property<string>("Fingerprint")
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("FingerprintLastUpdateTime")
.HasColumnType("TEXT");
b.Property<int>("Index")
.HasColumnType("INTEGER");
b.Property<bool>("IsOversea")
.HasColumnType("INTEGER");
b.Property<bool>("IsSelected")
.HasColumnType("INTEGER");
b.Property<string>("LToken")
.HasColumnType("TEXT")
.HasColumnName("Ltoken");
b.Property<string>("Mid")
.HasColumnType("TEXT");
b.Property<string>("PreferredUid")
.HasColumnType("TEXT");
b.Property<string>("SToken")
.HasColumnType("TEXT")
.HasColumnName("Stoken");
b.HasKey("InnerId");
b.ToTable("users");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.UserGameRoleProfilePicture", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("AvatarId")
.HasColumnType("INTEGER");
b.Property<uint>("CostumeId")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("LastUpdateTime")
.HasColumnType("TEXT");
b.Property<uint>("ProfilePictureId")
.HasColumnType("INTEGER");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("profile_pictures");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.Achievement", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.AchievementArchive", "Archive")
.WithMany()
.HasForeignKey("ArchiveId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Archive");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntry", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateProject", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntryLevelInformation", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateEntry", "Entry")
.WithOne("LevelInformation")
.HasForeignKey("Snap.Hutao.Model.Entity.CultivateEntryLevelInformation", "EntryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Entry");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateItem", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateEntry", "Entry")
.WithMany()
.HasForeignKey("EntryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Entry");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.DailyNoteEntry", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.GachaItem", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.GachaArchive", "Archive")
.WithMany()
.HasForeignKey("ArchiveId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Archive");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.InventoryItem", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateProject", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.InventoryReliquary", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateProject", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.InventoryWeapon", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateProject", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntry", b =>
{
b.Navigation("LevelInformation");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,38 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Snap.Hutao.Migrations
{
/// <inheritdoc />
public partial class UserGameRoleProfilePicture : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "profile_pictures",
columns: table => new
{
InnerId = table.Column<Guid>(type: "TEXT", nullable: false),
Uid = table.Column<string>(type: "TEXT", nullable: false),
ProfilePictureId = table.Column<uint>(type: "INTEGER", nullable: false),
AvatarId = table.Column<uint>(type: "INTEGER", nullable: false),
CostumeId = table.Column<uint>(type: "INTEGER", nullable: false),
LastUpdateTime = table.Column<DateTimeOffset>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_profile_pictures", x => x.InnerId);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "profile_pictures");
}
}
}

View File

@@ -15,7 +15,7 @@ namespace Snap.Hutao.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
modelBuilder.Entity("Snap.Hutao.Model.Entity.Achievement", b =>
{
@@ -515,6 +515,33 @@ namespace Snap.Hutao.Migrations
b.ToTable("users");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.UserGameRoleProfilePicture", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("AvatarId")
.HasColumnType("INTEGER");
b.Property<uint>("CostumeId")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("LastUpdateTime")
.HasColumnType("TEXT");
b.Property<uint>("ProfilePictureId")
.HasColumnType("INTEGER");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("profile_pictures");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.Achievement", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.AchievementArchive", "Archive")

View File

@@ -65,6 +65,8 @@ internal sealed class AppDbContext : DbContext
public DbSet<SpiralAbyssEntry> SpiralAbysses { get; set; } = default!;
public DbSet<UserGameRoleProfilePicture> UserGameRoleProfilePictures { get; set; } = default!;
public static AppDbContext Create(IServiceProvider serviceProvider, string sqlConnectionString)
{
DbContextOptions<AppDbContext> options = new DbContextOptionsBuilder<AppDbContext>()

View File

@@ -12,7 +12,8 @@ namespace Snap.Hutao.Model.Entity;
/// </summary>
[HighQuality]
[Table("inventory_items")]
internal sealed class InventoryItem : IDbMappingForeignKeyFrom<InventoryItem, uint>
internal sealed class InventoryItem : IDbMappingForeignKeyFrom<InventoryItem, uint>,
IDbMappingForeignKeyFrom<InventoryItem, uint, uint>
{
/// <summary>
/// 内部Id
@@ -56,4 +57,21 @@ internal sealed class InventoryItem : IDbMappingForeignKeyFrom<InventoryItem, ui
ItemId = itemId,
};
}
/// <summary>
/// 构造一个新的个数不为0的物品
/// </summary>
/// <param name="projectId">项目Id</param>
/// <param name="itemId">物品Id</param>
/// <param name="count">物品个数</param>
/// <returns>新的个数不为0的物品</returns>
public static InventoryItem From(in Guid projectId, in uint itemId, in uint count)
{
return new()
{
ProjectId = projectId,
ItemId = itemId,
Count = count,
};
}
}

View File

@@ -0,0 +1,41 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Core.Abstraction;
using Snap.Hutao.Web.Enka.Model;
using Snap.Hutao.Web.Hoyolab;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Snap.Hutao.Model.Entity;
[Table("profile_pictures")]
[SuppressMessage("", "SH002")]
internal sealed class UserGameRoleProfilePicture : IMappingFrom<UserGameRoleProfilePicture, PlayerUid, ProfilePicture>
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid InnerId { get; set; }
public string Uid { get; set; } = default!;
public uint ProfilePictureId { get; set; }
public uint AvatarId { get; set; }
public uint CostumeId { get; set; }
public DateTimeOffset LastUpdateTime { get; set; }
public static UserGameRoleProfilePicture From(PlayerUid uid, ProfilePicture profilePicture)
{
return new()
{
Uid = uid.ToString(),
ProfilePictureId = profilePicture.ProfilePictureId,
AvatarId = profilePicture.AvatarId,
CostumeId = profilePicture.CostumeId,
LastUpdateTime = DateTimeOffset.Now,
};
}
}

View File

@@ -13,7 +13,7 @@ namespace Snap.Hutao.Model.InterChange.GachaLog;
/// UIGF物品
/// </summary>
[HighQuality]
internal sealed class UIGFItem : GachaLogItem, IMappingFrom<UIGFItem, GachaItem, INameQuality>
internal sealed class UIGFItem : GachaLogItem, IMappingFrom<UIGFItem, GachaItem, INameQualityAccess>
{
/// <summary>
/// 额外祈愿映射
@@ -22,7 +22,7 @@ internal sealed class UIGFItem : GachaLogItem, IMappingFrom<UIGFItem, GachaItem,
[JsonEnum(JsonSerializeType.NumberString)]
public GachaType UIGFGachaType { get; set; } = default!;
public static UIGFItem From(GachaItem item, INameQuality nameQuality)
public static UIGFItem From(GachaItem item, INameQualityAccess nameQuality)
{
return new()
{

View File

@@ -0,0 +1,13 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Primitive;
namespace Snap.Hutao.Model.Metadata.Abstraction;
internal interface ICultivationItemsAccess
{
string Name { get; }
List<MaterialId> CultivationItems { get; }
}

View File

@@ -3,7 +3,7 @@
namespace Snap.Hutao.Model.Metadata.Abstraction;
internal interface IItemSource
internal interface IItemConvertible
{
Model.Item ToItem();
}

View File

@@ -9,7 +9,7 @@ namespace Snap.Hutao.Model.Metadata.Abstraction;
/// 物品与星级
/// </summary>
[HighQuality]
internal interface INameQuality
internal interface INameQualityAccess
{
/// <summary>
/// 名称

View File

@@ -9,7 +9,7 @@ namespace Snap.Hutao.Model.Metadata.Abstraction;
/// 指示该类为统计物品的源
/// </summary>
[HighQuality]
internal interface IStatisticsItemSource
internal interface IStatisticsItemConvertible
{
/// <summary>
/// 转换到统计物品

View File

@@ -10,19 +10,9 @@ namespace Snap.Hutao.Model.Metadata.Abstraction;
/// 指示该类为简述统计物品的源
/// </summary>
[HighQuality]
internal interface ISummaryItemSource
internal interface ISummaryItemConvertible
{
/// <summary>
/// 星级
/// </summary>
QualityType Quality { get; }
/// <summary>
/// 转换到简述统计物品
/// </summary>
/// <param name="lastPull">距上个五星</param>
/// <param name="time">时间</param>
/// <param name="isUp">是否为Up物品</param>
/// <returns>简述统计物品</returns>
SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp);
}

View File

@@ -1,99 +0,0 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Calculable;
using Snap.Hutao.Model.Metadata.Abstraction;
using Snap.Hutao.Model.Metadata.Converter;
using Snap.Hutao.Model.Metadata.Item;
using Snap.Hutao.ViewModel.Complex;
using Snap.Hutao.ViewModel.GachaLog;
using Snap.Hutao.ViewModel.Wiki;
namespace Snap.Hutao.Model.Metadata.Avatar;
/// <summary>
/// 角色的接口实现部分
/// </summary>
internal partial class Avatar : IStatisticsItemSource, ISummaryItemSource, IItemSource, INameQuality, ICalculableSource<ICalculableAvatar>
{
/// <summary>
/// [非元数据] 搭配数据
/// TODO:Add View suffix.
/// </summary>
[JsonIgnore]
public AvatarCollocationView? Collocation { get; set; }
/// <summary>
/// [非元数据] 烹饪奖励
/// </summary>
[JsonIgnore]
public CookBonusView? CookBonusView { get; set; }
/// <summary>
/// [非元数据] 养成物品视图
/// </summary>
[JsonIgnore]
public List<Material>? CultivationItemsView { get; set; }
/// <summary>
/// 最大等级
/// </summary>
[SuppressMessage("", "CA1822")]
public uint MaxLevel { get => GetMaxLevel(); }
public static uint GetMaxLevel()
{
return 90U;
}
/// <inheritdoc/>
public ICalculableAvatar ToCalculable()
{
return CalculableAvatar.From(this);
}
/// <summary>
/// 转换为基础物品
/// </summary>
/// <returns>基础物品</returns>
public Model.Item ToItem()
{
return new()
{
Name = Name,
Icon = AvatarIconConverter.IconNameToUri(Icon),
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
Quality = Quality,
};
}
/// <inheritdoc/>
public StatisticsItem ToStatisticsItem(int count)
{
return new()
{
Name = Name,
Icon = AvatarIconConverter.IconNameToUri(Icon),
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
Quality = Quality,
Count = count,
};
}
/// <inheritdoc/>
public SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp)
{
return new()
{
Name = Name,
Icon = AvatarIconConverter.IconNameToUri(Icon),
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
Quality = Quality,
Time = time,
LastPull = lastPull,
IsUp = isUp,
};
}
}

View File

@@ -1,99 +1,118 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Calculable;
using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Metadata.Abstraction;
using Snap.Hutao.Model.Metadata.Converter;
using Snap.Hutao.Model.Metadata.Item;
using Snap.Hutao.Model.Primitive;
using Snap.Hutao.ViewModel.Complex;
using Snap.Hutao.ViewModel.GachaLog;
using Snap.Hutao.ViewModel.Wiki;
namespace Snap.Hutao.Model.Metadata.Avatar;
/// <summary>
/// 角色
/// </summary>
[HighQuality]
internal partial class Avatar
internal partial class Avatar : INameQualityAccess,
IStatisticsItemConvertible,
ISummaryItemConvertible,
IItemConvertible,
ICalculableSource<ICalculableAvatar>,
ICultivationItemsAccess
{
/// <summary>
/// Id
/// </summary>
public AvatarId Id { get; set; }
/// <summary>
/// 突破提升 Id 外键
/// </summary>
public PromoteId PromoteId { get; set; }
/// <summary>
/// 排序号
/// </summary>
public uint Sort { get; set; }
/// <summary>
/// 体型
/// </summary>
public BodyType Body { get; set; } = default!;
/// <summary>
/// 正面图标
/// </summary>
public string Icon { get; set; } = default!;
/// <summary>
/// 侧面图标
/// </summary>
public string SideIcon { get; set; } = default!;
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; } = default!;
/// <summary>
/// 描述
/// </summary>
public string Description { get; set; } = default!;
/// <summary>
/// 角色加入游戏时间
/// </summary>
public DateTimeOffset BeginTime { get; set; }
/// <summary>
/// 星级
/// </summary>
public QualityType Quality { get; set; }
/// <summary>
/// 武器类型
/// </summary>
public WeaponType Weapon { get; set; }
/// <summary>
/// 基础数值
/// </summary>
public AvatarBaseValue BaseValue { get; set; } = default!;
/// <summary>
/// 生长曲线
/// </summary>
public List<TypeValue<FightProperty, GrowCurveType>> GrowCurves { get; set; } = default!;
/// <summary>
/// 技能
/// </summary>
public SkillDepot SkillDepot { get; set; } = default!;
/// <summary>
/// 好感信息/基本信息
/// </summary>
public FetterInfo FetterInfo { get; set; } = default!;
/// <summary>
/// 皮肤
/// </summary>
public List<Costume> Costumes { get; set; } = default!;
/// <summary>
/// 养成物品
/// </summary>
public List<MaterialId> CultivationItems { get; set; } = default!;
[JsonIgnore]
public AvatarCollocationView? CollocationView { get; set; }
[JsonIgnore]
public CookBonusView? CookBonusView { get; set; }
[JsonIgnore]
public List<Material>? CultivationItemsView { get; set; }
[SuppressMessage("", "CA1822")]
public uint MaxLevel { get => GetMaxLevel(); }
public static uint GetMaxLevel()
{
return 90U;
}
public ICalculableAvatar ToCalculable()
{
return CalculableAvatar.From(this);
}
public Model.Item ToItem()
{
return new()
{
Name = Name,
Icon = AvatarIconConverter.IconNameToUri(Icon),
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
Quality = Quality,
};
}
public StatisticsItem ToStatisticsItem(int count)
{
return new()
{
Name = Name,
Icon = AvatarIconConverter.IconNameToUri(Icon),
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
Quality = Quality,
Count = count,
};
}
public SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp)
{
return new()
{
Name = Name,
Icon = AvatarIconConverter.IconNameToUri(Icon),
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
Quality = Quality,
Time = time,
LastPull = lastPull,
IsUp = isUp,
};
}
}

View File

@@ -12,4 +12,8 @@ internal sealed class ProfilePicture
public string Icon { get; set; } = default!;
public string Name { get; set; } = default!;
public AvatarId AvatarId { get; set; }
public CostumeId CostumeId { get; set; }
}

View File

@@ -0,0 +1,29 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Control;
namespace Snap.Hutao.Model.Metadata.Converter;
/// <summary>
/// 玩家头像转换器
/// </summary>
[HighQuality]
internal sealed class AvatarIconCircleConverter : ValueConverter<string, Uri>
{
/// <summary>
/// 名称转Uri
/// </summary>
/// <param name="name">名称</param>
/// <returns>链接</returns>
public static Uri IconNameToUri(string name)
{
return Web.HutaoEndpoints.StaticRaw("AvatarIconCircle", $"{name}.png").ToUri();
}
/// <inheritdoc/>
public override Uri Convert(string from)
{
return IconNameToUri(from);
}
}

View File

@@ -1,107 +0,0 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Calculable;
using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Metadata.Abstraction;
using Snap.Hutao.Model.Metadata.Converter;
using Snap.Hutao.Model.Metadata.Item;
using Snap.Hutao.ViewModel.Complex;
using Snap.Hutao.ViewModel.GachaLog;
namespace Snap.Hutao.Model.Metadata.Weapon;
/// <summary>
/// 武器的接口实现
/// </summary>
internal sealed partial class Weapon : IStatisticsItemSource, ISummaryItemSource, IItemSource, INameQuality, ICalculableSource<ICalculableWeapon>
{
/// <summary>
/// [非元数据] 搭配数据
/// TODO:Add View suffix.
/// </summary>
[JsonIgnore]
public WeaponCollocationView? Collocation { get; set; }
/// <summary>
/// [非元数据] 养成物品视图
/// </summary>
[JsonIgnore]
public List<Material>? CultivationItemsView { get; set; }
/// <inheritdoc cref="INameQuality.Quality" />
[JsonIgnore]
public QualityType Quality
{
get => RankLevel;
}
/// <summary>
/// 最大等级
/// </summary>
internal uint MaxLevel { get => GetMaxLevelByQuality(Quality); }
public static uint GetMaxLevelByQuality(QualityType quality)
{
return quality >= QualityType.QUALITY_BLUE ? 90U : 70U;
}
/// <inheritdoc/>
public ICalculableWeapon ToCalculable()
{
return CalculableWeapon.From(this);
}
/// <summary>
/// 转换为基础物品
/// </summary>
/// <returns>基础物品</returns>
public Model.Item ToItem()
{
return new()
{
Name = Name,
Icon = EquipIconConverter.IconNameToUri(Icon),
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
Quality = RankLevel,
};
}
/// <summary>
/// 转换到统计物品
/// </summary>
/// <param name="count">个数</param>
/// <returns>统计物品</returns>
public StatisticsItem ToStatisticsItem(int count)
{
return new()
{
Name = Name,
Icon = EquipIconConverter.IconNameToUri(Icon),
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
Quality = RankLevel,
Count = count,
};
}
/// <summary>
/// 转换到简述统计物品
/// </summary>
/// <param name="lastPull">距上个五星</param>
/// <param name="time">时间</param>
/// <param name="isUp">是否为Up物品</param>
/// <returns>简述统计物品</returns>
public SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp)
{
return new()
{
Name = Name,
Icon = EquipIconConverter.IconNameToUri(Icon),
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
Time = time,
Quality = RankLevel,
LastPull = lastPull,
IsUp = isUp,
};
}
}

View File

@@ -1,69 +1,107 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Calculable;
using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Metadata.Abstraction;
using Snap.Hutao.Model.Metadata.Converter;
using Snap.Hutao.Model.Metadata.Item;
using Snap.Hutao.Model.Primitive;
using Snap.Hutao.ViewModel.Complex;
using Snap.Hutao.ViewModel.GachaLog;
namespace Snap.Hutao.Model.Metadata.Weapon;
/// <summary>
/// 武器
/// </summary>
[HighQuality]
internal sealed partial class Weapon
internal sealed partial class Weapon : INameQualityAccess,
IStatisticsItemConvertible,
ISummaryItemConvertible,
IItemConvertible,
ICalculableSource<ICalculableWeapon>,
ICultivationItemsAccess
{
/// <summary>
/// Id
/// </summary>
public WeaponId Id { get; set; }
/// <summary>
/// 突破 Id
/// </summary>
public PromoteId PromoteId { get; set; }
/// <summary>
/// 武器类型
/// </summary>
public uint Sort { get; set; }
public WeaponType WeaponType { get; set; }
/// <summary>
/// 等级
/// </summary>
public QualityType RankLevel { get; set; }
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; } = default!;
/// <summary>
/// 描述
/// </summary>
public string Description { get; set; } = default!;
/// <summary>
/// 图标
/// </summary>
public string Icon { get; set; } = default!;
/// <summary>
/// 觉醒图标
/// </summary>
public string AwakenIcon { get; set; } = default!;
/// <summary>
/// 生长曲线
/// </summary>
public List<WeaponTypeValue> GrowCurves { get; set; } = default!;
/// <summary>
/// 被动信息, 无被动的武器为 <see langword="null"/>
/// </summary>
public NameDescriptions? Affix { get; set; } = default!;
/// <summary>
/// 养成物品
/// </summary>
public List<MaterialId> CultivationItems { get; set; } = default!;
[JsonIgnore]
public WeaponCollocationView? CollocationView { get; set; }
[JsonIgnore]
public List<Material>? CultivationItemsView { get; set; }
[JsonIgnore]
public QualityType Quality
{
get => RankLevel;
}
internal uint MaxLevel { get => GetMaxLevelByQuality(Quality); }
public static uint GetMaxLevelByQuality(QualityType quality)
{
return quality >= QualityType.QUALITY_BLUE ? 90U : 70U;
}
public ICalculableWeapon ToCalculable()
{
return CalculableWeapon.From(this);
}
public Model.Item ToItem()
{
return new()
{
Name = Name,
Icon = EquipIconConverter.IconNameToUri(Icon),
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
Quality = RankLevel,
};
}
public StatisticsItem ToStatisticsItem(int count)
{
return new()
{
Name = Name,
Icon = EquipIconConverter.IconNameToUri(Icon),
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
Quality = RankLevel,
Count = count,
};
}
public SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp)
{
return new()
{
Name = Name,
Icon = EquipIconConverter.IconNameToUri(Icon),
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
Time = time,
Quality = RankLevel,
LastPull = lastPull,
IsUp = isUp,
};
}
}

View File

@@ -552,10 +552,10 @@
<value>精炼 {0} 阶</value>
</data>
<data name="MustSelectUserAndUid" xml:space="preserve">
<value>必须登录 米游社/HoYoLAB 并选择一个用户与角色</value>
<value>必须登录 米游社 / HoYoLAB 并选择一个用户与角色</value>
</data>
<data name="ServerGachaLogServiceDeleteEntrySucceed" xml:space="preserve">
<value>删除了 Uid{0} 的 {1} 条祈愿记录</value>
<value>删除了 UID{0} 的 {1} 条祈愿记录</value>
</data>
<data name="ServerGachaLogServiceInsufficientRecordSlot" xml:space="preserve">
<value>胡桃云保存的祈愿记录存档数已达当前账号上限</value>
@@ -570,7 +570,7 @@
<value>数据异常,无法保存至云端,请勿跨账号上传或尝试删除云端数据后重试</value>
</data>
<data name="ServerGachaLogServiceUploadEntrySucceed" xml:space="preserve">
<value>上传了 Uid{0} 的 {1} 条祈愿记录,存储了 {2} 条</value>
<value>上传了 UID{0} 的 {1} 条祈愿记录,存储了 {2} 条</value>
</data>
<data name="ServerPassportLoginRequired" xml:space="preserve">
<value>请先登录或注册胡桃账号</value>
@@ -621,7 +621,7 @@
<value>验证请求过快,请 1 分钟后再试</value>
</data>
<data name="ServerRecordBannedUid" xml:space="preserve">
<value>上传深渊记录失败,当前 Uid 已被胡桃数据库封禁</value>
<value>上传深渊记录失败,当前 UID 已被胡桃数据库封禁</value>
</data>
<data name="ServerRecordComputingStatistics" xml:space="preserve">
<value>上传深渊记录失败,正在计算统计数据</value>
@@ -636,13 +636,13 @@
<value>上传深渊记录失败,存在无效的数据</value>
</data>
<data name="ServerRecordInvalidUid" xml:space="preserve">
<value>无效的 Uid</value>
<value>无效的 UID</value>
</data>
<data name="ServerRecordNotCurrentSchedule" xml:space="preserve">
<value>上传深渊记录失败,不是本期数据</value>
</data>
<data name="ServerRecordPreviousRequestNotCompleted" xml:space="preserve">
<value>上传深渊记录失败,当前 Uid 的记录仍在处理中,请勿重复操作</value>
<value>上传深渊记录失败,当前 UID 的记录仍在处理中,请勿重复操作</value>
</data>
<data name="ServerRecordUploadSuccessAndGachaLogServiceTimeExtended" xml:space="preserve">
<value>上传深渊记录成功,获赠祈愿记录上传服务时长</value>
@@ -1545,10 +1545,10 @@
<value>养成计划添加失败</value>
</data>
<data name="ViewModelCultivationBatchAddCompletedFormat" xml:space="preserve">
<value>操作完成:添加/更新:{0} 个,跳过 {1} 个</value>
<value>操作完成:添加 / 更新:{0} 个,跳过 {1} 个</value>
</data>
<data name="ViewModelCultivationBatchAddIncompletedFormat" xml:space="preserve">
<value>操作未全部完成:添加/更新:{0} 个,跳过 {1} 个</value>
<value>操作未全部完成:添加 / 更新:{0} 个,跳过 {1} 个</value>
</data>
<data name="ViewModelCultivationEntryAddSuccess" xml:space="preserve">
<value>已成功添加至当前养成计划</value>
@@ -1568,6 +1568,9 @@
<data name="ViewModelCultivationProjectInvalidName" xml:space="preserve">
<value>不能添加名称无效的计划</value>
</data>
<data name="ViewModelCultivationRefreshInventoryProgress" xml:space="preserve">
<value>正在同步背包物品</value>
</data>
<data name="ViewModelCultivationRemoveProjectContent" xml:space="preserve">
<value>此操作不可逆,此计划的养成物品与背包材料将会丢失</value>
</data>
@@ -1925,6 +1928,9 @@
<data name="ViewPageCultivationNavigateAction" xml:space="preserve">
<value>前往</value>
</data>
<data name="ViewPageCultivationRefreshInventory" xml:space="preserve">
<value>同步背包物品</value>
</data>
<data name="ViewPageCultivationRemoveEntry" xml:space="preserve">
<value>删除清单</value>
</data>
@@ -2067,10 +2073,10 @@
<value>前往爱发电购买相关服务</value>
</data>
<data name="ViewPageGachaLogHutaoCloudAfdianPurchaseHeader" xml:space="preserve">
<value>购买/续费云服务</value>
<value>购买 / 续费云服务</value>
</data>
<data name="ViewPageGachaLogHutaoCloudDelete" xml:space="preserve">
<value>删除此 Uid 的云端存档</value>
<value>删除此 UID 的云端存档</value>
</data>
<data name="ViewPageGachaLogHutaoCloudDeveloperHint" xml:space="preserve">
<value>开发者账号无视服务到期时间</value>
@@ -2079,7 +2085,7 @@
<value>胡桃云服务时长不足</value>
</data>
<data name="ViewPageGachaLogHutaoCloudRetrieve" xml:space="preserve">
<value>下载此 Uid 的云端存档</value>
<value>下载此 UID 的云端存档</value>
</data>
<data name="ViewPageGachaLogHutaoCloudSpiralAbyssActivityDescription" xml:space="preserve">
<value>每期深渊首次上传可免费获得 3 天时长</value>
@@ -2406,7 +2412,7 @@
<value>重命名</value>
</data>
<data name="ViewPageLaunchGameSwitchSchemeDescription" xml:space="preserve">
<value>切换游戏服务器(国服/渠道服/国际服)</value>
<value>切换游戏服务器(国服 / 渠道服 / 国际服)</value>
</data>
<data name="ViewPageLaunchGameSwitchSchemeHeader" xml:space="preserve">
<value>服务器</value>
@@ -2415,7 +2421,7 @@
<value>版本更新前需要提前转换至与启动器匹配的服务器</value>
</data>
<data name="ViewPageLaunchGameUnlockFpsDescription" xml:space="preserve">
<value>请在游戏内关闭垂直同步选项,需要高性能的显卡以支持更高的帧率</value>
<value>请在游戏内关闭垂直同步选项,需要高性能的显卡以支持更高的帧率</value>
</data>
<data name="ViewPageLaunchGameUnlockFpsHeader" xml:space="preserve">
<value>解锁帧率限制</value>
@@ -2433,7 +2439,7 @@
<value>Windows HDR</value>
</data>
<data name="ViewPageLoginHoyoverseUserHint" xml:space="preserve">
<value>请输入你的 HoYoLab Uid</value>
<value>请输入你的 HoYoLab UID</value>
</data>
<data name="ViewPageLoginMihoyoUserDescription" xml:space="preserve">
<value>你正在通过由我们提供的内嵌网页视图登录 米哈游通行证,我们会在你点击 我已登录 按钮后,读取你的 Cookie 信息,由此视图发起的网络通信只发生于你的计算机与米哈游服务器之间</value>
@@ -2511,7 +2517,7 @@
<value>除非开发人员明确要求你这么做,否则不应尝试执行下方的操作!</value>
</data>
<data name="ViewPageSettingDataFolderDescription" xml:space="preserve">
<value>用户数据/元数据 在此处存放</value>
<value>用户数据 / 元数据 在此处存放</value>
</data>
<data name="ViewPageSettingDataFolderHeader" xml:space="preserve">
<value>数据 文件夹</value>
@@ -2589,7 +2595,7 @@
<value>选择想要获取公告的游戏服务器</value>
</data>
<data name="ViewPageSettingHomeAnnouncementRegionHeader" xml:space="preserve">
<value>公告所属服务器</value>
<value>游戏公告所属服务器</value>
</data>
<data name="ViewpageSettingHomeCardDescription" xml:space="preserve">
<value>管理主页仪表板中的卡片</value>
@@ -2646,7 +2652,7 @@
<value>您可以无限制的使用任何测试功能</value>
</data>
<data name="ViewPageSettingHutaoPassportMaintainerHeader" xml:space="preserve">
<value>胡桃开发/运维</value>
<value>胡桃开发 / 运维</value>
</data>
<data name="ViewPageSettingHutaoPassportRedeemCodeDescription" xml:space="preserve">
<value>我们有时会向某些用户赠送胡桃云兑换码</value>
@@ -2703,7 +2709,7 @@
<value>重置图片资源</value>
</data>
<data name="ViewPageSettingsAdvancedOptionsLaunchUnlockFpsDescription" xml:space="preserve">
<value>在启动游戏页面的进程部分加入解锁帧率限制选项</value>
<value>在启动游戏-进程」选项卡加入解锁帧率限制选项</value>
</data>
<data name="ViewPageSettingsAdvancedOptionsLaunchUnlockFpsHeader" xml:space="preserve">
<value>启动游戏-解锁帧率限制</value>
@@ -2751,7 +2757,7 @@
<value>贡献翻译</value>
</data>
<data name="ViewPageSettingUnobtainedWishItemVisibleDescription" xml:space="preserve">
<value>在祈愿记录页面角色与武器页签显示未抽取到的祈愿物品</value>
<value>在祈愿记录-角色」与「祈愿记录-武器」中显示未抽取到的祈愿物品</value>
</data>
<data name="ViewPageSettingUnobtainedWishItemVisibleHeader" xml:space="preserve">
<value>未抽取到的祈愿物品</value>

View File

@@ -20,7 +20,7 @@ namespace Snap.Hutao.Service;
[Injection(InjectAs.Scoped, typeof(IAnnouncementService))]
internal sealed partial class AnnouncementService : IAnnouncementService
{
private static readonly string CacheKey = $"{nameof(AnnouncementService)}.Cache.{nameof(AnnouncementWrapper)}";
private const string CacheKey = $"{nameof(AnnouncementService)}.Cache.{nameof(AnnouncementWrapper)}";
private readonly IServiceScopeFactory serviceScopeFactory;
private readonly ITaskContext taskContext;

View File

@@ -16,16 +16,6 @@ internal sealed partial class CultivationDbService : ICultivationDbService
public IServiceProvider ServiceProvider { get => serviceProvider; }
public List<InventoryItem> GetInventoryItemListByProjectId(Guid projectId)
{
return this.List<InventoryItem>(i => i.ProjectId == projectId);
}
public ValueTask<List<InventoryItem>> GetInventoryItemListByProjectIdAsync(Guid projectId, CancellationToken token = default)
{
return this.ListAsync<InventoryItem>(i => i.ProjectId == projectId, token);
}
public ValueTask<List<CultivateEntry>> GetCultivateEntryListByProjectIdAsync(Guid projectId, CancellationToken token = default)
{
return this.ListAsync<CultivateEntry>(e => e.ProjectId == projectId, token);

View File

@@ -2,15 +2,14 @@
// Licensed under the MIT license.
using Snap.Hutao.Core.Database;
using Snap.Hutao.Model;
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Model.Entity.Primitive;
using Snap.Hutao.Model.Metadata.Item;
using Snap.Hutao.Service.Inventory;
using Snap.Hutao.Service.Metadata.ContextAbstraction;
using Snap.Hutao.ViewModel.Cultivation;
using System.Collections.ObjectModel;
using CalculateItem = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Item;
using ModelItem = Snap.Hutao.Model.Item;
namespace Snap.Hutao.Service.Cultivation;
@@ -51,22 +50,6 @@ internal sealed partial class CultivationService : ICultivationService
}
}
/// <inheritdoc/>
public List<InventoryItemView> GetInventoryItemViews(CultivateProject cultivateProject, ICultivationMetadataContext context, ICommand saveCommand)
{
Guid projectId = cultivateProject.InnerId;
List<InventoryItem> entities = cultivationDbService.GetInventoryItemListByProjectId(projectId);
List<InventoryItemView> results = [];
foreach (Material meta in context.EnumerateInventoryMaterial())
{
InventoryItem entity = entities.SingleOrDefault(e => e.ItemId == meta.Id) ?? InventoryItem.From(projectId, meta.Id);
results.Add(new(entity, meta, saveCommand));
}
return results;
}
/// <inheritdoc/>
public async ValueTask<ObservableCollection<CultivateEntryView>> GetCultivateEntriesAsync(CultivateProject cultivateProject, ICultivationMetadataContext context)
{
@@ -86,7 +69,7 @@ internal sealed partial class CultivationService : ICultivationService
entryItems.Add(new(cultivateItem, context.GetMaterial(cultivateItem.ItemId)));
}
Item item = entry.Type switch
ModelItem item = entry.Type switch
{
CultivateType.AvatarAndSkill => context.GetAvatar(entry.Id).ToItem(),
CultivateType.Weapon => context.GetWeapon(entry.Id).ToItem(),
@@ -130,7 +113,7 @@ internal sealed partial class CultivationService : ICultivationService
}
}
foreach (InventoryItem inventoryItem in await cultivationDbService.GetInventoryItemListByProjectIdAsync(projectId, token).ConfigureAwait(false))
foreach (InventoryItem inventoryItem in await inventoryDbService.GetInventoryItemListByProjectIdAsync(projectId, token).ConfigureAwait(false))
{
if (resultItems.SingleOrDefault(i => i.Inner.Id == inventoryItem.ItemId) is { } existedItem)
{
@@ -147,12 +130,6 @@ internal sealed partial class CultivationService : ICultivationService
await cultivationDbService.RemoveCultivateEntryByIdAsync(entryId).ConfigureAwait(false);
}
/// <inheritdoc/>
public void SaveInventoryItem(InventoryItemView item)
{
inventoryDbService.UpdateInventoryItem(item.Entity);
}
/// <inheritdoc/>
public void SaveCultivateItem(CultivateItemView item)
{

View File

@@ -7,8 +7,7 @@ using System.Collections.ObjectModel;
namespace Snap.Hutao.Service.Cultivation;
internal interface ICultivationDbService : IAppDbService<InventoryItem>,
IAppDbService<CultivateEntryLevelInformation>,
internal interface ICultivationDbService : IAppDbService<CultivateEntryLevelInformation>,
IAppDbService<CultivateProject>,
IAppDbService<CultivateEntry>,
IAppDbService<CultivateItem>
@@ -29,10 +28,6 @@ internal interface ICultivationDbService : IAppDbService<InventoryItem>,
ObservableCollection<CultivateProject> GetCultivateProjectCollection();
List<InventoryItem> GetInventoryItemListByProjectId(Guid projectId);
ValueTask<List<InventoryItem>> GetInventoryItemListByProjectIdAsync(Guid projectId, CancellationToken token = default);
ValueTask AddCultivateEntryAsync(CultivateEntry entry, CancellationToken token = default);
ValueTask AddCultivateItemRangeAsync(IEnumerable<CultivateItem> toAdd, CancellationToken token = default);

View File

@@ -27,8 +27,6 @@ internal interface ICultivationService
ValueTask<ObservableCollection<CultivateEntryView>> GetCultivateEntriesAsync(CultivateProject cultivateProject, ICultivationMetadataContext context);
List<InventoryItemView> GetInventoryItemViews(CultivateProject cultivateProject, ICultivationMetadataContext context, ICommand saveCommand);
ValueTask<ObservableCollection<StatisticsCultivateItem>> GetStatisticsCultivateItemCollectionAsync(
CultivateProject cultivateProject, ICultivationMetadataContext context, CancellationToken token);
@@ -54,12 +52,6 @@ internal interface ICultivationService
/// <param name="item">养成物品</param>
void SaveCultivateItem(CultivateItemView item);
/// <summary>
/// 保存单个物品
/// </summary>
/// <param name="item">物品</param>
void SaveInventoryItem(InventoryItemView item);
/// <summary>
/// 异步尝试添加新的项目
/// </summary>

View File

@@ -48,7 +48,7 @@ internal sealed partial class DailyNoteOptions : DbStoreOptions
{
quartzService.UpdateJobAsync(JobIdentity.DailyNoteGroupName, JobIdentity.DailyNoteRefreshTriggerName, builder =>
{
return builder.WithSimpleSchedule(sb => sb.WithIntervalInMinutes(SelectedRefreshTime.Value).RepeatForever());
return builder.WithSimpleSchedule(sb => sb.WithIntervalInSeconds(SelectedRefreshTime.Value).RepeatForever());
}).SafeForget();
}
}

View File

@@ -49,7 +49,7 @@ internal static class GachaStatisticsExtension
/// <param name="dict">计数器</param>
/// <returns>统计物品列表</returns>
public static List<StatisticsItem> ToStatisticsList<TItem>(this Dictionary<TItem, int> dict)
where TItem : IStatisticsItemSource
where TItem : IStatisticsItemConvertible
{
IOrderedEnumerable<StatisticsItem> result = dict
.Select(kvp => kvp.Key.ToStatisticsItem(kvp.Value))

View File

@@ -27,7 +27,7 @@ internal sealed partial class GachaStatisticsSlimFactory : IGachaStatisticsSlimF
return CreateCore(context, items, uid);
}
private static void Track(INameQuality nameQuality, ref int orangeTracker, ref int purpleTracker)
private static void Track(INameQualityAccess nameQuality, ref int orangeTracker, ref int purpleTracker)
{
switch (nameQuality.Quality)
{
@@ -69,7 +69,7 @@ internal sealed partial class GachaStatisticsSlimFactory : IGachaStatisticsSlimF
// O(n) operation
foreach (ref readonly GachaItem item in CollectionsMarshal.AsSpan(items))
{
INameQuality nameQuality = context.GetNameQualityByItemId(item.ItemId);
INameQualityAccess nameQuality = context.GetNameQualityByItemId(item.ItemId);
switch (item.QueryType)
{
case GachaType.Standard:

View File

@@ -16,11 +16,11 @@ internal sealed class HistoryWishBuilder
{
private readonly GachaEvent gachaEvent;
private readonly Dictionary<IStatisticsItemSource, int> orangeUpCounter = [];
private readonly Dictionary<IStatisticsItemSource, int> purpleUpCounter = [];
private readonly Dictionary<IStatisticsItemSource, int> orangeCounter = [];
private readonly Dictionary<IStatisticsItemSource, int> purpleCounter = [];
private readonly Dictionary<IStatisticsItemSource, int> blueCounter = [];
private readonly Dictionary<IStatisticsItemConvertible, int> orangeUpCounter = [];
private readonly Dictionary<IStatisticsItemConvertible, int> purpleUpCounter = [];
private readonly Dictionary<IStatisticsItemConvertible, int> orangeCounter = [];
private readonly Dictionary<IStatisticsItemConvertible, int> purpleCounter = [];
private readonly Dictionary<IStatisticsItemConvertible, int> blueCounter = [];
private int totalCountTracker;
@@ -37,18 +37,18 @@ internal sealed class HistoryWishBuilder
switch (ConfigType)
{
case GachaType.ActivityAvatar or GachaType.SpecialActivityAvatar:
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => context.IdAvatarMap[id]).ToDictionary(a => (IStatisticsItemSource)a, a => 0);
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => context.IdAvatarMap[id]).ToDictionary(a => (IStatisticsItemSource)a, a => 0);
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => context.IdAvatarMap[id]).ToDictionary(a => (IStatisticsItemConvertible)a, a => 0);
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => context.IdAvatarMap[id]).ToDictionary(a => (IStatisticsItemConvertible)a, a => 0);
break;
case GachaType.ActivityWeapon:
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => context.IdWeaponMap[id]).ToDictionary(w => (IStatisticsItemSource)w, w => 0);
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => context.IdWeaponMap[id]).ToDictionary(w => (IStatisticsItemSource)w, w => 0);
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => context.IdWeaponMap[id]).ToDictionary(w => (IStatisticsItemConvertible)w, w => 0);
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => context.IdWeaponMap[id]).ToDictionary(w => (IStatisticsItemConvertible)w, w => 0);
break;
case GachaType.ActivityCity:
// Avatars are less than weapons, so we try to get the value from avatar map first
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => (IStatisticsItemSource?)context.IdAvatarMap.GetValueOrDefault(id) ?? context.IdWeaponMap[id]).ToDictionary(c => c, c => 0);
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => (IStatisticsItemSource?)context.IdAvatarMap.GetValueOrDefault(id) ?? context.IdWeaponMap[id]).ToDictionary(c => c, c => 0);
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => (IStatisticsItemConvertible?)context.IdAvatarMap.GetValueOrDefault(id) ?? context.IdWeaponMap[id]).ToDictionary(c => c, c => 0);
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => (IStatisticsItemConvertible?)context.IdAvatarMap.GetValueOrDefault(id) ?? context.IdWeaponMap[id]).ToDictionary(c => c, c => 0);
break;
}
}
@@ -74,7 +74,7 @@ internal sealed class HistoryWishBuilder
/// </summary>
/// <param name="item">物品</param>
/// <returns>是否为Up物品</returns>
public bool IncreaseOrange(IStatisticsItemSource item)
public bool IncreaseOrange(IStatisticsItemConvertible item)
{
orangeCounter.IncreaseOne(item);
++totalCountTracker;
@@ -86,7 +86,7 @@ internal sealed class HistoryWishBuilder
/// 计数四星物品
/// </summary>
/// <param name="item">物品</param>
public void IncreasePurple(IStatisticsItemSource item)
public void IncreasePurple(IStatisticsItemConvertible item)
{
purpleUpCounter.TryIncreaseOne(item);
purpleCounter.IncreaseOne(item);
@@ -97,7 +97,7 @@ internal sealed class HistoryWishBuilder
/// 计数三星武器
/// </summary>
/// <param name="item">武器</param>
public void IncreaseBlue(IStatisticsItemSource item)
public void IncreaseBlue(IStatisticsItemConvertible item)
{
blueCounter.IncreaseOne(item);
++totalCountTracker;

View File

@@ -55,7 +55,7 @@ internal sealed class HutaoStatisticsFactory
foreach (ref readonly ItemCount item in CollectionsMarshal.AsSpan(items))
{
IStatisticsItemSource source = item.Item.StringLength() switch
IStatisticsItemConvertible source = item.Item.StringLength() switch
{
8U => context.GetAvatar(item.Item),
5U => context.GetWeapon(item.Item),

View File

@@ -44,7 +44,7 @@ internal sealed class TypedWishSummaryBuilder
/// <param name="item">祈愿物品</param>
/// <param name="source">对应武器</param>
/// <param name="isUp">是否为Up物品</param>
public void Track(GachaItem item, ISummaryItemSource source, bool isUp)
public void Track(GachaItem item, ISummaryItemConvertible source, bool isUp)
{
if (!context.TypeEvaluator(item.GachaType))
{

View File

@@ -59,7 +59,7 @@ internal sealed class GachaLogServiceMetadataContext : IMetadataContext,
return result;
}
public INameQuality GetNameQualityByItemId(uint id)
public INameQualityAccess GetNameQualityByItemId(uint id)
{
uint place = id.StringLength();
return place switch

View File

@@ -3,7 +3,6 @@
using Snap.Hutao.Core.ExceptionService;
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.Memory;
using System.Diagnostics;
using static Snap.Hutao.Win32.Kernel32;

View File

@@ -15,30 +15,35 @@ internal readonly struct RequiredLocalModule : IDisposable
public readonly Module UnityPlayer;
public readonly Module UserAssembly;
private readonly HMODULE hModuleUnityPlayer;
private readonly HMODULE hModuleUserAssembly;
[SuppressMessage("", "SH002")]
public RequiredLocalModule(HMODULE unityPlayer, HMODULE userAssembly)
{
hModuleUnityPlayer = unityPlayer;
hModuleUserAssembly = userAssembly;
// Align the pointer
unityPlayer = (nint)(unityPlayer & ~0x3L);
userAssembly = (nint)(userAssembly & ~0x3L);
nint unityPlayerMappedView = (nint)(unityPlayer & ~0x3L);
nint userAssemblyMappedView = (nint)(userAssembly & ~0x3L);
HasValue = true;
UnityPlayer = new((nuint)(nint)unityPlayer, GetImageSize(unityPlayer));
UserAssembly = new((nuint)(nint)userAssembly, GetImageSize(userAssembly));
UnityPlayer = new((nuint)unityPlayerMappedView, GetImageSize(unityPlayerMappedView));
UserAssembly = new((nuint)userAssemblyMappedView, GetImageSize(userAssemblyMappedView));
}
public void Dispose()
{
FreeLibrary((nint)UnityPlayer.Address);
FreeLibrary((nint)UserAssembly.Address);
FreeLibrary(hModuleUnityPlayer);
FreeLibrary(hModuleUserAssembly);
}
[SuppressMessage("", "SH002")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe uint GetImageSize(HMODULE hModule)
private unsafe uint GetImageSize(nint baseAddress)
{
IMAGE_DOS_HEADER* pImageDosHeader = (IMAGE_DOS_HEADER*)(nint)hModule;
IMAGE_NT_HEADERS64* pImageNtHeader = (IMAGE_NT_HEADERS64*)(pImageDosHeader->e_lfanew + hModule);
IMAGE_DOS_HEADER* pImageDosHeader = (IMAGE_DOS_HEADER*)baseAddress;
IMAGE_NT_HEADERS64* pImageNtHeader = (IMAGE_NT_HEADERS64*)(pImageDosHeader->e_lfanew + baseAddress);
return pImageNtHeader->OptionalHeader.SizeOfImage;
}
}

View File

@@ -2,16 +2,21 @@
// Licensed under the MIT license.
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Service.Abstraction;
namespace Snap.Hutao.Service.Inventory;
internal interface IInventoryDbService
internal interface IInventoryDbService : IAppDbService<InventoryItem>
{
ValueTask AddInventoryItemRangeByProjectId(List<InventoryItem> items);
ValueTask AddInventoryItemRangeByProjectIdAsync(List<InventoryItem> items, CancellationToken token = default);
ValueTask RemoveInventoryItemRangeByProjectId(Guid projectId);
ValueTask RemoveInventoryItemRangeByProjectIdAsync(Guid projectId, CancellationToken token = default);
void UpdateInventoryItem(InventoryItem item);
ValueTask UpdateInventoryItemAsync(InventoryItem item);
ValueTask UpdateInventoryItemAsync(InventoryItem item, CancellationToken token = default);
List<InventoryItem> GetInventoryItemListByProjectId(Guid projectId);
ValueTask<List<InventoryItem>> GetInventoryItemListByProjectIdAsync(Guid projectId, CancellationToken token = default);
}

View File

@@ -1,8 +1,17 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Service.Cultivation;
using Snap.Hutao.ViewModel.Cultivation;
namespace Snap.Hutao.Service.Inventory;
internal interface IInventoryService
{
List<InventoryItemView> GetInventoryItemViews(CultivateProject cultivateProject, ICultivationMetadataContext context, ICommand saveCommand);
void SaveInventoryItem(InventoryItemView item);
ValueTask RefreshInventoryAsync(CultivateProject project);
}

View File

@@ -1,10 +1,8 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.EntityFrameworkCore;
using Snap.Hutao.Core.Database;
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Model.Entity.Database;
using Snap.Hutao.Service.Abstraction;
namespace Snap.Hutao.Service.Inventory;
@@ -14,43 +12,35 @@ internal sealed partial class InventoryDbService : IInventoryDbService
{
private readonly IServiceProvider serviceProvider;
public async ValueTask RemoveInventoryItemRangeByProjectId(Guid projectId)
public IServiceProvider ServiceProvider { get => serviceProvider; }
public async ValueTask RemoveInventoryItemRangeByProjectIdAsync(Guid projectId, CancellationToken token = default)
{
using (IServiceScope scope = serviceProvider.CreateScope())
{
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
await appDbContext.InventoryItems
.AsNoTracking()
.Where(a => a.ProjectId == projectId && a.ItemId != 202U) // 摩拉
.ExecuteDeleteAsync()
.ConfigureAwait(false);
}
await this.DeleteAsync(i => i.ProjectId == projectId, token).ConfigureAwait(false);
}
public async ValueTask AddInventoryItemRangeByProjectId(List<InventoryItem> items)
public async ValueTask AddInventoryItemRangeByProjectIdAsync(List<InventoryItem> items, CancellationToken token = default)
{
using (IServiceScope scope = serviceProvider.CreateScope())
{
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
await appDbContext.InventoryItems.AddRangeAndSaveAsync(items).ConfigureAwait(false);
}
await this.AddRangeAsync(items, token).ConfigureAwait(false);
}
public void UpdateInventoryItem(InventoryItem item)
{
using (IServiceScope scope = serviceProvider.CreateScope())
{
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
appDbContext.InventoryItems.UpdateAndSave(item);
}
this.Update(item);
}
public async ValueTask UpdateInventoryItemAsync(InventoryItem item)
public async ValueTask UpdateInventoryItemAsync(InventoryItem item, CancellationToken token = default)
{
using (IServiceScope scope = serviceProvider.CreateScope())
{
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
await appDbContext.InventoryItems.UpdateAndSaveAsync(item).ConfigureAwait(false);
}
await this.UpdateAsync(item, token).ConfigureAwait(false);
}
public List<InventoryItem> GetInventoryItemListByProjectId(Guid projectId)
{
return this.List(i => i.ProjectId == projectId);
}
public ValueTask<List<InventoryItem>> GetInventoryItemListByProjectIdAsync(Guid projectId, CancellationToken token = default)
{
return this.ListAsync(i => i.ProjectId == projectId, token);
}
}

View File

@@ -1,9 +1,83 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Model.Metadata.Item;
using Snap.Hutao.Service.Cultivation;
using Snap.Hutao.Service.Metadata.ContextAbstraction;
using Snap.Hutao.Service.Notification;
using Snap.Hutao.Service.User;
using Snap.Hutao.ViewModel.Cultivation;
using Snap.Hutao.ViewModel.User;
using Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
using Snap.Hutao.Web.Response;
namespace Snap.Hutao.Service.Inventory;
[Injection(InjectAs.Transient)]
internal sealed class InventoryService : IInventoryService
[ConstructorGenerated]
[Injection(InjectAs.Singleton, typeof(IInventoryService))]
internal sealed partial class InventoryService : IInventoryService
{
private readonly MinimalPromotionDelta minimalPromotionDelta;
private readonly IServiceScopeFactory serviceScopeFactory;
private readonly IInventoryDbService inventoryDbService;
private readonly IInfoBarService infoBarService;
private readonly IUserService userService;
/// <inheritdoc/>
public List<InventoryItemView> GetInventoryItemViews(CultivateProject cultivateProject, ICultivationMetadataContext context, ICommand saveCommand)
{
Guid projectId = cultivateProject.InnerId;
List<InventoryItem> entities = inventoryDbService.GetInventoryItemListByProjectId(projectId);
List<InventoryItemView> results = [];
foreach (Material meta in context.EnumerateInventoryMaterial())
{
InventoryItem entity = entities.SingleOrDefault(e => e.ItemId == meta.Id) ?? InventoryItem.From(projectId, meta.Id);
results.Add(new(entity, meta, saveCommand));
}
return results;
}
/// <inheritdoc/>
public void SaveInventoryItem(InventoryItemView item)
{
inventoryDbService.UpdateInventoryItem(item.Entity);
}
/// <inheritdoc/>
public async ValueTask RefreshInventoryAsync(CultivateProject project)
{
List<AvatarPromotionDelta> deltas = await minimalPromotionDelta.GetAsync().ConfigureAwait(false);
BatchConsumption? batchConsumption = default;
using (IServiceScope scope = serviceScopeFactory.CreateScope())
{
if (!UserAndUid.TryFromUser(userService.Current, out UserAndUid? userAndUid))
{
infoBarService.Warning(SH.MustSelectUserAndUid);
return;
}
CalculateClient calculateClient = scope.ServiceProvider.GetRequiredService<CalculateClient>();
Response<BatchConsumption>? resp = await calculateClient
.BatchComputeAsync(userAndUid, deltas, true)
.ConfigureAwait(false);
if (!resp.IsOk())
{
return;
}
batchConsumption = resp.Data;
}
if (batchConsumption is { OverallConsume: { } items })
{
await inventoryDbService.RemoveInventoryItemRangeByProjectIdAsync(project.InnerId).ConfigureAwait(false);
await inventoryDbService.AddInventoryItemRangeByProjectIdAsync(items.SelectList(item => InventoryItem.From(project.InnerId, item.Id, (uint)((int)item.Num - item.LackNum)))).ConfigureAwait(false);
}
}
}

View File

@@ -0,0 +1,165 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Google.OrTools.LinearSolver;
using Microsoft.Extensions.Caching.Memory;
using Snap.Hutao.Core;
using Snap.Hutao.Core.Diagnostics;
using Snap.Hutao.Core.ExceptionService;
using Snap.Hutao.Model.Metadata.Abstraction;
using Snap.Hutao.Model.Primitive;
using Snap.Hutao.Service.Metadata;
using Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
using System.Runtime.InteropServices;
using MetadataAvatar = Snap.Hutao.Model.Metadata.Avatar.Avatar;
using MetadataWeapon = Snap.Hutao.Model.Metadata.Weapon.Weapon;
namespace Snap.Hutao.Service.Inventory;
[ConstructorGenerated]
[Injection(InjectAs.Singleton)]
internal sealed partial class MinimalPromotionDelta
{
private const string CacheKey = $"{nameof(MinimalPromotionDelta)}.Cache";
private readonly ILogger<MinimalPromotionDelta> logger;
private readonly IMetadataService metadataService;
private readonly IMemoryCache memoryCache;
public async ValueTask<List<AvatarPromotionDelta>> GetAsync()
{
if (memoryCache.TryGetRequiredValue(CacheKey, out List<AvatarPromotionDelta>? cache))
{
return cache;
}
List<ICultivationItemsAccess> cultivationItemsEntryList =
[
.. (await metadataService.GetAvatarListAsync().ConfigureAwait(false)).Where(a => a.BeginTime <= DateTimeOffset.Now),
.. (await metadataService.GetWeaponListAsync().ConfigureAwait(false)).Where(w => w.Quality >= Model.Intrinsic.QualityType.QUALITY_BLUE),
];
List<ICultivationItemsAccess> minimal;
using (ValueStopwatch.MeasureExecution(logger))
{
minimal = Minimize(cultivationItemsEntryList);
}
// Gurantee the order of avatar and weapon
// Make sure weapons can have avatar to attach
minimal.Sort(CultivationItemsAccessComparer.Shared);
return memoryCache.Set(CacheKey, ToPromotionDeltaList(minimal));
}
private static List<ICultivationItemsAccess> Minimize(List<ICultivationItemsAccess> cultivationItems)
{
using (Solver? solver = Solver.CreateSolver("SCIP"))
{
ArgumentNullException.ThrowIfNull(solver);
Objective objective = solver.Objective();
objective.SetMinimization();
Dictionary<ICultivationItemsAccess, Variable> itemVariableMap = [];
foreach (ref readonly ICultivationItemsAccess item in CollectionsMarshal.AsSpan(cultivationItems))
{
Variable variable = solver.MakeBoolVar(item.Name);
itemVariableMap[item] = variable;
objective.SetCoefficient(variable, 1);
}
Dictionary<MaterialId, Constraint> materialConstraintMap = [];
foreach (ref readonly ICultivationItemsAccess item in CollectionsMarshal.AsSpan(cultivationItems))
{
foreach (ref readonly MaterialId materialId in CollectionsMarshal.AsSpan(item.CultivationItems))
{
ref Constraint? constraint = ref CollectionsMarshal.GetValueRefOrAddDefault(materialConstraintMap, materialId, out _);
constraint ??= solver.MakeConstraint(1, double.PositiveInfinity, $"{materialId}");
constraint.SetCoefficient(itemVariableMap[item], 1);
}
}
Solver.ResultStatus status = solver.Solve();
HutaoException.ThrowIf(status != Solver.ResultStatus.OPTIMAL, "Unable to solve minimal item set");
List<ICultivationItemsAccess> results = [];
foreach ((ICultivationItemsAccess item, Variable variable) in itemVariableMap)
{
if (variable.SolutionValue() > 0.5)
{
results.Add(item);
}
}
return results;
}
}
private static List<AvatarPromotionDelta> ToPromotionDeltaList(List<ICultivationItemsAccess> cultivationItems)
{
List<AvatarPromotionDelta> deltas = [];
int currentWeaponEmptyAvatarIndex = 0;
foreach (ref readonly ICultivationItemsAccess item in CollectionsMarshal.AsSpan(cultivationItems))
{
switch (item)
{
case MetadataAvatar avatar:
deltas.Add(new()
{
AvatarId = avatar.Id,
AvatarLevelCurrent = 1,
AvatarLevelTarget = 90,
SkillList = avatar.SkillDepot.CompositeSkillsNoInherents().SelectList(skill => new PromotionDelta()
{
Id = skill.GroupId,
LevelCurrent = 1,
LevelTarget = 10,
}),
});
break;
case MetadataWeapon weapon:
AvatarPromotionDelta delta;
if (currentWeaponEmptyAvatarIndex < deltas.Count)
{
delta = deltas[currentWeaponEmptyAvatarIndex++];
}
else
{
delta = new();
deltas.Add(delta);
}
delta.Weapon = new()
{
Id = weapon.Id,
LevelCurrent = 1,
LevelTarget = 90,
};
break;
}
}
return deltas;
}
private sealed class CultivationItemsAccessComparer : IComparer<ICultivationItemsAccess>
{
private static readonly LazySlim<CultivationItemsAccessComparer> LazyShared = new(() => new());
public static CultivationItemsAccessComparer Shared { get => LazyShared.Value; }
public int Compare(ICultivationItemsAccess? x, ICultivationItemsAccess? y)
{
return (x, y) switch
{
(MetadataAvatar, MetadataWeapon) => -1,
(MetadataWeapon, MetadataAvatar) => 1,
_ => 0,
};
}
}
}

View File

@@ -26,7 +26,7 @@ internal sealed partial class DailyNoteRefreshJobScheduler : IJobScheduler
ITrigger dailyNoteTrigger = TriggerBuilder.Create()
.WithIdentity(JobIdentity.DailyNoteRefreshTriggerName, JobIdentity.DailyNoteGroupName)
.StartNow()
.WithSimpleSchedule(builder => builder.WithIntervalInMinutes(interval).RepeatForever())
.WithSimpleSchedule(builder => builder.WithIntervalInSeconds(interval).RepeatForever())
.Build();
await scheduler.ScheduleJob(dailyNoteJob, dailyNoteTrigger).ConfigureAwait(false);

View File

@@ -0,0 +1,11 @@
// 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; }
}

View File

@@ -0,0 +1,11 @@
// 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; }
}

View File

@@ -0,0 +1,11 @@
// 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; }
}

View File

@@ -66,6 +66,21 @@ 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);

View File

@@ -16,6 +16,7 @@ internal static class MetadataFileNames
public const string FileNameMaterial = "Material";
public const string FileNameMonster = "Monster";
public const string FileNameMonsterCurve = "MonsterCurve";
public const string FileNameProfilePicture = "ProfilePicture";
public const string FileNameReliquary = "Reliquary";
public const string FileNameReliquaryAffixWeight = "ReliquaryAffixWeight";
public const string FileNameReliquaryMainAffix = "ReliquaryMainAffix";

View File

@@ -71,6 +71,21 @@ 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<AvatarId, ProfilePicture>(FileNameProfilePicture, p => p.AvatarId, token);
}
public static ValueTask<Dictionary<CostumeId, ProfilePicture>> GetCostumeIdToProfilePictureMapAsync(this IMetadataService metadataService, CancellationToken token = default)
{
return metadataService.FromCacheAsDictionaryAsync<CostumeId, ProfilePicture>(FileNameProfilePicture, p => p.CostumeId, 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);

View File

@@ -1,7 +1,6 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.UI.Xaml.Controls;
using System.Collections.ObjectModel;
namespace Snap.Hutao.Service.Notification;
@@ -9,7 +8,7 @@ namespace Snap.Hutao.Service.Notification;
[HighQuality]
internal interface IInfoBarService
{
ObservableCollection<InfoBar> Collection { get; }
ObservableCollection<InfoBarOptions> Collection { get; }
void PrepareInfoBarAndShow(Action<IInfoBarOptionsBuilder> configure);
}

View File

@@ -2,7 +2,6 @@
// Licensed under the MIT license.
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
namespace Snap.Hutao.Service.Notification;
@@ -16,7 +15,9 @@ internal sealed class InfoBarOptions
public object? Content { get; set; }
public ButtonBase? ActionButton { get; set; }
public string? ActionButtonContent { get; set; }
public ICommand? ActionButtonCommand { get; set; }
public int MilliSecondsDelay { get; set; }
}

View File

@@ -2,8 +2,6 @@
// Licensed under the MIT license.
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Snap.Hutao.Control.Builder.ButtonBase;
using Snap.Hutao.Core.Abstraction.Extension;
namespace Snap.Hutao.Service.Notification;
@@ -38,20 +36,17 @@ internal static class InfoBarOptionsBuilderExtension
return builder;
}
public static IInfoBarOptionsBuilder SetActionButton<TBuilder, TButton>(this TBuilder builder, Action<ButtonBaseBuilder<TButton>> configureButton)
public static IInfoBarOptionsBuilder SetActionButtonContent<TBuilder>(this TBuilder builder, string? buttonContent)
where TBuilder : IInfoBarOptionsBuilder
where TButton : ButtonBase, new()
{
ButtonBaseBuilder<TButton> buttonBaseBuilder = new ButtonBaseBuilder<TButton>().Configure(configureButton);
builder.Configure(builder => builder.Options.ActionButton = buttonBaseBuilder.Button);
builder.Configure(builder => builder.Options.ActionButtonContent = buttonContent);
return builder;
}
public static IInfoBarOptionsBuilder SetActionButton<TBuilder>(this TBuilder builder, Action<ButtonBuilder> configureButton)
public static IInfoBarOptionsBuilder SetActionButtonCommand<TBuilder>(this TBuilder builder, ICommand? buttonCommand)
where TBuilder : IInfoBarOptionsBuilder
{
ButtonBuilder buttonBaseBuilder = new ButtonBuilder().Configure(configureButton);
builder.Configure(builder => builder.Options.ActionButton = buttonBaseBuilder.Button);
builder.Configure(builder => builder.Options.ActionButtonCommand = buttonCommand);
return builder;
}

View File

@@ -1,11 +1,8 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Animation;
using Snap.Hutao.Core.Abstraction.Extension;
using System.Collections.ObjectModel;
using Windows.Foundation;
namespace Snap.Hutao.Service.Notification;
@@ -17,20 +14,16 @@ internal sealed class InfoBarService : IInfoBarService
private readonly ILogger<InfoBarService> logger;
private readonly ITaskContext taskContext;
private readonly TypedEventHandler<InfoBar, InfoBarClosedEventArgs> infobarClosedEventHandler;
private ObservableCollection<InfoBar>? collection;
private ObservableCollection<InfoBarOptions>? collection;
public InfoBarService(IServiceProvider serviceProvider)
{
logger = serviceProvider.GetRequiredService<ILogger<InfoBarService>>();
taskContext = serviceProvider.GetRequiredService<ITaskContext>();
infobarClosedEventHandler = OnInfoBarClosed;
}
/// <inheritdoc/>
public ObservableCollection<InfoBar> Collection
public ObservableCollection<InfoBarOptions> Collection
{
get => collection ??= [];
}
@@ -51,33 +44,7 @@ internal sealed class InfoBarService : IInfoBarService
await taskContext.SwitchToMainThreadAsync();
InfoBar infoBar = new()
{
Severity = builder.Options.Severity,
Title = builder.Options.Title,
Message = builder.Options.Message,
Content = builder.Options.Content,
IsOpen = true,
ActionButton = builder.Options.ActionButton,
Transitions = [new AddDeleteThemeTransition()],
};
infoBar.Closed += infobarClosedEventHandler;
ArgumentNullException.ThrowIfNull(collection);
collection.Add(infoBar);
if (builder.Options.MilliSecondsDelay > 0)
{
await Delay.FromMilliSeconds(builder.Options.MilliSecondsDelay).ConfigureAwait(true);
collection.Remove(infoBar);
infoBar.IsOpen = false;
}
}
private void OnInfoBarClosed(InfoBar sender, InfoBarClosedEventArgs args)
{
ArgumentNullException.ThrowIfNull(collection);
taskContext.BeginInvokeOnMainThread(() => collection.Remove(sender));
sender.Closed -= infobarClosedEventHandler;
collection.Add(builder.Options);
}
}

View File

@@ -2,7 +2,6 @@
// Licensed under the MIT license.
using Microsoft.UI.Xaml.Controls;
using Snap.Hutao.Control.Builder.ButtonBase;
using Snap.Hutao.Core.Abstraction.Extension;
namespace Snap.Hutao.Service.Notification;
@@ -21,7 +20,7 @@ internal static class InfoBarServiceExtension
public static void Information(this IInfoBarService infoBarService, string title, string message, string buttonContent, ICommand buttonCommand, int milliSeconds = 5000)
{
infoBarService.Information(builder => builder.SetTitle(title).SetMessage(message).SetActionButton(buttonBuilder => buttonBuilder.SetContent(buttonContent).SetCommand(buttonCommand)).SetDelay(milliSeconds));
infoBarService.Information(builder => builder.SetTitle(title).SetMessage(message).SetActionButtonContent(buttonContent).SetActionButtonCommand(buttonCommand).SetDelay(milliSeconds));
}
public static void Information(this IInfoBarService infoBarService, Action<IInfoBarOptionsBuilder> configure)
@@ -56,7 +55,7 @@ internal static class InfoBarServiceExtension
public static void Warning(this IInfoBarService infoBarService, string title, string message, string buttonContent, ICommand buttonCommand, int milliSeconds = 30000)
{
infoBarService.Warning(builder => builder.SetTitle(title).SetMessage(message).SetActionButton(buttonBuilder => buttonBuilder.SetContent(buttonContent).SetCommand(buttonCommand)).SetDelay(milliSeconds));
infoBarService.Warning(builder => builder.SetTitle(title).SetMessage(message).SetActionButtonContent(buttonContent).SetActionButtonCommand(buttonCommand).SetDelay(milliSeconds));
}
public static void Warning(this IInfoBarService infoBarService, Action<IInfoBarOptionsBuilder> configure)
@@ -76,7 +75,7 @@ internal static class InfoBarServiceExtension
public static void Error(this IInfoBarService infoBarService, string title, string message, string buttonContent, ICommand buttonCommand, int milliSeconds = 0)
{
infoBarService.Error(builder => builder.SetTitle(title).SetMessage(message).SetActionButton(buttonBuilder => buttonBuilder.SetContent(buttonContent).SetCommand(buttonCommand)).SetDelay(milliSeconds));
infoBarService.Error(builder => builder.SetTitle(title).SetMessage(message).SetActionButtonContent(buttonContent).SetActionButtonCommand(buttonCommand).SetDelay(milliSeconds));
}
public static void Error(this IInfoBarService infoBarService, Exception ex, int milliSeconds = 0)
@@ -91,7 +90,7 @@ internal static class InfoBarServiceExtension
public static void Error(this IInfoBarService infoBarService, Exception ex, string subtitle, string buttonContent, ICommand buttonCommand, int milliSeconds = 0)
{
infoBarService.Error(builder => builder.SetTitle(ex.GetType().Name).SetMessage($"{subtitle}\n{ex.Message}").SetActionButton(buttonBuilder => buttonBuilder.SetContent(buttonContent).SetCommand(buttonCommand)).SetDelay(milliSeconds));
infoBarService.Error(builder => builder.SetTitle(ex.GetType().Name).SetMessage($"{subtitle}\n{ex.Message}").SetActionButtonContent(buttonContent).SetActionButtonCommand(buttonCommand).SetDelay(milliSeconds));
}
public static void Error(this IInfoBarService infoBarService, Action<IInfoBarOptionsBuilder> configure)

View File

@@ -0,0 +1,18 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Service.Abstraction;
namespace Snap.Hutao.Service.User;
internal interface IUserGameRoleDbService : IAppDbService<UserGameRoleProfilePicture>
{
ValueTask<bool> ContainsUidAsync(string uid, CancellationToken token = default);
ValueTask<UserGameRoleProfilePicture> GetUserGameRoleProfilePictureByUidAsync(string uid, CancellationToken token = default);
ValueTask UpdateUserGameRoleProfilePictureAsync(UserGameRoleProfilePicture profilePicture, CancellationToken token = default);
ValueTask DeleteUserGameRoleProfilePictureByUidAsync(string uid, CancellationToken token = default);
}

View File

@@ -1,6 +1,8 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Web.Hoyolab.Takumi.Binding;
namespace Snap.Hutao.Service.User;
internal interface IUserInitializationService
@@ -8,4 +10,6 @@ internal interface IUserInitializationService
ValueTask<ViewModel.User.User?> CreateUserFromInputCookieOrDefaultAsync(InputCookie inputCookie, CancellationToken token = default(CancellationToken));
ValueTask<ViewModel.User.User> ResumeUserAsync(Model.Entity.User inner, CancellationToken token = default(CancellationToken));
ValueTask RefreshUserGameRolesProfilePictureAsync(UserGameRole userGameRole, CancellationToken token = default);
}

View File

@@ -0,0 +1,11 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Service.Metadata.ContextAbstraction;
namespace Snap.Hutao.Service.User;
internal interface IUserMetadataContext : IMetadataContext,
IMetadataDictionaryIdProfilePictureSource,
IMetadataDictionaryAvatarIdProfilePictureSource,
IMetadataDictionaryCostumeIdProfilePictureSource;

View File

@@ -53,4 +53,6 @@ internal interface IUserService
/// <param name="user">待移除的用户</param>
/// <returns>任务</returns>
ValueTask RemoveUserAsync(BindingUser user);
ValueTask RefreshUserGameRoleProfilePictureAsync(UserGameRole userGameRole);
}

View File

@@ -0,0 +1,37 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.EntityFrameworkCore;
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Service.Abstraction;
namespace Snap.Hutao.Service.User;
[ConstructorGenerated]
[Injection(InjectAs.Singleton, typeof(IUserGameRoleDbService))]
internal sealed partial class UserGameRoleDbService : IUserGameRoleDbService
{
private readonly IServiceProvider serviceProvider;
public IServiceProvider ServiceProvider { get => serviceProvider; }
public ValueTask<bool> ContainsUidAsync(string uid, CancellationToken token = default)
{
return this.QueryAsync(query => query.AnyAsync(n => n.Uid == uid));
}
public ValueTask<UserGameRoleProfilePicture> GetUserGameRoleProfilePictureByUidAsync(string uid, CancellationToken token = default)
{
return this.QueryAsync(query => query.FirstAsync(n => n.Uid == uid));
}
public async ValueTask UpdateUserGameRoleProfilePictureAsync(UserGameRoleProfilePicture profilePicture, CancellationToken token = default)
{
await this.UpdateAsync(profilePicture, token).ConfigureAwait(false);
}
public async ValueTask DeleteUserGameRoleProfilePictureByUidAsync(string uid, CancellationToken token = default)
{
await this.DeleteAsync(profilePicture => profilePicture.Uid == uid, token).ConfigureAwait(false);
}
}

View File

@@ -2,12 +2,18 @@
// Licensed under the MIT license.
using Snap.Hutao.Core.DependencyInjection.Abstraction;
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Model.Entity.Extension;
using Snap.Hutao.Service.Metadata;
using Snap.Hutao.Service.Metadata.ContextAbstraction;
using Snap.Hutao.Web.Enka;
using Snap.Hutao.Web.Enka.Model;
using Snap.Hutao.Web.Hoyolab;
using Snap.Hutao.Web.Hoyolab.Bbs.User;
using Snap.Hutao.Web.Hoyolab.Passport;
using Snap.Hutao.Web.Hoyolab.Takumi.Binding;
using Snap.Hutao.Web.Response;
using MetadataProfilePicture = Snap.Hutao.Model.Metadata.Avatar.ProfilePicture;
namespace Snap.Hutao.Service.User;
@@ -16,6 +22,7 @@ namespace Snap.Hutao.Service.User;
internal sealed partial class UserInitializationService : IUserInitializationService
{
private readonly IUserFingerprintService userFingerprintService;
private readonly IUserGameRoleDbService userGameRoleDbService;
private readonly IServiceProvider serviceProvider;
public async ValueTask<ViewModel.User.User> ResumeUserAsync(Model.Entity.User inner, CancellationToken token = default)
@@ -55,6 +62,30 @@ internal sealed partial class UserInitializationService : IUserInitializationSer
}
}
public async ValueTask RefreshUserGameRolesProfilePictureAsync(UserGameRole userGameRole, CancellationToken token = default)
{
EnkaResponse? enkaResponse;
using (IServiceScope scope = serviceProvider.CreateScope())
{
EnkaClient enkaClient = scope.ServiceProvider
.GetRequiredService<EnkaClient>();
enkaResponse = await enkaClient
.GetForwardPlayerInfoAsync(userGameRole, token)
.ConfigureAwait(false);
}
if (enkaResponse is { PlayerInfo: { } playerInfo })
{
UserGameRoleProfilePicture profilePicture = UserGameRoleProfilePicture.From(userGameRole, playerInfo.ProfilePicture);
await userGameRoleDbService.DeleteUserGameRoleProfilePictureByUidAsync(userGameRole.GameUid, token).ConfigureAwait(false);
await userGameRoleDbService.UpdateUserGameRoleProfilePictureAsync(profilePicture, token).ConfigureAwait(false);
await SetUserGameRolesProfilePictureCoreAsync(userGameRole, profilePicture, token).ConfigureAwait(false);
}
}
private async ValueTask<bool> InitializeUserAsync(ViewModel.User.User user, CancellationToken token = default)
{
if (user.IsInitialized)
@@ -89,6 +120,8 @@ internal sealed partial class UserInitializationService : IUserInitializationSer
return false;
}
TrySetUserUserGameRolesProfilePictureAsync(user, token).SafeForget();
await userFingerprintService.TryInitializeAsync(user, token).ConfigureAwait(false);
return user.IsInitialized = true;
@@ -216,4 +249,69 @@ internal sealed partial class UserInitializationService : IUserInitializationSer
return false;
}
}
private async ValueTask TrySetUserUserGameRolesProfilePictureAsync(ViewModel.User.User user, CancellationToken token = default)
{
foreach (UserGameRole userGameRole in user.UserGameRoles)
{
if (await userGameRoleDbService.ContainsUidAsync(userGameRole.GameUid, token).ConfigureAwait(false))
{
UserGameRoleProfilePicture savedProfilePicture = await userGameRoleDbService
.GetUserGameRoleProfilePictureByUidAsync(userGameRole.GameUid, token)
.ConfigureAwait(false);
if (await SetUserGameRolesProfilePictureCoreAsync(userGameRole, savedProfilePicture, token).ConfigureAwait(false))
{
continue;
}
}
await RefreshUserGameRolesProfilePictureAsync(userGameRole, token).ConfigureAwait(false);
}
}
private async ValueTask<bool> SetUserGameRolesProfilePictureCoreAsync(UserGameRole userGameRole, UserGameRoleProfilePicture profilePicture, CancellationToken token = default)
{
if (profilePicture.LastUpdateTime.AddDays(15) < DateTimeOffset.Now)
{
return false;
}
UserMetadataContext context;
using (IServiceScope scope = serviceProvider.CreateScope())
{
IMetadataService metadataService = scope.ServiceProvider
.GetRequiredService<IMetadataService>();
if (!await metadataService.InitializeAsync().ConfigureAwait(false))
{
return false;
}
context = await scope.ServiceProvider
.GetRequiredService<IMetadataService>()
.GetContextAsync<UserMetadataContext>(token)
.ConfigureAwait(false);
}
if (context.IdProfilePictureMap.TryGetValue(profilePicture.ProfilePictureId, out MetadataProfilePicture? metadataProfilePicture))
{
userGameRole.ProfilePictureIcon = metadataProfilePicture.Icon;
return true;
}
if (context.CostumeIdProfilePictureMap.TryGetValue(profilePicture.CostumeId, out metadataProfilePicture))
{
userGameRole.ProfilePictureIcon = metadataProfilePicture.Icon;
return true;
}
if (context.AvatarIdProfilePictureMap.TryGetValue(profilePicture.AvatarId, out metadataProfilePicture))
{
userGameRole.ProfilePictureIcon = metadataProfilePicture.Icon;
return true;
}
return false;
}
}

View File

@@ -0,0 +1,16 @@
// Copyright (c) DGP Studio. All rights reserved.
// 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!;
}

View File

@@ -21,6 +21,7 @@ namespace Snap.Hutao.Service.User;
[Injection(InjectAs.Singleton, typeof(IUserService))]
internal sealed partial class UserService : IUserService, IUserServiceUnsafe
{
private readonly IUserInitializationService userInitializationService;
private readonly IUserCollectionService userCollectionService;
private readonly IServiceProvider serviceProvider;
private readonly IUserDbService userDbService;
@@ -121,4 +122,9 @@ internal sealed partial class UserService : IUserService, IUserServiceUnsafe
return true;
}
public async ValueTask RefreshUserGameRoleProfilePictureAsync(UserGameRole userGameRole)
{
await userInitializationService.RefreshUserGameRolesProfilePictureAsync(userGameRole).ConfigureAwait(false);
}
}

View File

@@ -313,8 +313,9 @@
<PackageReference Include="CommunityToolkit.WinUI.Controls.TokenizingTextBox" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.WinUI.Media" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.WinUI.Notifications" Version="7.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.5">
<PackageReference Include="Google.OrTools" Version="9.10.4067" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

View File

@@ -44,7 +44,10 @@
CornerRadius="{ThemeResource ControlCornerRadiusTop}">
<shci:CachedImage Source="{Binding Event.Banner}" Stretch="UniformToFill"/>
</cwc:ConstrainedBox>
<Border Margin="-1" Background="{ThemeResource DarkOnlyOverlayMaskColorBrush}"/>
<Border
Margin="-1"
Background="{ThemeResource DarkOnlyOverlayMaskColorBrush}"
IsHitTestVisible="False"/>
</Grid>
<ScrollViewer Grid.Row="1">

View File

@@ -31,14 +31,14 @@
<Slider
MinWidth="160"
Margin="32,0,0,0"
Maximum="160"
Maximum="{Binding DailyNote.MaxResin}"
Minimum="0"
Value="{Binding ResinNotifyThreshold, Mode=TwoWay}"/>
</clw:SettingsCard>
<clw:SettingsCard Padding="16,8" Header="{shcm:ResourceString Name=ViewDialogDailyNoteNotificationHomeCoinNotifyThreshold}">
<Slider
MinWidth="160"
Maximum="2400"
Maximum="{Binding DailyNote.MaxHomeCoin}"
Minimum="0"
Value="{Binding HomeCoinNotifyThreshold, Mode=TwoWay}"/>
</clw:SettingsCard>

View File

@@ -5,67 +5,112 @@
xmlns:cw="using:CommunityToolkit.WinUI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mxi="using:Microsoft.Xaml.Interactivity"
xmlns:shcb="using:Snap.Hutao.Control.Behavior"
xmlns:shcm="using:Snap.Hutao.Control.Markup"
xmlns:shcs="using:Snap.Hutao.Control.Selector"
xmlns:shsn="using:Snap.Hutao.Service.Notification"
mc:Ignorable="d">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<AcrylicBrush
x:Key="InfoBarErrorSeverityBackgroundBrush"
FallbackColor="#FDE7E9"
TintColor="#FDE7E9"
TintOpacity="0.6"/>
<AcrylicBrush
x:Key="InfoBarWarningSeverityBackgroundBrush"
FallbackColor="#FFF4CE"
TintColor="#FFF4CE"
TintOpacity="0.6"/>
<AcrylicBrush
x:Key="InfoBarSuccessSeverityBackgroundBrush"
FallbackColor="#DFF6DD"
TintColor="#DFF6DD"
TintOpacity="0.6"/>
<AcrylicBrush
x:Key="InfoBarInformationalSeverityBackgroundBrush"
FallbackColor="#80F6F6F6"
TintColor="#80F6F6F6"
TintOpacity="0.6"/>
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<AcrylicBrush
x:Key="InfoBarErrorSeverityBackgroundBrush"
FallbackColor="#442726"
TintColor="#442726"
TintOpacity="0.6"/>
<AcrylicBrush
x:Key="InfoBarWarningSeverityBackgroundBrush"
FallbackColor="#433519"
TintColor="#433519"
TintOpacity="0.6"/>
<AcrylicBrush
x:Key="InfoBarSuccessSeverityBackgroundBrush"
FallbackColor="#393D1B"
TintColor="#393D1B"
TintOpacity="0.6"/>
<AcrylicBrush
x:Key="InfoBarInformationalSeverityBackgroundBrush"
FallbackColor="#34424d"
TintColor="#34424d"
TintOpacity="0.6"/>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<DataTemplate x:Key="InfoBarTemplate" x:DataType="shsn:InfoBarOptions">
<InfoBar
Title="{Binding Title}"
Closed="OnInfoBarClosed"
Content="{Binding Content}"
IsOpen="True"
Message="{Binding Message}"
Severity="{Binding Severity}">
<mxi:Interaction.Behaviors>
<shcb:InfoBarDelayCloseBehavior MilliSecondsDelay="{Binding MilliSecondsDelay}"/>
</mxi:Interaction.Behaviors>
</InfoBar>
</DataTemplate>
<DataTemplate x:Key="InfoBarWithActionButtonTemplate" x:DataType="shsn:InfoBarOptions">
<InfoBar
Title="{Binding Title}"
Closed="OnInfoBarClosed"
Content="{Binding Content}"
IsOpen="True"
Message="{Binding Message}"
Severity="{Binding Severity}">
<InfoBar.ActionButton>
<Button Command="{Binding ActionButtonCommand}" Content="{Binding ActionButtonContent}"/>
</InfoBar.ActionButton>
<mxi:Interaction.Behaviors>
<shcb:InfoBarDelayCloseBehavior MilliSecondsDelay="{Binding MilliSecondsDelay}"/>
</mxi:Interaction.Behaviors>
</InfoBar>
</DataTemplate>
<shcs:InfoBarTemplateSelector
x:Key="InfoBarTemplateSelector"
ActionButtonDisabled="{StaticResource InfoBarTemplate}"
ActionButtonEnabled="{StaticResource InfoBarWithActionButtonTemplate}"/>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<ItemsControl
MaxWidth="640"
Margin="32,48,32,32"
VerticalAlignment="Bottom"
ItemContainerTransitions="{StaticResource RepositionThemeTransitions}"
ItemTemplateSelector="{StaticResource InfoBarTemplateSelector}"
ItemsSource="{x:Bind InfoBars}"
Visibility="{x:Bind VisibilityButton.IsChecked, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}">
<ItemsControl.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<AcrylicBrush
x:Key="InfoBarErrorSeverityBackgroundBrush"
FallbackColor="#FDE7E9"
TintColor="#FDE7E9"
TintOpacity="0.6"/>
<AcrylicBrush
x:Key="InfoBarWarningSeverityBackgroundBrush"
FallbackColor="#FFF4CE"
TintColor="#FFF4CE"
TintOpacity="0.6"/>
<AcrylicBrush
x:Key="InfoBarSuccessSeverityBackgroundBrush"
FallbackColor="#DFF6DD"
TintColor="#DFF6DD"
TintOpacity="0.6"/>
<AcrylicBrush
x:Key="InfoBarInformationalSeverityBackgroundBrush"
FallbackColor="#80F6F6F6"
TintColor="#80F6F6F6"
TintOpacity="0.6"/>
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<AcrylicBrush
x:Key="InfoBarErrorSeverityBackgroundBrush"
FallbackColor="#442726"
TintColor="#442726"
TintOpacity="0.6"/>
<AcrylicBrush
x:Key="InfoBarWarningSeverityBackgroundBrush"
FallbackColor="#433519"
TintColor="#433519"
TintOpacity="0.6"/>
<AcrylicBrush
x:Key="InfoBarSuccessSeverityBackgroundBrush"
FallbackColor="#393D1B"
TintColor="#393D1B"
TintOpacity="0.6"/>
<AcrylicBrush
x:Key="InfoBarInformationalSeverityBackgroundBrush"
FallbackColor="#34424d"
TintColor="#34424d"
TintOpacity="0.6"/>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</ItemsControl.Resources>
<ItemsControl.Transitions>
<AddDeleteThemeTransition/>
</ItemsControl.Transitions>
</ItemsControl>
<Border

View File

@@ -13,7 +13,7 @@ namespace Snap.Hutao.View;
/// <summary>
/// 信息条视图
/// </summary>
[DependencyProperty("InfoBars", typeof(ObservableCollection<InfoBar>))]
[DependencyProperty("InfoBars", typeof(ObservableCollection<InfoBarOptions>))]
internal sealed partial class InfoBarView : UserControl
{
private readonly IInfoBarService infoBarService;
@@ -35,4 +35,9 @@ internal sealed partial class InfoBarView : UserControl
{
LocalSetting.Set(SettingKeys.IsInfoBarToggleChecked, ((ToggleButton)sender).IsChecked ?? false);
}
private void OnInfoBarClosed(InfoBar sender, InfoBarClosedEventArgs args)
{
InfoBars.Remove((InfoBarOptions)sender.DataContext);
}
}

View File

@@ -62,7 +62,7 @@
</cwa:AnimationSet>
</cwa:Explicit.Animations>
</Border>
<Border Background="{ThemeResource DarkOnlyOverlayMaskColorBrush}"/>
<Border Background="{ThemeResource DarkOnlyOverlayMaskColorBrush}" IsHitTestVisible="False"/>
</Grid>
</Border>
<!-- Time Description -->

View File

@@ -11,7 +11,6 @@
xmlns:mxi="using:Microsoft.Xaml.Interactivity"
xmlns:shc="using:Snap.Hutao.Control"
xmlns:shcb="using:Snap.Hutao.Control.Behavior"
xmlns:shcca="using:Snap.Hutao.Control.Collection.Alternating"
xmlns:shci="using:Snap.Hutao.Control.Image"
xmlns:shcm="using:Snap.Hutao.Control.Markup"
xmlns:shcp="using:Snap.Hutao.Control.Panel"
@@ -620,7 +619,8 @@
<Rectangle
Grid.RowSpan="2"
Grid.ColumnSpan="2"
Fill="#33000000"/>
Fill="#33000000"
IsHitTestVisible="False"/>
<StackPanel
Margin="16"
HorizontalAlignment="Left"

View File

@@ -269,6 +269,10 @@
Style="{ThemeResource CommandBarComboBoxStyle}"/>
</shc:SizeRestrictedContentControl>
</AppBarElementContainer>
<AppBarButton
Command="{Binding RefreshInventoryCommand}"
Icon="{shcm:FontIcon Glyph=&#xE72C;}"
Label="{shcm:ResourceString Name=ViewPageCultivationRefreshInventory}"/>
<AppBarButton
Command="{Binding AddProjectCommand}"
Icon="{shcm:FontIcon Glyph=&#xE710;}"

View File

@@ -343,7 +343,10 @@
Source="{Binding SelectedHistoryWish.BannerImage}"
Stretch="UniformToFill"/>
</cwcont:ConstrainedBox>
<Border Grid.ColumnSpan="2" Background="{ThemeResource DarkOnlyOverlayMaskColorBrush}"/>
<Border
Grid.ColumnSpan="2"
Background="{ThemeResource DarkOnlyOverlayMaskColorBrush}"
IsHitTestVisible="False"/>
</Grid>
</Border>

View File

@@ -571,7 +571,7 @@
Grid.Column="0"
ItemTemplate="{StaticResource CollocationTemplate}"
ItemsPanel="{StaticResource StackPanelSpacing4Template}"
ItemsSource="{Binding Selected.Collocation.Avatars}"/>
ItemsSource="{Binding Selected.CollocationView.Avatars}"/>
<TextBlock
Grid.Row="0"
Grid.Column="1"
@@ -582,7 +582,7 @@
Grid.Column="1"
ItemTemplate="{StaticResource CollocationTemplate}"
ItemsPanel="{StaticResource StackPanelSpacing4Template}"
ItemsSource="{Binding Selected.Collocation.Weapons}"/>
ItemsSource="{Binding Selected.CollocationView.Weapons}"/>
<TextBlock
Grid.Row="0"
Grid.Column="2"
@@ -593,7 +593,7 @@
Grid.Column="2"
ItemTemplate="{StaticResource CollocationReliquaryTemplate}"
ItemsPanel="{StaticResource StackPanelSpacing4Template}"
ItemsSource="{Binding Selected.Collocation.ReliquarySets}"/>
ItemsSource="{Binding Selected.CollocationView.ReliquarySets}"/>
</Grid>
</Border>

View File

@@ -336,7 +336,7 @@
<Border Padding="16" Style="{ThemeResource BorderCardStyle}">
<StackPanel Spacing="16">
<TextBlock Style="{StaticResource BaseTextBlockStyle}" Text="{shcm:ResourceString Name=ViewPageWiKiAvatarTeamCombinationHeader}"/>
<ItemsControl ItemTemplate="{StaticResource CollocationTemplate}" ItemsSource="{Binding Selected.Collocation.Avatars}">
<ItemsControl ItemTemplate="{StaticResource CollocationTemplate}" ItemsSource="{Binding Selected.CollocationView.Avatars}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<cwc:UniformGrid

View File

@@ -19,14 +19,73 @@
<shc:BindingProxy x:Key="ViewModelBindingProxy" DataContext="{Binding}"/>
<DataTemplate x:Key="UserGameRoleTemplate">
<StackPanel Padding="0,6">
<TextBlock Text="{Binding Nickname}"/>
<TextBlock
Margin="0,2,0,0"
Opacity="0.6"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{Binding Description}"/>
</StackPanel>
<Grid Padding="0,12" Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<PersonPicture
Grid.Column="0"
Height="32"
Margin="2,0"
HorizontalAlignment="Left"
ProfilePicture="{Binding ProfilePictureIcon, Converter={StaticResource AvatarIconCircleConverter}}"/>
<Button
Grid.Column="0"
Width="32"
Height="32"
Margin="2,0"
Padding="0"
HorizontalAlignment="Left"
Background="Transparent"
BorderBrush="Transparent"
BorderThickness="0"
Command="{Binding DataContext.RefreshUserGameRoleProfilePictureCommand, Source={StaticResource ViewModelBindingProxy}}"
CommandParameter="{Binding}"
CornerRadius="8">
<Button.Resources>
<Storyboard x:Key="ShowRefreshIcon">
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="RefreshIcon" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="HideRefreshIcon">
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="RefreshIcon" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</Button.Resources>
<mxi:Interaction.Behaviors>
<mxic:EventTriggerBehavior EventName="PointerEntered">
<mxim:ControlStoryboardAction Storyboard="{StaticResource ShowRefreshIcon}"/>
</mxic:EventTriggerBehavior>
<mxic:EventTriggerBehavior EventName="PointerExited">
<mxim:ControlStoryboardAction Storyboard="{StaticResource HideRefreshIcon}"/>
</mxic:EventTriggerBehavior>
</mxi:Interaction.Behaviors>
<FontIcon
x:Name="RefreshIcon"
FontSize="12"
Glyph="&#xE72C;"
Visibility="Collapsed"/>
</Button>
<StackPanel Grid.Column="1" Margin="12,0">
<TextBlock Text="{Binding Nickname}"/>
<TextBlock
Margin="0,2,0,0"
Opacity="0.6"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{Binding Description}"/>
</StackPanel>
</Grid>
</DataTemplate>
<DataTemplate x:Key="UserTemplate">

View File

@@ -25,6 +25,7 @@ using Windows.Graphics.Imaging;
using Windows.Storage.Streams;
using Windows.UI;
using CalculatorAvatarPromotionDelta = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.AvatarPromotionDelta;
using CalculatorBatchConsumption = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.BatchConsumption;
using CalculatorClient = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.CalculateClient;
using CalculatorConsumption = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Consumption;
using CalculatorItem = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Item;
@@ -175,7 +176,7 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
return;
}
if (userService.Current is null)
if (!UserAndUid.TryFromUser(userService.Current, out UserAndUid? userAndUid))
{
infoBarService.Warning(SH.MustSelectUserAndUid);
return;
@@ -196,17 +197,20 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
return;
}
CultivateCoreResult result = await CultivateCoreAsync(userService.Current.Entity, delta, avatar).ConfigureAwait(false);
Response<CalculatorBatchConsumption> response = await calculatorClient.BatchComputeAsync(userAndUid, delta).ConfigureAwait(false);
switch (result)
if (!response.IsOk())
{
case CultivateCoreResult.Ok:
infoBarService.Success(SH.ViewModelCultivationEntryAddSuccess);
break;
case CultivateCoreResult.SaveConsumptionFailed:
infoBarService.Warning(SH.ViewModelCultivationEntryAddWarning);
break;
return;
}
if (!await SaveCultivationAsync(response.Data.Items.Single(), delta).ConfigureAwait(false))
{
infoBarService.Warning(SH.ViewModelCultivationEntryAddWarning);
return;
}
infoBarService.Success(SH.ViewModelCultivationEntryAddSuccess);
}
[Command("BatchCultivateCommand")]
@@ -217,7 +221,7 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
return;
}
if (userService.Current is null)
if (!UserAndUid.TryFromUser(userService.Current, out UserAndUid? userAndUid))
{
infoBarService.Warning(SH.MustSelectUserAndUid);
return;
@@ -237,9 +241,11 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
ContentDialog progressDialog = await contentDialogFactory
.CreateForIndeterminateProgressAsync(SH.ViewModelAvatarPropertyBatchCultivateProgressTitle)
.ConfigureAwait(false);
BatchCultivateResult result = default;
using (await progressDialog.BlockAsync(taskContext).ConfigureAwait(false))
{
BatchCultivateResult result = default;
List<CalculatorAvatarPromotionDelta> deltas = [];
foreach (AvatarView avatar in avatars)
{
if (!baseline.TryGetNonErrorCopy(avatar, out CalculatorAvatarPromotionDelta? copy))
@@ -248,75 +254,64 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
continue;
}
CultivateCoreResult coreResult = await CultivateCoreAsync(userService.Current.Entity, copy, avatar).ConfigureAwait(false);
deltas.Add(copy);
}
switch (coreResult)
{
case CultivateCoreResult.Ok:
++result.SucceedCount;
break;
case CultivateCoreResult.ComputeConsumptionFailed:
result.Interrupted = true;
break;
case CultivateCoreResult.SaveConsumptionFailed:
result.Interrupted = true;
break;
}
Response<CalculatorBatchConsumption> response = await calculatorClient.BatchComputeAsync(userAndUid, deltas).ConfigureAwait(false);
if (result.Interrupted)
if (!response.IsOk())
{
return;
}
foreach ((CalculatorConsumption consumption, CalculatorAvatarPromotionDelta delta) in response.Data.Items.Zip(deltas))
{
if (!await SaveCultivationAsync(consumption, delta).ConfigureAwait(false))
{
result.Interrupted = true;
break;
}
}
if (result.Interrupted)
{
infoBarService.Warning(SH.FormatViewModelCultivationBatchAddIncompletedFormat(result.SucceedCount, result.SkippedCount));
}
else
{
infoBarService.Success(SH.FormatViewModelCultivationBatchAddCompletedFormat(result.SucceedCount, result.SkippedCount));
++result.SucceedCount;
}
}
if (result.Interrupted)
{
infoBarService.Warning(SH.FormatViewModelCultivationBatchAddIncompletedFormat(result.SucceedCount, result.SkippedCount));
}
else
{
infoBarService.Success(SH.FormatViewModelCultivationBatchAddCompletedFormat(result.SucceedCount, result.SkippedCount));
}
}
private async ValueTask<CultivateCoreResult> CultivateCoreAsync(Model.Entity.User user, CalculatorAvatarPromotionDelta delta, AvatarView avatar)
private async ValueTask<bool> SaveCultivationAsync(CalculatorConsumption consumption, CalculatorAvatarPromotionDelta delta)
{
Response<CalculatorConsumption> consumptionResponse = await calculatorClient.ComputeAsync(user, delta).ConfigureAwait(false);
if (!consumptionResponse.IsOk())
{
return CultivateCoreResult.ComputeConsumptionFailed;
}
CalculatorConsumption consumption = consumptionResponse.Data;
LevelInformation levelInformation = LevelInformation.From(delta);
List<CalculatorItem> items = CalculatorItemHelper.Merge(consumption.AvatarConsume, consumption.AvatarSkillConsume);
bool avatarSaved = await cultivationService
.SaveConsumptionAsync(CultivateType.AvatarAndSkill, avatar.Id, items, levelInformation)
.SaveConsumptionAsync(CultivateType.AvatarAndSkill, delta.AvatarId, items, levelInformation)
.ConfigureAwait(false);
try
{
ArgumentNullException.ThrowIfNull(avatar.Weapon);
ArgumentNullException.ThrowIfNull(delta.Weapon);
// Take a hot path if avatar is not saved.
bool avatarAndWeaponSaved = avatarSaved && await cultivationService
.SaveConsumptionAsync(CultivateType.Weapon, avatar.Weapon.Id, consumption.WeaponConsume.EmptyIfNull(), levelInformation)
.SaveConsumptionAsync(CultivateType.Weapon, delta.Weapon.Id, consumption.WeaponConsume.EmptyIfNull(), levelInformation)
.ConfigureAwait(false);
if (!avatarAndWeaponSaved)
{
return CultivateCoreResult.SaveConsumptionFailed;
}
return avatarAndWeaponSaved;
}
catch (HutaoException ex)
{
infoBarService.Error(ex, SH.ViewModelCultivationAddWarning);
}
return CultivateCoreResult.Ok;
return true;
}
[Command("ExportAsImageCommand")]

View File

@@ -2,10 +2,12 @@
// Licensed under the MIT license.
using Microsoft.UI.Xaml.Controls;
using Snap.Hutao.Control.Extension;
using Snap.Hutao.Core.ExceptionService;
using Snap.Hutao.Factory.ContentDialog;
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Service.Cultivation;
using Snap.Hutao.Service.Inventory;
using Snap.Hutao.Service.Metadata;
using Snap.Hutao.Service.Metadata.ContextAbstraction;
using Snap.Hutao.Service.Navigation;
@@ -29,6 +31,7 @@ internal sealed partial class CultivationViewModel : Abstraction.ViewModel
private readonly ICultivationService cultivationService;
private readonly ILogger<CultivationViewModel> logger;
private readonly INavigationService navigationService;
private readonly IInventoryService inventoryService;
private readonly IMetadataService metadataService;
private readonly IInfoBarService infoBarService;
private readonly ITaskContext taskContext;
@@ -140,8 +143,8 @@ internal sealed partial class CultivationViewModel : Abstraction.ViewModel
await taskContext.SwitchToMainThreadAsync();
CultivateEntries = entries;
InventoryItems = cultivationService.GetInventoryItemViews(project, context, SaveInventoryItemCommand);
await UpdateInventoryItemsAsync().ConfigureAwait(false);
await UpdateStatisticsItemsAsync().ConfigureAwait(false);
}
@@ -173,11 +176,35 @@ internal sealed partial class CultivationViewModel : Abstraction.ViewModel
{
if (inventoryItem is not null)
{
cultivationService.SaveInventoryItem(inventoryItem);
inventoryService.SaveInventoryItem(inventoryItem);
await UpdateStatisticsItemsAsync().ConfigureAwait(false);
}
}
[Command("RefreshInventoryCommand")]
private async Task RefreshInventoryAsync()
{
if (SelectedProject is null)
{
return;
}
using (await EnterCriticalExecutionAsync().ConfigureAwait(false))
{
ContentDialog dialog = await contentDialogFactory
.CreateForIndeterminateProgressAsync(SH.ViewModelCultivationRefreshInventoryProgress)
.ConfigureAwait(false);
using (await dialog.BlockAsync(taskContext).ConfigureAwait(false))
{
await inventoryService.RefreshInventoryAsync(SelectedProject).ConfigureAwait(false);
await UpdateInventoryItemsAsync().ConfigureAwait(false);
await UpdateStatisticsItemsAsync().ConfigureAwait(false);
}
}
}
private async ValueTask UpdateStatisticsItemsAsync()
{
if (SelectedProject is not null)
@@ -201,6 +228,18 @@ internal sealed partial class CultivationViewModel : Abstraction.ViewModel
}
}
private async ValueTask UpdateInventoryItemsAsync()
{
if (SelectedProject is not null)
{
await taskContext.SwitchToBackgroundAsync();
CultivationMetadataContext context = await metadataService.GetContextAsync<CultivationMetadataContext>().ConfigureAwait(false);
await taskContext.SwitchToMainThreadAsync();
InventoryItems = inventoryService.GetInventoryItemViews(SelectedProject, context, SaveInventoryItemCommand);
}
}
[Command("NavigateToPageCommand")]
private void NavigateToPage(string? typeString)
{

View File

@@ -10,7 +10,6 @@ using Snap.Hutao.Core.Setting;
using Snap.Hutao.Core.Windowing;
using Snap.Hutao.Service.Game.Automation.ScreenCapture;
using Snap.Hutao.Service.Notification;
using Snap.Hutao.View.Converter;
using Snap.Hutao.ViewModel.Guide;
using Snap.Hutao.Web.Hutao.HutaoAsAService;
using Snap.Hutao.Win32.Foundation;

View File

@@ -17,6 +17,7 @@ using Snap.Hutao.View.Dialog;
using Snap.Hutao.View.Page;
using Snap.Hutao.Web.Hoyolab;
using Snap.Hutao.Web.Hoyolab.Passport;
using Snap.Hutao.Web.Hoyolab.Takumi.Binding;
using Snap.Hutao.Web.Response;
using System.Text;
using EntityUser = Snap.Hutao.Model.Entity.User;
@@ -297,4 +298,10 @@ internal sealed partial class UserViewModel : ObservableObject
FlyoutBase.ShowAttachedFlyout(appBarButton);
infoBarService.Warning(message);
}
[Command("RefreshUserGameRoleProfilePictureCommand")]
private void RefreshUserGameRoleProfilePicture(UserGameRole userGameRole)
{
userService.RefreshUserGameRoleProfilePictureAsync(userGameRole).SafeForget();
}
}

View File

@@ -20,15 +20,14 @@ using Snap.Hutao.Service.Metadata;
using Snap.Hutao.Service.Notification;
using Snap.Hutao.Service.User;
using Snap.Hutao.View.Dialog;
using Snap.Hutao.ViewModel.User;
using Snap.Hutao.Web.Response;
using System.Collections.Frozen;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using CalculateAvatarPromotionDelta = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.AvatarPromotionDelta;
using CalculateBatchConsumption = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.BatchConsumption;
using CalculateClient = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.CalculateClient;
using CalculateConsumption = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Consumption;
using CalculateItem = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Item;
using CalculateItemHelper = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.ItemHelper;
namespace Snap.Hutao.ViewModel.Wiki;
@@ -149,7 +148,7 @@ internal sealed partial class WikiAvatarViewModel : Abstraction.ViewModel
foreach (Avatar avatar in avatars)
{
avatar.Collocation = hutaoCache.AvatarCollocations.GetValueOrDefault(avatar.Id);
avatar.CollocationView = hutaoCache.AvatarCollocations.GetValueOrDefault(avatar.Id);
avatar.CookBonusView ??= CookBonusView.Create(avatar.FetterInfo.CookBonus, idMaterialMap);
avatar.CultivationItemsView ??= avatar.CultivationItems.SelectList(i => idMaterialMap.GetValueOrDefault(i, Material.Default));
}
@@ -163,7 +162,7 @@ internal sealed partial class WikiAvatarViewModel : Abstraction.ViewModel
return;
}
if (userService.Current is null)
if (!UserAndUid.TryFromUser(userService.Current, out UserAndUid? userAndUid))
{
infoBarService.Warning(SH.MustSelectUserAndUid);
return;
@@ -178,22 +177,21 @@ internal sealed partial class WikiAvatarViewModel : Abstraction.ViewModel
return;
}
Response<CalculateConsumption> consumptionResponse = await calculateClient
.ComputeAsync(userService.Current.Entity, delta)
Response<CalculateBatchConsumption> response = await calculateClient
.BatchComputeAsync(userAndUid, delta)
.ConfigureAwait(false);
if (!consumptionResponse.IsOk())
if (!response.IsOk())
{
return;
}
CalculateConsumption consumption = consumptionResponse.Data;
CalculateBatchConsumption batchConsumption = response.Data;
LevelInformation levelInformation = LevelInformation.From(delta);
List<CalculateItem> items = CalculateItemHelper.Merge(consumption.AvatarConsume, consumption.AvatarSkillConsume);
try
{
bool saved = await cultivationService
.SaveConsumptionAsync(CultivateType.AvatarAndSkill, avatar.Id, items, levelInformation)
.SaveConsumptionAsync(CultivateType.AvatarAndSkill, avatar.Id, batchConsumption.OverallConsume, levelInformation)
.ConfigureAwait(false);
if (saved)

View File

@@ -20,13 +20,14 @@ using Snap.Hutao.Service.Metadata;
using Snap.Hutao.Service.Notification;
using Snap.Hutao.Service.User;
using Snap.Hutao.View.Dialog;
using Snap.Hutao.ViewModel.User;
using Snap.Hutao.Web.Response;
using System.Collections.Frozen;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using CalculateAvatarPromotionDelta = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.AvatarPromotionDelta;
using CalculateBatchConsumption = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.BatchConsumption;
using CalculateClient = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.CalculateClient;
using CalculateConsumption = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Consumption;
namespace Snap.Hutao.ViewModel.Wiki;
@@ -101,9 +102,7 @@ internal sealed partial class WikiWeaponViewModel : Abstraction.ViewModel
List<Weapon> weapons = await metadataService.GetWeaponListAsync().ConfigureAwait(false);
IEnumerable<Weapon> sorted = weapons
.OrderByDescending(weapon => weapon.RankLevel)
.ThenBy(weapon => weapon.WeaponType)
.ThenByDescending(weapon => weapon.Id.Value);
.OrderByDescending(weapon => weapon.Sort);
List<Weapon> list = [.. sorted];
await CombineComplexDataAsync(list, idMaterialMap).ConfigureAwait(false);
@@ -140,7 +139,7 @@ internal sealed partial class WikiWeaponViewModel : Abstraction.ViewModel
foreach (Weapon weapon in weapons)
{
weapon.Collocation = hutaoCache.WeaponCollocations.GetValueOrDefault(weapon.Id);
weapon.CollocationView = hutaoCache.WeaponCollocations.GetValueOrDefault(weapon.Id);
weapon.CultivationItemsView ??= weapon.CultivationItems.SelectList(i => idMaterialMap.GetValueOrDefault(i, Material.Default));
}
}
@@ -154,7 +153,7 @@ internal sealed partial class WikiWeaponViewModel : Abstraction.ViewModel
return;
}
if (userService.Current is null)
if (!UserAndUid.TryFromUser(userService.Current, out UserAndUid? userAndUid))
{
infoBarService.Warning(SH.MustSelectUserAndUid);
return;
@@ -169,21 +168,21 @@ internal sealed partial class WikiWeaponViewModel : Abstraction.ViewModel
return;
}
Response<CalculateConsumption> consumptionResponse = await calculateClient
.ComputeAsync(userService.Current.Entity, delta)
Response<CalculateBatchConsumption> response = await calculateClient
.BatchComputeAsync(userAndUid, delta)
.ConfigureAwait(false);
if (!consumptionResponse.IsOk())
if (!response.IsOk())
{
return;
}
CalculateConsumption consumption = consumptionResponse.Data;
CalculateBatchConsumption batchConsumption = response.Data;
LevelInformation levelInformation = LevelInformation.From(delta);
try
{
bool saved = await cultivationService
.SaveConsumptionAsync(CultivateType.Weapon, weapon.Id, consumption.WeaponConsume.EmptyIfNull(), levelInformation)
.SaveConsumptionAsync(CultivateType.Weapon, weapon.Id, batchConsumption.OverallConsume, levelInformation)
.ConfigureAwait(false);
if (saved)

View File

@@ -21,11 +21,23 @@ namespace Snap.Hutao.Web.Enka;
internal sealed partial class EnkaClient
{
private const string EnkaAPI = "https://enka.network/api/uid/{0}";
private const string EnkaInfoAPI = "https://enka.network/api/uid/{0}?info";
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly JsonSerializerOptions options;
private readonly HttpClient httpClient;
public ValueTask<EnkaResponse?> GetForwardPlayerInfoAsync(in PlayerUid playerUid, CancellationToken token = default)
{
// TODO
return TryGetEnkaResponseCoreAsync($"https://enka-api.hut.ao/{playerUid}?info", token);
}
public ValueTask<EnkaResponse?> GetPlayerInfoAsync(in PlayerUid playerUid, CancellationToken token = default)
{
return TryGetEnkaResponseCoreAsync(string.Format(CultureInfo.CurrentCulture, EnkaInfoAPI, playerUid), token);
}
public ValueTask<EnkaResponse?> GetForwardDataAsync(in PlayerUid playerUid, CancellationToken token = default)
{
return TryGetEnkaResponseCoreAsync(HutaoEndpoints.Enka(playerUid), token);

View File

@@ -12,5 +12,11 @@ namespace Snap.Hutao.Web.Enka.Model;
internal sealed class ProfilePicture
{
[JsonPropertyName("id")]
public ProfilePictureId Id { get; set; }
public ProfilePictureId ProfilePictureId { get; set; }
[JsonPropertyName("avatarId")]
public AvatarId AvatarId { get; set; }
[JsonPropertyName("costumeId")]
public CostumeId CostumeId { get; set; }
}

View File

@@ -57,6 +57,8 @@ internal sealed class UserGameRole
[JsonPropertyName("is_official")]
public bool IsOfficial { get; set; } = default!;
public string ProfilePictureIcon { get; set; } = default!;
/// <summary>
/// 玩家服务器与等级简述
/// </summary>

View File

@@ -6,13 +6,13 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
internal sealed class BatchConsumption
{
[JsonPropertyName("items")]
public List<Consumption>? Items { get; set; }
public List<Consumption> Items { get; set; } = default!;
[JsonPropertyName("available_material")]
public List<Item>? AvailableMaterial { get; set; }
[JsonPropertyName("overall_consume")]
public List<Item>? OverallConsume { get; set; }
public List<Item> OverallConsume { get; set; } = default!;
[JsonPropertyName("has_user_info")]
public bool HasUserInfo { get; set; }

View File

@@ -19,6 +19,7 @@ internal sealed partial class CalculateClient
private readonly ILogger<CalculateClient> logger;
private readonly HttpClient httpClient;
[Obsolete("Use BatchComputeAsync instead")]
public async ValueTask<Response<Consumption>> ComputeAsync(Model.Entity.User user, AvatarPromotionDelta delta, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -34,15 +35,18 @@ internal sealed partial class CalculateClient
return Response.Response.DefaultIfNull(resp);
}
public async ValueTask<Response<BatchConsumption>> BatchComputeAsync(UserAndUid userAndUid, List<AvatarPromotionDelta> deltas, CancellationToken token = default)
public async ValueTask<Response<BatchConsumption>> BatchComputeAsync(UserAndUid userAndUid, AvatarPromotionDelta delta, bool syncInventory = false, CancellationToken token = default)
{
ArgumentOutOfRangeException.ThrowIfGreaterThan(deltas.Count, 8);
return await BatchComputeAsync(userAndUid, [delta], syncInventory, token).ConfigureAwait(false);
}
public async ValueTask<Response<BatchConsumption>> BatchComputeAsync(UserAndUid userAndUid, List<AvatarPromotionDelta> deltas, bool syncInventory = false, CancellationToken token = default)
{
BatchConsumptionData data = new()
{
Items = deltas,
Region = userAndUid.Uid.Region,
Uid = userAndUid.Uid.ToString(),
Region = syncInventory ? userAndUid.Uid.Region : default!,
Uid = syncInventory ? userAndUid.Uid.ToString() : default!,
};
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()

View File

@@ -42,5 +42,5 @@ internal sealed class Item
public QualityType Level { get; set; }
[JsonPropertyName("lack_num")]
public uint LackNum { get; set; }
public int LackNum { get; set; }
}

View File

@@ -212,6 +212,11 @@ internal static class HutaoEndpoints
return $"{ApiSnapGenshinEnka}/{uid}";
}
public static string EnkaPlayerInfo(in PlayerUid uid)
{
return $"{ApiSnapGenshinEnka}/{uid}/info";
}
public const string Ip = $"{ApiSnapGenshin}/ip";
#region Metadata
@@ -278,7 +283,7 @@ internal static class HutaoEndpoints
public const string WallpaperBing = $"{ApiSnapGenshin}/wallpaper/bing";
public const string WallpaperGenshinLauncher = $"{ApiSnapGenshin}/wallpaper/genshin-launcher";
public const string WallpaperGenshinLauncher = $"{ApiSnapGenshin}/wallpaper/hoyoplay";
public const string WallpaperToday = $"{ApiSnapGenshin}/wallpaper/today";
#endregion
@@ -292,4 +297,5 @@ 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";
}

View File

@@ -1,12 +1,6 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Snap.Hutao.Win32.System.SystemInformation;
internal enum IMAGE_FILE_MACHINE : ushort