Skip to content

Commit

Permalink
display promote level
Browse files Browse the repository at this point in the history
  • Loading branch information
qhy040404 committed Jan 31, 2025
1 parent 26951c5 commit 81c3ec6
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 5 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
using Snap.Hutao.Model.Metadata.Avatar;
using Snap.Hutao.Model.Primitive;
using Snap.Hutao.ViewModel.User;
using Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord;
using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord.Avatar;
using Snap.Hutao.Web.Response;
using System.Collections.Frozen;
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using EntityAvatarInfo = Snap.Hutao.Model.Entity.AvatarInfo;
using CalculableAvatar = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Avatar;

namespace Snap.Hutao.Service.AvatarInfo;

Expand All @@ -40,6 +42,8 @@ public async ValueTask<ImmutableArray<EntityAvatarInfo>> UpdateDbAvatarInfosAsyn
.GetRequiredService<IOverseaSupportFactory<IGameRecordClient>>()
.CreateFor(userAndUid);

CalculateClient calculateClient = scope.ServiceProvider.GetRequiredService<CalculateClient>();

// This is a tricky way to immediately update the avatar info, this behavior
// can change in the future by miHoYo, so it's not recommended to rely on this.
await gameRecordClient.GetPlayerInfoAsync(userAndUid, token).ConfigureAwait(false);
Expand All @@ -63,13 +67,22 @@ public async ValueTask<ImmutableArray<EntityAvatarInfo>> UpdateDbAvatarInfosAsyn
return avatarInfoRepository.GetAvatarInfoImmutableArrayByUid(uid);
}

// We can't obtain avatar promote level from game record,
// but we can obtain it from the calculator.
ImmutableArray<CalculableAvatar> calculableAvatars = await calculateClient
.GetAvatarsAsync(userAndUid, token)
.ConfigureAwait(false);

foreach (DetailedCharacter character in detailsWrapper.List)
{
if (AvatarIds.IsPlayer(character.Base.Id))
{
continue;
}

CalculableAvatar calculableAvatar = calculableAvatars.Single(info => info.Id == character.Base.Id);
character.Base.PromoteLevel = calculableAvatar.PromoteLevel;

// We can only obtain new avatar, and we can't lose the avatar we already have.
// So we don't need to remove any avatar info from the database.
EntityAvatarInfo? entity = dbInfoMap.GetValueOrDefault(character.Base.Id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Snap.Hutao.Core.Abstraction;
using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Metadata.Avatar;
Expand Down Expand Up @@ -102,6 +103,18 @@ public static TBuilder SetNameCard<TBuilder>(this TBuilder builder, Uri nameCard
return builder.Configure(b => b.View.NameCard = nameCard);
}

public static TBuilder SetPromoteList<TBuilder>(this TBuilder builder, PromoteLevel promoteLevel)
where TBuilder : IAvatarViewBuilder
{
bool[] promoteListBuilder = new bool[6];
for (int i = 0; i < promoteLevel; i++)
{
promoteListBuilder[i] = true;
}

return builder.Configure(b => b.View.PromoteList = promoteListBuilder.ToImmutableArray());
}

public static TBuilder SetProperties<TBuilder>(this TBuilder builder, ImmutableArray<AvatarProperty> properties)
where TBuilder : IAvatarViewBuilder
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Primitive;
using Snap.Hutao.ViewModel.AvatarProperty;
using System.Collections.Immutable;

namespace Snap.Hutao.Service.AvatarInfo.Factory.Builder;

Expand Down Expand Up @@ -77,6 +78,18 @@ public static TBuilder SetName<TBuilder>(this TBuilder builder, string name)
return builder.SetName<TBuilder, WeaponView>(name);
}

public static TBuilder SetPromoteList<TBuilder>(this TBuilder builder, PromoteLevel promoteLevel)
where TBuilder : IWeaponViewBuilder
{
bool[] promoteListBuilder = new bool[6];
for (int i = 0; i < promoteLevel; i++)
{
promoteListBuilder[i] = true;
}

return builder.Configure(b => b.View.PromoteList = promoteListBuilder.ToImmutableArray());
}

public static TBuilder SetQuality<TBuilder>(this TBuilder builder, QualityType quality)
where TBuilder : IWeaponViewBuilder
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public AvatarView Create()
.SetReliquaries(character.Relics.SelectAsArray(relic => SummaryReliquaryFactory.Create(context, relic)))
.SetRefreshTimeFormat(refreshTime, obj => string.Format(CultureInfo.CurrentCulture, "{0:MM-dd HH:mm}", obj), SH.ServiceAvatarInfoSummaryNotRefreshed)
.SetCostumeIconOrDefault(character, avatar)
.SetPromoteList(character.Base.PromoteLevel)
.View;

return propertyAvatar;
Expand Down Expand Up @@ -142,6 +143,7 @@ private WeaponView CreateWeapon(DetailedWeapon detailedWeapon)
.SetAffixName(metadataWeapon.Affix?.Name)
.SetAffixDescription(metadataWeapon.Affix?.Descriptions.Single(a => a.Level == (detailedWeapon.AffixLevel - 1)).Description)
.SetWeaponType(metadataWeapon.WeaponType)
.SetPromoteList(detailedWeapon.PromoteLevel)
.View;
}
}
2 changes: 2 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@
<Content Update="Assets\Wide310x150Logo.scale-100.png" />
<Content Update="Assets\Wide310x150Logo.scale-200.png" />
<Content Update="Assets\Wide310x150Logo.scale-400.png" />
<None Remove="Resource\Icon\UI_IconKira.png" />
<Content Include="Resource\Icon\UI_IconKira.png" />
</ItemGroup>

<!-- Resources Files -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,31 @@
Foreground="#FFFFFFFF"
Style="{StaticResource SubtitleTextBlockStyle}"
Text="{Binding Summary.Avatars.CurrentItem.Name}"/>
<ItemsControl Margin="0,2,0,0" ItemsSource="{Binding Summary.Avatars.CurrentItem.PromoteList}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="x:Boolean">
<Grid>
<BitmapIcon
Width="16"
Foreground="#FFFFFFFF"
UriSource="ms-appx:///Resource/Icon/UI_IconKira.png"
Visibility="{Binding}"/>
<BitmapIcon
Width="16"
Foreground="#FF808080"
UriSource="ms-appx:///Resource/Icon/UI_IconKira.png"
Visibility="{Binding Converter={StaticResource BoolToVisibilityRevertConverter}}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="2"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<TextBlock
Margin="0,4,0,0"
Margin="0,2,0,0"
Foreground="#FFFFFFFF"
Style="{StaticResource BaseTextBlockStyle}"
Text="{Binding Summary.Avatars.CurrentItem.Level}"/>
Expand Down Expand Up @@ -762,8 +785,31 @@
Foreground="#FFFFFFFF"
Style="{StaticResource SubtitleTextBlockStyle}"
Text="{Binding Name}"/>
<ItemsControl Margin="0,2,0,0" ItemsSource="{Binding PromoteList}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="x:Boolean">
<Grid>
<BitmapIcon
Width="16"
Foreground="#FFFFFFFF"
UriSource="ms-appx:///Resource/Icon/UI_IconKira.png"
Visibility="{Binding}"/>
<BitmapIcon
Width="16"
Foreground="#FF808080"
UriSource="ms-appx:///Resource/Icon/UI_IconKira.png"
Visibility="{Binding Converter={StaticResource BoolToVisibilityRevertConverter}}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="2"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<TextBlock
Margin="0,4,0,0"
Margin="0,2,0,0"
Foreground="#FFFFFFFF"
Style="{StaticResource BaseTextBlockStyle}"
Text="{Binding Level}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ internal sealed partial class AvatarView : INameIconSide<Uri>,

public string FormattedRefreshTime { get; set; } = default!;

public ImmutableArray<bool> PromoteList { get; set; }

internal AvatarId Id { get; set; }

internal uint LevelNumber { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Snap.Hutao.Model.Calculable;
using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Primitive;
using System.Collections.Immutable;

namespace Snap.Hutao.ViewModel.AvatarProperty;

Expand All @@ -20,6 +21,8 @@ internal sealed class WeaponView : EquipView, ICalculableSource<ICalculableWeapo

public string AffixDescription { get; set; } = default!;

public ImmutableArray<bool> PromoteList { get; set; }

internal WeaponId Id { get; set; }

internal uint LevelNumber { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Primitive;

namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;

Expand All @@ -15,4 +16,7 @@ internal sealed class Avatar : Calculable

[JsonPropertyName("element_attr_id")]
public ElementAttributeId ElementAttrId { get; set; }

[JsonPropertyName("promote_level")]
public PromoteLevel PromoteLevel { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public async ValueTask<Response<BatchConsumption>> BatchComputeAsync(UserAndUid
return Response.Response.DefaultIfNull(resp);
}

public async ValueTask<List<Avatar>> GetAvatarsAsync(UserAndUid userAndUid, CancellationToken token = default)
public async ValueTask<ImmutableArray<Avatar>> GetAvatarsAsync(UserAndUid userAndUid, CancellationToken token = default)
{
int currentPage = 1;
SyncAvatarFilter filter = new() { Uid = userAndUid.Uid.Value, Region = userAndUid.Uid.Region };

List<Avatar> avatars = [];
ImmutableArray<Avatar>.Builder avatars = ImmutableArray.CreateBuilder<Avatar>();
Response<ListWrapper<Avatar>>? resp;

IApiEndpoints apiEndpoints = apiEndpointsFactory.Create(userAndUid.IsOversea);
Expand Down Expand Up @@ -92,7 +92,7 @@ public async ValueTask<List<Avatar>> GetAvatarsAsync(UserAndUid userAndUid, Canc
}
while (resp.Data is { List.Length: 20 });

return avatars;
return avatars.ToImmutable();
}

public async ValueTask<Response<AvatarDetail>> GetAvatarDetailAsync(UserAndUid userAndUid, Avatar avatar, CancellationToken token = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ internal class Avatar
[JsonPropertyName("actived_constellation_num")]
public int ActivedConstellationNum { get; set; }

// late-init field
[JsonPropertyName("promote_level")]
public PromoteLevel PromoteLevel { get; set; }

// Ignored field: string image
// Ignored field: string card_image
// Ignored field: bool is_chosen
Expand Down

0 comments on commit 81c3ec6

Please sign in to comment.