mirror of https://github.com/ppy/osu
Simplify/improve beatmap conversion precheck
This commit is contained in:
parent
cc808a9eb1
commit
6e7426a098
|
@ -4,7 +4,7 @@
|
|||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Catch.Objects;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Game.Rulesets.Catch.UI;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
|
@ -19,7 +19,7 @@ public CatchBeatmapConverter(IBeatmap beatmap)
|
|||
{
|
||||
}
|
||||
|
||||
protected override IEnumerable<Type> ValidConversionTypes { get; } = new[] { typeof(IHasXPosition) };
|
||||
public override bool CanConvert() => Beatmap.HitObjects.All(h => h is IHasXPosition);
|
||||
|
||||
protected override IEnumerable<CatchHitObject> ConvertHitObject(HitObject obj, IBeatmap beatmap)
|
||||
{
|
||||
|
|
|
@ -24,8 +24,6 @@ public class ManiaBeatmapConverter : BeatmapConverter<ManiaHitObject>
|
|||
/// </summary>
|
||||
private const int max_notes_for_density = 7;
|
||||
|
||||
protected override IEnumerable<Type> ValidConversionTypes { get; } = new[] { typeof(IHasXPosition) };
|
||||
|
||||
public int TargetColumns;
|
||||
public bool Dual;
|
||||
public readonly bool IsForCurrentRuleset;
|
||||
|
@ -69,6 +67,8 @@ public ManiaBeatmapConverter(IBeatmap beatmap)
|
|||
}
|
||||
}
|
||||
|
||||
public override bool CanConvert() => Beatmap.HitObjects.All(h => h is IHasXPosition || h is ManiaHitObject);
|
||||
|
||||
protected override Beatmap<ManiaHitObject> ConvertBeatmap(IBeatmap original)
|
||||
{
|
||||
BeatmapDifficulty difficulty = original.BeatmapInfo.BaseDifficulty;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Game.Rulesets.Osu.UI;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
|
||||
|
@ -20,7 +20,7 @@ public OsuBeatmapConverter(IBeatmap beatmap)
|
|||
{
|
||||
}
|
||||
|
||||
protected override IEnumerable<Type> ValidConversionTypes { get; } = new[] { typeof(IHasPosition) };
|
||||
public override bool CanConvert() => Beatmap.HitObjects.All(h => h is IHasPosition);
|
||||
|
||||
protected override IEnumerable<OsuHitObject> ConvertHitObject(HitObject original, IBeatmap beatmap)
|
||||
{
|
||||
|
|
|
@ -39,14 +39,14 @@ internal class TaikoBeatmapConverter : BeatmapConverter<TaikoHitObject>
|
|||
|
||||
private readonly bool isForCurrentRuleset;
|
||||
|
||||
protected override IEnumerable<Type> ValidConversionTypes { get; } = new[] { typeof(HitObject) };
|
||||
|
||||
public TaikoBeatmapConverter(IBeatmap beatmap)
|
||||
: base(beatmap)
|
||||
{
|
||||
isForCurrentRuleset = beatmap.BeatmapInfo.Ruleset.Equals(new TaikoRuleset().RulesetInfo);
|
||||
}
|
||||
|
||||
public override bool CanConvert() => true;
|
||||
|
||||
protected override Beatmap<TaikoHitObject> ConvertBeatmap(IBeatmap original)
|
||||
{
|
||||
// Rewrite the beatmap info to add the slider velocity multiplier
|
||||
|
|
|
@ -273,7 +273,7 @@ public TestBeatmapConverter(IBeatmap beatmap)
|
|||
{
|
||||
}
|
||||
|
||||
protected override IEnumerable<Type> ValidConversionTypes => new[] { typeof(HitObject) };
|
||||
public override bool CanConvert() => true;
|
||||
|
||||
protected override IEnumerable<TestHitObject> ConvertHitObject(HitObject original, IBeatmap beatmap)
|
||||
{
|
||||
|
|
|
@ -33,7 +33,7 @@ protected BeatmapConverter(IBeatmap beatmap)
|
|||
/// <summary>
|
||||
/// Whether <see cref="Beatmap"/> can be converted by this <see cref="BeatmapConverter{T}"/>.
|
||||
/// </summary>
|
||||
public bool CanConvert => !Beatmap.HitObjects.Any() || ValidConversionTypes.All(t => Beatmap.HitObjects.Any(t.IsInstanceOfType));
|
||||
public abstract bool CanConvert();
|
||||
|
||||
/// <summary>
|
||||
/// Converts <see cref="Beatmap"/>.
|
||||
|
@ -92,11 +92,6 @@ private List<T> convertHitObjects(IReadOnlyList<HitObject> hitObjects, IBeatmap
|
|||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The types of HitObjects that can be converted to be used for this Beatmap.
|
||||
/// </summary>
|
||||
protected abstract IEnumerable<Type> ValidConversionTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates the <see cref="Beatmap{T}"/> that will be returned by this <see cref="BeatmapProcessor"/>.
|
||||
/// </summary>
|
||||
|
|
|
@ -76,7 +76,7 @@ private class DummyBeatmapConverter : IBeatmapConverter
|
|||
|
||||
public IBeatmap Beatmap { get; set; }
|
||||
|
||||
public bool CanConvert => true;
|
||||
public bool CanConvert() => true;
|
||||
|
||||
public IBeatmap Convert()
|
||||
{
|
||||
|
|
|
@ -25,7 +25,7 @@ public interface IBeatmapConverter
|
|||
/// <summary>
|
||||
/// Whether <see cref="Beatmap"/> can be converted by this <see cref="IBeatmapConverter"/>.
|
||||
/// </summary>
|
||||
bool CanConvert { get; }
|
||||
bool CanConvert();
|
||||
|
||||
/// <summary>
|
||||
/// Converts <see cref="Beatmap"/>.
|
||||
|
|
|
@ -108,7 +108,7 @@ public IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods
|
|||
IBeatmapConverter converter = CreateBeatmapConverter(Beatmap, rulesetInstance);
|
||||
|
||||
// Check if the beatmap can be converted
|
||||
if (!converter.CanConvert)
|
||||
if (!converter.CanConvert())
|
||||
throw new BeatmapInvalidForRulesetException($"{nameof(Beatmaps.Beatmap)} can not be converted for the ruleset (ruleset: {ruleset.InstantiationInfo}, converter: {converter}).");
|
||||
|
||||
// Apply conversion mods
|
||||
|
|
Loading…
Reference in New Issue