mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 15:16:38 +09:00
Implement Beatmap conversion testing.
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Game.Modes.Objects;
|
||||
|
||||
namespace osu.Game.Beatmaps
|
||||
@ -11,6 +14,12 @@ namespace osu.Game.Beatmaps
|
||||
/// <typeparam name="T">The type of HitObject stored in the Beatmap.</typeparam>
|
||||
public interface IBeatmapConverter<T> where T : HitObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of HitObjects that can be converted to be used for this Beatmap.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerable<Type> ValidConversionTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Beatmap to another mode.
|
||||
/// </summary>
|
||||
@ -18,4 +27,16 @@ namespace osu.Game.Beatmaps
|
||||
/// <returns>The converted Beatmap.</returns>
|
||||
Beatmap<T> Convert(Beatmap original);
|
||||
}
|
||||
|
||||
public static class BeatmapConverterExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks if a Beatmap can be converted using a Beatmap Converter.
|
||||
/// </summary>
|
||||
/// <param name="converter">The Converter to use.</param>
|
||||
/// <param name="beatmap">The Beatmap to check.</param>
|
||||
/// <returns>Whether the Beatmap can be converted using <paramref name="converter" />.</returns>
|
||||
public static bool CanConvert<TObject>(this IBeatmapConverter<TObject> converter, Beatmap beatmap) where TObject : HitObject
|
||||
=> converter.ValidConversionTypes.All(t => beatmap.HitObjects.Any(h => t.IsAssignableFrom(h.GetType())));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user