Rework to support obsoletion

This commit is contained in:
smoogipoo 2020-09-17 21:36:55 +09:00
parent e71991a53c
commit de5ef8a471
1 changed files with 33 additions and 1 deletions

View File

@ -27,6 +27,8 @@ event Action<HitObject, IEnumerable<HitObject>> IBeatmapConverter.ObjectConverte
public IBeatmap Beatmap { get; }
private CancellationToken cancellationToken;
protected BeatmapConverter(IBeatmap beatmap, Ruleset ruleset)
{
Beatmap = beatmap;
@ -39,6 +41,8 @@ protected BeatmapConverter(IBeatmap beatmap, Ruleset ruleset)
public IBeatmap Convert(CancellationToken cancellationToken = default)
{
this.cancellationToken = cancellationToken;
// We always operate on a clone of the original beatmap, to not modify it game-wide
return ConvertBeatmap(Beatmap.Clone(), cancellationToken);
}
@ -51,6 +55,19 @@ public IBeatmap Convert(CancellationToken cancellationToken = default)
/// <returns>The converted Beatmap.</returns>
protected virtual Beatmap<T> ConvertBeatmap(IBeatmap original, CancellationToken cancellationToken)
{
#pragma warning disable 618
return ConvertBeatmap(original);
#pragma warning restore 618
}
/// <summary>
/// Performs the conversion of a Beatmap using this Beatmap Converter.
/// </summary>
/// <param name="original">The un-converted Beatmap.</param>
/// <returns>The converted Beatmap.</returns>
[Obsolete("Use the cancellation-supporting override")] // Can be removed 20210318
protected virtual Beatmap<T> ConvertBeatmap(IBeatmap original)
{
var beatmap = CreateBeatmap();
beatmap.BeatmapInfo = original.BeatmapInfo;
@ -104,6 +121,21 @@ private List<T> convertHitObjects(IReadOnlyList<HitObject> hitObjects, IBeatmap
/// <param name="beatmap">The un-converted Beatmap.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The converted hit object.</returns>
protected abstract IEnumerable<T> ConvertHitObject(HitObject original, IBeatmap beatmap, CancellationToken cancellationToken);
protected virtual IEnumerable<T> ConvertHitObject(HitObject original, IBeatmap beatmap, CancellationToken cancellationToken)
{
#pragma warning disable 618
return ConvertHitObject(original, beatmap);
#pragma warning restore 618
}
/// <summary>
/// Performs the conversion of a hit object.
/// This method is generally executed sequentially for all objects in a beatmap.
/// </summary>
/// <param name="original">The hit object to convert.</param>
/// <param name="beatmap">The un-converted Beatmap.</param>
/// <returns>The converted hit object.</returns>
[Obsolete("Use the cancellation-supporting override")] // Can be removed 20210318
protected virtual IEnumerable<T> ConvertHitObject(HitObject original, IBeatmap beatmap) => Enumerable.Empty<T>();
}
}