Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx committed Oct 17, 2024
1 parent 343f401 commit ecc5117
Show file tree
Hide file tree
Showing 20 changed files with 56 additions and 41 deletions.
1 change: 1 addition & 0 deletions src/Snap.Hutao/Snap.Hutao/Core/RuntimeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Snap.Hutao.Core;

[Obsolete("This class only exist for binding purpose")]
[Injection(InjectAs.Singleton)]
internal sealed class RuntimeOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Snap.Hutao.Model.Metadata.Converter;

internal static class BaseValueInfoFormat
{
public static NameValue<string> ToNameValue(PropertyCurveValue propValue, Level level, PromoteLevel promoteLevel, ImmutableDictionary<Level, ImmutableDictionary<GrowCurveType, float>> growCurveMap, ImmutableDictionary<PromoteLevel, Promote>? promoteMap)
public static NameValue<string> ToNameValue(PropertyCurveValue propValue, Level level, PromoteLevel promoteLevel, ImmutableDictionary<Level, TypeValueCollection<GrowCurveType, float>> growCurveMap, ImmutableDictionary<PromoteLevel, Promote>? promoteMap)
{
float value = propValue.Value * growCurveMap[level].GetValueOrDefault(propValue.Type);
if (promoteMap is not null)
Expand Down
9 changes: 0 additions & 9 deletions src/Snap.Hutao/Snap.Hutao/Model/Metadata/GrowCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,7 @@ namespace Snap.Hutao.Model.Metadata;

internal sealed class GrowCurve
{
[Obsolete("Use Curves instead.")]
private ImmutableDictionary<GrowCurveType, float>? map;

public Level Level { get; set; }

public TypeValueCollection<GrowCurveType, float> Curves { get; set; } = default!;

[Obsolete("Use Curves instead.")]
public ImmutableDictionary<GrowCurveType, float> Map
{
get => map ??= Curves.ToImmutableDictionary(v => v.Type, v => v.Value);
}
}
19 changes: 19 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/Model/Metadata/TypeValueCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ public bool IsReadOnly

public int Count { get => inner.Count; }

public IEnumerable<TType> Keys { get => inner.Keys; }

public IEnumerable<TValue> Values { get => inner.Values; }

public TValue this[TType key] { get => inner[key]; }

IEnumerator<TypeValue<TType, TValue>> IEnumerable<TypeValue<TType, TValue>>.GetEnumerator()
{
return new TypeValueEnumerator(inner.GetEnumerator());
}

[Obsolete("avoid perform this operation on this collection", true)]
public void Add(TypeValue<TType, TValue> item)
{
inner.Add(item.Type, item.Value);
Expand All @@ -38,11 +45,13 @@ public void CopyTo(TypeValue<TType, TValue>[] array, int arrayIndex)
HutaoException.NotSupported();
}

[Obsolete("avoid perform this operation on this collection", true)]
public bool Remove(TypeValue<TType, TValue> item)
{
return Contains(item) && inner.Remove(item.Type);
}

[Obsolete("avoid perform this operation on this collection", true)]
public void Clear()
{
inner.Clear();
Expand All @@ -58,6 +67,16 @@ public IEnumerator GetEnumerator()
return inner.GetValueOrDefault(type);
}

public bool ContainsKey(TType key)
{
return inner.ContainsKey(key);
}

public bool TryGetValue(TType key, [MaybeNullWhen(false)] out TValue value)
{
return inner.TryGetValue(key, out value);
}

private struct TypeValueEnumerator : IEnumerator<TypeValue<TType, TValue>>
{
private SortedDictionary<TType, TValue>.Enumerator inner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal sealed class SummaryFactoryMetadataContext : IMetadataContext,

public ImmutableDictionary<ReliquaryId, MetadataReliquary> IdReliquaryMap { get; set; } = default!;

public ImmutableDictionary<Level, ImmutableDictionary<GrowCurveType, float>> LevelDictionaryWeaponGrowCurveMap { get; set; } = default!;
public ImmutableDictionary<Level, TypeValueCollection<GrowCurveType, float>> LevelDictionaryWeaponGrowCurveMap { get; set; } = default!;

public ImmutableDictionary<PromoteId, ImmutableDictionary<PromoteLevel, Promote>> IdDictionaryWeaponLevelPromoteMap { get; set; } = default!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public async ValueTask<GachaArchive> EnsureArchiveInCollectionAsync(Guid archive
.GetGachaLogPageAsync(fetchContext.TypedQueryOptions, token)
.ConfigureAwait(false);

if (!response.TryGetData(out GachaLogPage? page))
if (!ResponseValidator.TryValidateWithoutUINotification(response, out GachaLogPage? page))
{
fetchContext.Report(progress, isAuthKeyTimeout: true);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,23 @@ private static async ValueTask<bool> EnsureGameResourceAsync(LaunchExecutionCont

// We perform these requests before package conversion to ensure resources index is intact.
Response<GamePackagesWrapper> packagesResponse = await hoyoPlayClient.GetPackagesAsync(context.Scheme).ConfigureAwait(false);
if (!packagesResponse.TryGetDataWithoutUINotification(out GamePackagesWrapper? gamePackages))
if (!ResponseValidator.TryValidateWithoutUINotification(packagesResponse, out GamePackagesWrapper? gamePackages))
{
context.Result.Kind = LaunchExecutionResultKind.GameResourceIndexQueryInvalidResponse;
context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(packagesResponse);
return false;
}

Response<GameChannelSDKsWrapper> sdkResponse = await hoyoPlayClient.GetChannelSDKAsync(context.Scheme).ConfigureAwait(false);
if (!sdkResponse.TryGetDataWithoutUINotification(out GameChannelSDKsWrapper? channelSDKs))
if (!ResponseValidator.TryValidateWithoutUINotification(sdkResponse, out GameChannelSDKsWrapper? channelSDKs))
{
context.Result.Kind = LaunchExecutionResultKind.GameResourceIndexQueryInvalidResponse;
context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(sdkResponse);
return false;
}

Response<DeprecatedFileConfigurationsWrapper> deprecatedFileResponse = await hoyoPlayClient.GetDeprecatedFileConfigurationsAsync(context.Scheme).ConfigureAwait(false);
if (!deprecatedFileResponse.TryGetDataWithoutUINotification(out DeprecatedFileConfigurationsWrapper? deprecatedFileConfigs))
if (!ResponseValidator.TryValidateWithoutUINotification(deprecatedFileResponse, out DeprecatedFileConfigurationsWrapper? deprecatedFileConfigs))
{
context.Result.Kind = LaunchExecutionResultKind.GameResourceIndexQueryInvalidResponse;
context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(deprecatedFileResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Licensed under the MIT license.

using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Metadata;
using Snap.Hutao.Model.Primitive;
using System.Collections.Immutable;

namespace Snap.Hutao.Service.Metadata.ContextAbstraction;

internal interface IMetadataDictionaryLevelAvaterGrowCurveSource
{
ImmutableDictionary<Level, ImmutableDictionary<GrowCurveType, float>> LevelDictionaryAvatarGrowCurveMap { get; set; }
ImmutableDictionary<Level, TypeValueCollection<GrowCurveType, float>> LevelDictionaryAvatarGrowCurveMap { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Licensed under the MIT license.

using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Metadata;
using Snap.Hutao.Model.Primitive;
using System.Collections.Immutable;

namespace Snap.Hutao.Service.Metadata.ContextAbstraction;

internal interface IMetadataDictionaryLevelMonsterGrowCurveSource
{
ImmutableDictionary<Level, ImmutableDictionary<GrowCurveType, float>> LevelDictionaryMonsterGrowCurveMap { get; set; }
ImmutableDictionary<Level, TypeValueCollection<GrowCurveType, float>> LevelDictionaryMonsterGrowCurveMap { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Licensed under the MIT license.

using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Metadata;
using Snap.Hutao.Model.Primitive;
using System.Collections.Immutable;

namespace Snap.Hutao.Service.Metadata.ContextAbstraction;

internal interface IMetadataDictionaryLevelWeaponGrowCurveSource
{
ImmutableDictionary<Level, ImmutableDictionary<GrowCurveType, float>> LevelDictionaryWeaponGrowCurveMap { get; set; }
ImmutableDictionary<Level, TypeValueCollection<GrowCurveType, float>> LevelDictionaryWeaponGrowCurveMap { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,30 +169,30 @@ public static ValueTask<ImmutableDictionary<PromoteId, ImmutableDictionary<Promo
token);
}

public static ValueTask<ImmutableDictionary<Level, ImmutableDictionary<GrowCurveType, float>>> GetLevelToAvatarCurveMapAsync(this IMetadataService metadataService, CancellationToken token = default)
public static ValueTask<ImmutableDictionary<Level, TypeValueCollection<GrowCurveType, float>>> GetLevelToAvatarCurveMapAsync(this IMetadataService metadataService, CancellationToken token = default)
{
return metadataService.FromCacheAsDictionaryAsync<GrowCurve, Level, ImmutableDictionary<GrowCurveType, float>>(
return metadataService.FromCacheAsDictionaryAsync<GrowCurve, Level, TypeValueCollection<GrowCurveType, float>>(
MetadataFileStrategies.AvatarCurve,
a => a.Level,
a => a.Map,
a => a.Curves,
token);
}

public static ValueTask<ImmutableDictionary<Level, ImmutableDictionary<GrowCurveType, float>>> GetLevelToMonsterCurveMapAsync(this IMetadataService metadataService, CancellationToken token = default)
public static ValueTask<ImmutableDictionary<Level, TypeValueCollection<GrowCurveType, float>>> GetLevelToMonsterCurveMapAsync(this IMetadataService metadataService, CancellationToken token = default)
{
return metadataService.FromCacheAsDictionaryAsync<GrowCurve, Level, ImmutableDictionary<GrowCurveType, float>>(
return metadataService.FromCacheAsDictionaryAsync<GrowCurve, Level, TypeValueCollection<GrowCurveType, float>>(
MetadataFileStrategies.MonsterCurve,
m => m.Level,
m => m.Map,
m => m.Curves,
token);
}

public static ValueTask<ImmutableDictionary<Level, ImmutableDictionary<GrowCurveType, float>>> GetLevelToWeaponCurveMapAsync(this IMetadataService metadataService, CancellationToken token = default)
public static ValueTask<ImmutableDictionary<Level, TypeValueCollection<GrowCurveType, float>>> GetLevelToWeaponCurveMapAsync(this IMetadataService metadataService, CancellationToken token = default)
{
return metadataService.FromCacheAsDictionaryAsync<GrowCurve, Level, ImmutableDictionary<GrowCurveType, float>>(
return metadataService.FromCacheAsDictionaryAsync<GrowCurve, Level, TypeValueCollection<GrowCurveType, float>>(
MetadataFileStrategies.WeaponCurve,
w => w.Level,
w => w.Map,
w => w.Curves,
token);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
HeaderIcon="{shuxm:FontIcon Glyph=&#xE748;}"
IsClickEnabled="True"
IsEnabled="{Binding LaunchOptions.UsingHoyolabAccount, Converter={StaticResource BoolNegationConverter}}"/>
<Border Style="{StaticResource BorderCardStyle}">
<Border Style="{StaticResource BorderCardStyle}" Visibility="{Binding GameAccountsView.Count, Converter={StaticResource Int32ToVisibilityConverter}}">
<ListView
Padding="{StaticResource ListViewInSplitPanePadding}"
AllowDrop="{Binding RuntimeOptions.IsElevated, Converter={StaticResource BoolNegationConverter}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private async Task RegisterAsync()
if (ResponseValidator.TryValidate(response, infoBarService, out string? token))
{
infoBarService.Information(response.GetLocalizationMessageOrMessage());
await hutaoUserOptions.PostLoginSucceedAsync(hutaoPassportClient, taskContext, username, password, token).ConfigureAwait(false);
await hutaoUserOptions.PostLoginSucceedAsync(scope.ServiceProvider, username, password, token).ConfigureAwait(false);
}
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ private async Task LoginAsync()
if (ResponseValidator.TryValidate(response, infoBarService, out string? token))
{
infoBarService.Information(response.GetLocalizationMessageOrMessage());
await hutaoUserOptions.PostLoginSucceedAsync(hutaoPassportClient, taskContext, username, password, token).ConfigureAwait(false);
await hutaoUserOptions.PostLoginSucceedAsync(scope.ServiceProvider, username, password, token).ConfigureAwait(false);
}
}
}
Expand Down Expand Up @@ -168,7 +168,7 @@ private async Task ResetPasswordAsync()
if (ResponseValidator.TryValidate(response, infoBarService, out string? token))
{
infoBarService.Information(response.GetLocalizationMessageOrMessage());
await hutaoUserOptions.PostLoginSucceedAsync(hutaoPassportClient, taskContext, username, password, token).ConfigureAwait(false);
await hutaoUserOptions.PostLoginSucceedAsync(scope.ServiceProvider, username, password, token).ConfigureAwait(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private async Task OpenBackgroundImageFolderAsync()
[Command("SetDataFolderCommand")]
private void SetDataFolder()
{
if (fileSystemPickerInteraction.PickFolder().TryGetValue(out string folder))
if (fileSystemPickerInteraction.PickFolder().TryGetValue(out string? folder))
{
LocalSetting.Set(SettingKeys.DataFolderPath, folder);
infoBarService.Success(SH.ViewModelSettingSetDataFolderSuccess);
Expand Down
4 changes: 2 additions & 2 deletions src/Snap.Hutao/Snap.Hutao/ViewModel/Wiki/BaseValueInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ namespace Snap.Hutao.ViewModel.Wiki;
internal sealed partial class BaseValueInfo : ObservableObject
{
private readonly List<PropertyCurveValue> propValues;
private readonly ImmutableDictionary<Level, ImmutableDictionary<GrowCurveType, float>> growCurveMap;
private readonly ImmutableDictionary<Level, TypeValueCollection<GrowCurveType, float>> growCurveMap;
private readonly ImmutableDictionary<PromoteLevel, Promote>? promoteMap;

private uint currentLevel;
private List<NameValue<string>> values = default!;
private bool promoted = true;

public BaseValueInfo(uint maxLevel, List<PropertyCurveValue> propValues, ImmutableDictionary<Level, ImmutableDictionary<GrowCurveType, float>> growCurveMap, ImmutableDictionary<PromoteLevel, Promote>? promoteMap = null)
public BaseValueInfo(uint maxLevel, List<PropertyCurveValue> propValues, ImmutableDictionary<Level, TypeValueCollection<GrowCurveType, float>> growCurveMap, ImmutableDictionary<PromoteLevel, Promote>? promoteMap = null)
{
this.propValues = propValues;
this.growCurveMap = growCurveMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal sealed class WikiAvatarMetadataContext : IMetadataContext,
IMetadataDictionaryIdMaterialSource,
IMetadataArrayAvatarSource
{
public ImmutableDictionary<Level, ImmutableDictionary<GrowCurveType, float>> LevelDictionaryAvatarGrowCurveMap { get; set; } = default!;
public ImmutableDictionary<Level, TypeValueCollection<GrowCurveType, float>> LevelDictionaryAvatarGrowCurveMap { get; set; } = default!;

public ImmutableDictionary<PromoteId, ImmutableDictionary<PromoteLevel, Promote>> IdDictionaryAvatarLevelPromoteMap { get; set; } = default!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using Snap.Hutao.Factory.ContentDialog;
using Snap.Hutao.Model.Calculable;
using Snap.Hutao.Model.Entity.Primitive;
using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Intrinsic.Frozen;
using Snap.Hutao.Model.Metadata;
using Snap.Hutao.Model.Metadata.Avatar;
using Snap.Hutao.Model.Metadata.Converter;
using Snap.Hutao.Model.Metadata.Item;
Expand Down Expand Up @@ -173,13 +175,12 @@ private async Task CultivateAsync(Avatar? avatar)
CalculateClient calculateClient = scope.ServiceProvider.GetRequiredService<CalculateClient>();
Response<CalculateBatchConsumption> response = await calculateClient.BatchComputeAsync(userAndUid, deltaOptions.Delta).ConfigureAwait(false);

if (!ResponseValidator.TryValidate(response,scope.ServiceProvider, out batchConsumption))
if (!ResponseValidator.TryValidate(response, scope.ServiceProvider, out batchConsumption))
{
return;
}
}

CalculateBatchConsumption batchConsumption = response.Data;
LevelInformation levelInformation = LevelInformation.From(deltaOptions.Delta);
try
{
Expand Down Expand Up @@ -217,7 +218,7 @@ private void UpdateBaseValueInfo(Avatar? avatar)

BaseValueInfo = new(
avatar.MaxLevel,
avatar.GrowCurves.Select(info => new PropertyCurveValue(info.Type, info.Value, avatar.BaseValue.GetValue(info.Type))).ToList(),
avatar.GrowCurves.Select<TypeValue<FightProperty, GrowCurveType>, PropertyCurveValue>(info => new PropertyCurveValue(info.Type, info.Value, avatar.BaseValue.GetValue(info.Type))).ToList(),
metadataContext.LevelDictionaryAvatarGrowCurveMap,
metadataContext.IdDictionaryAvatarLevelPromoteMap[avatar.PromoteId]);
}
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.Metadata;
using Snap.Hutao.Model.Metadata.Item;
using Snap.Hutao.Model.Metadata.Monster;
using Snap.Hutao.Model.Primitive;
Expand All @@ -15,7 +16,7 @@ internal sealed class WikiMonsterMetadataContext : IMetadataContext,
IMetadataArrayMonsterSource,
IMetadataDictionaryIdDisplayItemAndMaterialSource
{
public ImmutableDictionary<Level, ImmutableDictionary<GrowCurveType, float>> LevelDictionaryMonsterGrowCurveMap { get; set; } = default!;
public ImmutableDictionary<Level, TypeValueCollection<GrowCurveType, float>> LevelDictionaryMonsterGrowCurveMap { get; set; } = default!;

public ImmutableArray<Monster> Monsters { get; set; } = default!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal sealed class WikiWeaponMetadataContext : IMetadataContext,
IMetadataDictionaryIdMaterialSource,
IMetadataArrayWeaponSource
{
public ImmutableDictionary<Level, ImmutableDictionary<GrowCurveType, float>> LevelDictionaryWeaponGrowCurveMap { get; set; } = default!;
public ImmutableDictionary<Level, TypeValueCollection<GrowCurveType, float>> LevelDictionaryWeaponGrowCurveMap { get; set; } = default!;

public ImmutableDictionary<PromoteId, ImmutableDictionary<PromoteLevel, Promote>> IdDictionaryWeaponLevelPromoteMap { get; set; } = default!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ private async Task CultivateAsync(Weapon? weapon)
}
}

CalculateBatchConsumption batchConsumption = response.Data;
LevelInformation levelInformation = LevelInformation.From(deltaOptions.Delta);
try
{
Expand Down

0 comments on commit ecc5117

Please sign in to comment.