osu/osu.Game/Modes/Beatmaps/IBeatmapConverter.cs

43 lines
1.7 KiB
C#
Raw Normal View History

2017-03-11 15:34:21 +00:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-04-17 06:44:46 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
2017-03-11 15:34:21 +00:00
using osu.Game.Modes.Objects;
using osu.Game.Beatmaps;
2017-03-11 15:34:21 +00:00
namespace osu.Game.Modes.Beatmaps
2017-03-11 15:34:21 +00:00
{
/// <summary>
/// Converts a Beatmap for another mode.
/// </summary>
/// <typeparam name="T">The type of HitObject stored in the Beatmap.</typeparam>
2017-03-11 15:34:21 +00:00
public interface IBeatmapConverter<T> where T : HitObject
{
2017-04-17 06:44:46 +00:00
/// <summary>
/// The types of HitObjects that can be converted to be used for this Beatmap.
2017-04-17 06:44:46 +00:00
/// </summary>
IEnumerable<Type> ValidConversionTypes { get; }
/// <summary>
/// Converts a Beatmap to another mode.
/// </summary>
/// <param name="original">The original Beatmap.</param>
/// <returns>The converted Beatmap.</returns>
2017-03-14 03:54:09 +00:00
Beatmap<T> Convert(Beatmap original);
2017-03-11 15:34:21 +00:00
}
2017-04-17 06:44:46 +00:00
public static class BeatmapConverterExtensions
{
/// <summary>
2017-04-18 00:13:36 +00:00
/// Checks if a Beatmap can be converted using this Beatmap Converter.
2017-04-17 06:44:46 +00:00
/// </summary>
2017-04-18 00:13:36 +00:00
/// <param name="converter">The Beatmap Converter.</param>
2017-04-17 06:44:46 +00:00
/// <param name="beatmap">The Beatmap to check.</param>
/// <returns>Whether the Beatmap can be converted using <paramref name="converter"/>.</returns>
2017-04-17 06:44:46 +00:00
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())));
}
2017-03-11 15:34:21 +00:00
}