From 96b6f070810feaa0f7e69a408700d962e6b774ab Mon Sep 17 00:00:00 2001 From: Katter Date: Fri, 6 Sep 2024 19:28:35 +0500 Subject: [PATCH] Merge Poser2DDataSetReplicator and Poser3DDataSetReplicator weights replication code --- .../DataSets/Poser2DDataSetReplicator.cs | 28 +---------------- .../DataSets/Poser3DDataSetReplicator.cs | 28 +---------------- .../DataSets/PoserDataSetReplicator.cs | 30 ++++++++++++++++++- 3 files changed, 31 insertions(+), 55 deletions(-) diff --git a/SightKeeper.Data/Binary/Replication/DataSets/Poser2DDataSetReplicator.cs b/SightKeeper.Data/Binary/Replication/DataSets/Poser2DDataSetReplicator.cs index 1eb9af24..4b9c1656 100644 --- a/SightKeeper.Data/Binary/Replication/DataSets/Poser2DDataSetReplicator.cs +++ b/SightKeeper.Data/Binary/Replication/DataSets/Poser2DDataSetReplicator.cs @@ -1,16 +1,14 @@ using System.Collections.Immutable; using SightKeeper.Data.Binary.Model.DataSets.Assets; -using SightKeeper.Data.Binary.Model.DataSets.Weights; using SightKeeper.Data.Binary.Services; using SightKeeper.Domain.Model; using SightKeeper.Domain.Model.DataSets.Assets; using SightKeeper.Domain.Model.DataSets.Poser2D; using SightKeeper.Domain.Model.DataSets.Screenshots; -using SightKeeper.Domain.Model.DataSets.Weights; namespace SightKeeper.Data.Binary.Replication.DataSets; -internal sealed class Poser2DDataSetReplicator : PoserDataSetReplicator +internal sealed class Poser2DDataSetReplicator : PoserDataSetReplicator { public Poser2DDataSetReplicator(FileSystemScreenshotsDataAccess screenshotsDataAccess) : base(screenshotsDataAccess) { @@ -42,28 +40,4 @@ protected override void ReplicateAsset(AssetsLibrary library, PackableAsset pack packedItem.NumericProperties); } } - - protected override void ReplicateWeights(WeightsLibrary library, PackableWeights weights, TagGetter getTag) - { - var typedLibrary = (WeightsLibrary)library; - var typedWeights = (PackablePoserWeights)weights; - var tags = GetTags(typedWeights, getTag); - typedLibrary.CreateWeights(weights.CreationDate, weights.ModelSize, weights.Metrics, weights.Resolution, tags); - } - - private static IEnumerable<(Poser2DTag, IEnumerable)> GetTags(PackablePoserWeights weights, TagGetter getTag) - { - foreach (var (tagId, keyPointTagIds) in weights.Tags) - { - var tag = (Poser2DTag)getTag(tagId); - var keyPointTags = GetKeyPointTags(tagId, keyPointTagIds, getTag); - yield return (tag, keyPointTags); - } - } - - private static IEnumerable GetKeyPointTags(byte tagId, IEnumerable keyPointTagIds, TagGetter getTag) - { - foreach (var keyPointTagId in keyPointTagIds) - yield return (KeyPointTag2D)getTag(tagId, keyPointTagId); - } } \ No newline at end of file diff --git a/SightKeeper.Data/Binary/Replication/DataSets/Poser3DDataSetReplicator.cs b/SightKeeper.Data/Binary/Replication/DataSets/Poser3DDataSetReplicator.cs index 93f6ec72..6a306d3d 100644 --- a/SightKeeper.Data/Binary/Replication/DataSets/Poser3DDataSetReplicator.cs +++ b/SightKeeper.Data/Binary/Replication/DataSets/Poser3DDataSetReplicator.cs @@ -1,16 +1,14 @@ using System.Collections.Immutable; using SightKeeper.Data.Binary.Model.DataSets.Assets; -using SightKeeper.Data.Binary.Model.DataSets.Weights; using SightKeeper.Data.Binary.Services; using SightKeeper.Domain.Model; using SightKeeper.Domain.Model.DataSets.Assets; using SightKeeper.Domain.Model.DataSets.Poser3D; using SightKeeper.Domain.Model.DataSets.Screenshots; -using SightKeeper.Domain.Model.DataSets.Weights; namespace SightKeeper.Data.Binary.Replication.DataSets; -internal sealed class Poser3DDataSetReplicator : PoserDataSetReplicator +internal sealed class Poser3DDataSetReplicator : PoserDataSetReplicator { public Poser3DDataSetReplicator(FileSystemScreenshotsDataAccess screenshotsDataAccess) : base(screenshotsDataAccess) { @@ -44,28 +42,4 @@ protected override void ReplicateAsset(AssetsLibrary library, PackableAsset pack packedItem.BooleanProperties); } } - - protected override void ReplicateWeights(WeightsLibrary library, PackableWeights weights, TagGetter getTag) - { - var typedLibrary = (WeightsLibrary)library; - var typedWeights = (PackablePoserWeights)weights; - var tags = GetTags(typedWeights, getTag); - typedLibrary.CreateWeights(weights.CreationDate, weights.ModelSize, weights.Metrics, weights.Resolution, tags); - } - - private static IEnumerable<(Poser3DTag, IEnumerable)> GetTags(PackablePoserWeights weights, TagGetter getTag) - { - foreach (var (tagId, keyPointTagIds) in weights.Tags) - { - var tag = (Poser3DTag)getTag(tagId); - var keyPointTags = GetKeyPointTags(tagId, keyPointTagIds, getTag); - yield return (tag, keyPointTags); - } - } - - private static IEnumerable GetKeyPointTags(byte tagId, IEnumerable keyPointTagIds, TagGetter getTag) - { - foreach (var keyPointTagId in keyPointTagIds) - yield return (KeyPointTag3D)getTag(tagId, keyPointTagId); - } } \ No newline at end of file diff --git a/SightKeeper.Data/Binary/Replication/DataSets/PoserDataSetReplicator.cs b/SightKeeper.Data/Binary/Replication/DataSets/PoserDataSetReplicator.cs index a7765e2f..e098a69d 100644 --- a/SightKeeper.Data/Binary/Replication/DataSets/PoserDataSetReplicator.cs +++ b/SightKeeper.Data/Binary/Replication/DataSets/PoserDataSetReplicator.cs @@ -1,12 +1,16 @@ using System.Collections.Immutable; using SightKeeper.Data.Binary.Model.DataSets.Tags; +using SightKeeper.Data.Binary.Model.DataSets.Weights; using SightKeeper.Data.Binary.Services; using SightKeeper.Domain.Model.DataSets.Poser; using SightKeeper.Domain.Model.DataSets.Tags; +using SightKeeper.Domain.Model.DataSets.Weights; namespace SightKeeper.Data.Binary.Replication.DataSets; -internal abstract class PoserDataSetReplicator : DataSetReplicator +internal abstract class PoserDataSetReplicator : DataSetReplicator + where TTag : PoserTag + where TKeyPointTag : KeyPointTag { protected PoserDataSetReplicator(FileSystemScreenshotsDataAccess screenshotsDataAccess) : base(screenshotsDataAccess) { @@ -24,4 +28,28 @@ protected override PoserTag ReplicateTag(TagsLibrary library, PackableTag packed } return tag; } + + protected sealed override void ReplicateWeights(WeightsLibrary library, PackableWeights weights, TagGetter getTag) + { + var typedLibrary = (WeightsLibrary)library; + var typedWeights = (PackablePoserWeights)weights; + var tags = GetTags(typedWeights, getTag); + typedLibrary.CreateWeights(weights.CreationDate, weights.ModelSize, weights.Metrics, weights.Resolution, tags); + } + + private static IEnumerable<(TTag, IEnumerable)> GetTags(PackablePoserWeights weights, TagGetter getTag) + { + foreach (var (tagId, keyPointTagIds) in weights.Tags) + { + var tag = (TTag)getTag(tagId); + var keyPointTags = GetKeyPointTags(tagId, keyPointTagIds, getTag); + yield return (tag, keyPointTags); + } + } + + private static IEnumerable GetKeyPointTags(byte tagId, IEnumerable keyPointTagIds, TagGetter getTag) + { + foreach (var keyPointTagId in keyPointTagIds) + yield return (TKeyPointTag)getTag(tagId, keyPointTagId); + } } \ No newline at end of file