spiral abyss using metadata context

This commit is contained in:
DismissedLight
2024-07-24 13:35:47 +08:00
parent 4ef65a2811
commit 1bc7786dcb
11 changed files with 98 additions and 27 deletions

View File

@@ -27,28 +27,20 @@ internal sealed partial class HutaoSpiralAbyssStatisticsCache : IHutaoSpiralAbys
private TaskCompletionSource<bool>? wikiAvatarViewModelTaskSource;
private TaskCompletionSource<bool>? wikiWeaponViewModelTaskSource;
/// <inheritdoc/>
public List<AvatarRankView>? AvatarUsageRanks { get; set; }
/// <inheritdoc/>
public List<AvatarRankView>? AvatarAppearanceRanks { get; set; }
/// <inheritdoc/>
public List<AvatarConstellationInfoView>? AvatarConstellationInfos { get; set; }
/// <inheritdoc/>
public List<TeamAppearanceView>? TeamAppearances { get; set; }
/// <inheritdoc/>
public Overview? Overview { get; set; }
/// <inheritdoc/>
public Dictionary<AvatarId, AvatarCollocationView>? AvatarCollocations { get; set; }
/// <inheritdoc/>
public Dictionary<WeaponId, WeaponCollocationView>? WeaponCollocations { get; set; }
/// <inheritdoc/>
public async ValueTask<bool> InitializeForSpiralAbyssViewAsync()
{
if (databaseViewModelTaskSource is not null)

View File

@@ -0,0 +1,8 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Service.Metadata.ContextAbstraction;
internal interface IMetadataDictionaryIdAvatarWithPlayersSource : IMetadataDictionaryIdAvatarSource
{
}

View File

@@ -0,0 +1,12 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Metadata.Tower;
using Snap.Hutao.Model.Primitive;
namespace Snap.Hutao.Service.Metadata.ContextAbstraction;
internal interface IMetadataDictionaryIdListTowerLevelSource
{
Dictionary<TowerLevelGroupId, List<TowerLevel>> IdListTowerLevelMap { get; set; }
}

View File

@@ -0,0 +1,12 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Metadata.Monster;
using Snap.Hutao.Model.Primitive;
namespace Snap.Hutao.Service.Metadata.ContextAbstraction;
internal interface IMetadataDictionaryIdMonsterSource
{
Dictionary<MonsterRelationshipId, Monster> IdMonsterMap { get; set; }
}

View File

@@ -0,0 +1,12 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Metadata.Tower;
using Snap.Hutao.Model.Primitive;
namespace Snap.Hutao.Service.Metadata.ContextAbstraction;
internal interface IMetadataDictionaryIdTowerFloorSource
{
Dictionary<TowerFloorId, TowerFloor> IdTowerFloorMap { get; set; }
}

View File

@@ -0,0 +1,12 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Metadata.Tower;
using Snap.Hutao.Model.Primitive;
namespace Snap.Hutao.Service.Metadata.ContextAbstraction;
internal interface IMetadataDictionaryIdTowerScheduleSource
{
Dictionary<TowerScheduleId, TowerSchedule> IdTowerScheduleMap { get; set; }
}

View File

@@ -1,6 +1,7 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Metadata;
using Snap.Hutao.Model.Metadata.Avatar;
using Snap.Hutao.Model.Metadata.Item;
using Snap.Hutao.Model.Metadata.Weapon;
@@ -64,6 +65,16 @@ internal static class MetadataServiceContextExtension
if (context is IMetadataDictionaryIdAvatarSource dictionaryIdAvatarSource)
{
dictionaryIdAvatarSource.IdAvatarMap = await metadataService.GetIdToAvatarMapAsync(token).ConfigureAwait(false);
if (context is IMetadataDictionaryIdAvatarWithPlayersSource)
{
dictionaryIdAvatarSource.IdAvatarMap = AvatarIds.WithPlayers(dictionaryIdAvatarSource.IdAvatarMap);
}
}
if (context is IMetadataDictionaryIdListTowerLevelSource dictionaryIdListTowerLevelSource)
{
dictionaryIdListTowerLevelSource.IdListTowerLevelMap = await metadataService.GetGroupIdToTowerLevelGroupMapAsync(token).ConfigureAwait(false);
}
if (context is IMetadataDictionaryIdMaterialSource dictionaryIdMaterialSource)
@@ -71,6 +82,11 @@ internal static class MetadataServiceContextExtension
dictionaryIdMaterialSource.IdMaterialMap = await metadataService.GetIdToMaterialMapAsync(token).ConfigureAwait(false);
}
if (context is IMetadataDictionaryIdMonsterSource dictionaryIdMonsterSource)
{
dictionaryIdMonsterSource.IdMonsterMap = await metadataService.GetRelationshipIdToMonsterMapAsync(token).ConfigureAwait(false);
}
if (context is IMetadataDictionaryIdReliquarySource dictionaryIdReliquarySource)
{
dictionaryIdReliquarySource.IdReliquaryMap = await metadataService.GetIdToReliquaryMapAsync(token).ConfigureAwait(false);
@@ -96,6 +112,16 @@ internal static class MetadataServiceContextExtension
dictionaryIdReliquarySubAffixSource.IdReliquarySubAffixMap = await metadataService.GetIdToReliquarySubAffixMapAsync(token).ConfigureAwait(false);
}
if (context is IMetadataDictionaryIdTowerFloorSource dictionaryIdTowerFloorSource)
{
dictionaryIdTowerFloorSource.IdTowerFloorMap = await metadataService.GetIdToTowerFloorMapAsync(token).ConfigureAwait(false);
}
if (context is IMetadataDictionaryIdTowerScheduleSource dictionaryIdTowerScheduleSource)
{
dictionaryIdTowerScheduleSource.IdTowerScheduleMap = await metadataService.GetIdToTowerScheduleMapAsync(token).ConfigureAwait(false);
}
if (context is IMetadataDictionaryIdWeaponSource dictionaryIdWeaponSource)
{
dictionaryIdWeaponSource.IdWeaponMap = await metadataService.GetIdToWeaponMapAsync(token).ConfigureAwait(false);

View File

@@ -3,8 +3,8 @@
using Snap.Hutao.Core.DependencyInjection.Abstraction;
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Model.Metadata;
using Snap.Hutao.Service.Metadata;
using Snap.Hutao.Service.Metadata.ContextAbstraction;
using Snap.Hutao.ViewModel.SpiralAbyss;
using Snap.Hutao.ViewModel.User;
using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord;
@@ -34,15 +34,7 @@ internal sealed partial class SpiralAbyssRecordService : ISpiralAbyssRecordServi
{
if (await metadataService.InitializeAsync().ConfigureAwait(false))
{
// TODO replace to IMetadataContext
metadataContext = new()
{
IdScheduleMap = await metadataService.GetIdToTowerScheduleMapAsync().ConfigureAwait(false),
IdFloorMap = await metadataService.GetIdToTowerFloorMapAsync().ConfigureAwait(false),
IdLevelGroupMap = await metadataService.GetGroupIdToTowerLevelGroupMapAsync().ConfigureAwait(false),
IdMonsterMap = await metadataService.GetRelationshipIdToMonsterMapAsync().ConfigureAwait(false),
IdAvatarMap = AvatarIds.WithPlayers(await metadataService.GetIdToAvatarMapAsync().ConfigureAwait(false)),
};
metadataContext = await metadataService.GetContextAsync<SpiralAbyssMetadataContext>().ConfigureAwait(false);
return true;
}
@@ -64,7 +56,7 @@ internal sealed partial class SpiralAbyssRecordService : ISpiralAbyssRecordServi
Dictionary<uint, SpiralAbyssEntry> entryMap = spiralAbyssRecordDbService.GetSpiralAbyssEntryMapByUid(userAndUid.Uid.Value);
ArgumentNullException.ThrowIfNull(metadataContext);
spiralAbysses = metadataContext.IdScheduleMap.Values
spiralAbysses = metadataContext.IdTowerScheduleMap.Values
.Select(sch => SpiralAbyssView.From(entryMap.GetValueOrDefault(sch.Id), sch, metadataContext))
.OrderByDescending(e => e.ScheduleId)
.ToObservableCollection();

View File

@@ -18,7 +18,7 @@ internal sealed class FloorView : IMappingFrom<FloorView, TowerFloor, SpiralAbys
IndexValue = floor.Index;
Disorders = floor.Descriptions;
Levels = context.IdLevelGroupMap[floor.LevelGroupId].SortBy(l => l.Index).SelectList(l => LevelView.From(l, context));
Levels = context.IdListTowerLevelMap[floor.LevelGroupId].SortBy(l => l.Index).SelectList(l => LevelView.From(l, context));
}
public bool Engaged { get; private set; }

View File

@@ -5,17 +5,22 @@ using Snap.Hutao.Model.Metadata.Avatar;
using Snap.Hutao.Model.Metadata.Monster;
using Snap.Hutao.Model.Metadata.Tower;
using Snap.Hutao.Model.Primitive;
using Snap.Hutao.Service.Metadata.ContextAbstraction;
namespace Snap.Hutao.ViewModel.SpiralAbyss;
// TODO: replace this
internal sealed class SpiralAbyssMetadataContext
internal sealed class SpiralAbyssMetadataContext : IMetadataContext,
IMetadataDictionaryIdTowerScheduleSource,
IMetadataDictionaryIdTowerFloorSource,
IMetadataDictionaryIdListTowerLevelSource,
IMetadataDictionaryIdMonsterSource,
IMetadataDictionaryIdAvatarWithPlayersSource
{
public Dictionary<TowerScheduleId, TowerSchedule> IdScheduleMap { get; set; } = default!;
public Dictionary<TowerScheduleId, TowerSchedule> IdTowerScheduleMap { get; set; } = default!;
public Dictionary<TowerFloorId, TowerFloor> IdFloorMap { get; set; } = default!;
public Dictionary<TowerFloorId, TowerFloor> IdTowerFloorMap { get; set; } = default!;
public Dictionary<TowerLevelGroupId, List<TowerLevel>> IdLevelGroupMap { get; set; } = default!;
public Dictionary<TowerLevelGroupId, List<TowerLevel>> IdListTowerLevelMap { get; set; } = default!;
public Dictionary<MonsterRelationshipId, Monster> IdMonsterMap { get; set; } = default!;

View File

@@ -17,7 +17,7 @@ internal sealed partial class SpiralAbyssView : IEntityAccess<SpiralAbyssEntry?>
private readonly SpiralAbyssEntry? entity;
private SpiralAbyssView(SpiralAbyssEntry entity, SpiralAbyssMetadataContext context)
: this(context.IdScheduleMap[entity.ScheduleId], context)
: this(context.IdTowerScheduleMap[entity.ScheduleId], context)
{
this.entity = entity;
@@ -50,7 +50,7 @@ internal sealed partial class SpiralAbyssView : IEntityAccess<SpiralAbyssEntry?>
BlessingName = towerSchedule.BuffName;
Blessings = towerSchedule.Descriptions;
Floors = towerSchedule.FloorIds.Select(id => FloorView.From(context.IdFloorMap[id], context)).Reverse().ToList();
Floors = towerSchedule.FloorIds.Select(id => FloorView.From(context.IdTowerFloorMap[id], context)).Reverse().ToList();
}
public uint ScheduleId { get; }