Skip to content

Commit

Permalink
Abstract Assets replication methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Neakita committed Sep 6, 2024
1 parent 7f842d2 commit 8fdcb2f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions SightKeeper.Data/Binary/Model/DataSets/PackableDataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public PackableDataSet(
}

public abstract ImmutableArray<PackableTag> GetTags();
public abstract ImmutableArray<PackableAsset> GetAssets();
}

/// <summary>
Expand Down Expand Up @@ -73,4 +74,9 @@ public sealed override ImmutableArray<PackableTag> GetTags()
{
return ImmutableArray<PackableTag>.CastUp(Tags);
}

public sealed override ImmutableArray<PackableAsset> GetAssets()
{
return ImmutableArray<PackableAsset>.CastUp(Assets);
}
}
13 changes: 13 additions & 0 deletions SightKeeper.Data/Binary/Replication/DataSetReplicator.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
using System.Collections.Immutable;
using CommunityToolkit.Diagnostics;
using SightKeeper.Data.Binary.Model.DataSets;
using SightKeeper.Data.Binary.Model.DataSets.Assets;
using SightKeeper.Data.Binary.Model.DataSets.Compositions;
using SightKeeper.Data.Binary.Model.DataSets.Tags;
using SightKeeper.Data.Binary.Services;
using SightKeeper.Domain.Model;
using SightKeeper.Domain.Model.DataSets;
using SightKeeper.Domain.Model.DataSets.Assets;
using SightKeeper.Domain.Model.DataSets.Screenshots;
using SightKeeper.Domain.Model.DataSets.Tags;

namespace SightKeeper.Data.Binary.Replication;

internal abstract class DataSetReplicator
{
protected delegate Tag TagGetter(byte TagId, byte? KeyPointTagId = null);

public DataSetReplicator(FileSystemScreenshotsDataAccess screenshotsDataAccess)
{
_screenshotsDataAccess = screenshotsDataAccess;
Expand All @@ -26,6 +30,7 @@ public DataSet Replicate(PackableDataSet packed, ReplicationSession session)
var dataSet = CreateDataSet(packed.Name, packed.Description, game, composition);
ReplicateScreenshots(dataSet.Screenshots, packed.Screenshots);
var tagsLookup = ReplicateTags(dataSet.Tags, packed.GetTags());
ReplicateAssets(dataSet.Assets, packed.GetAssets(), (tagId, keyPointTagId) => tagsLookup[(tagId, keyPointTagId)]);
return dataSet;
}

Expand All @@ -43,6 +48,8 @@ protected virtual Tag ReplicateTag(
return tag;
}

protected abstract void ReplicateAsset(AssetsLibrary library, PackableAsset asset, TagGetter getTag);

private readonly FileSystemScreenshotsDataAccess _screenshotsDataAccess;

private static Composition ReplicateComposition(PackableComposition? composition)
Expand Down Expand Up @@ -74,4 +81,10 @@ private void ReplicateScreenshots(ScreenshotsLibrary library, ImmutableArray<Pac
ReplicateTag(library, tag, lookupBuilder);
return lookupBuilder.ToImmutable();
}

private void ReplicateAssets(AssetsLibrary library, ImmutableArray<PackableAsset> assets, TagGetter getTag)
{
foreach (var asset in assets)
ReplicateAsset(library, asset, getTag);
}
}

0 comments on commit 8fdcb2f

Please sign in to comment.