Remove PlayMode enum requirement. Clean things up a lot.

This commit is contained in:
smoogipooo
2017-03-12 14:32:50 +09:00
parent b0ea282a06
commit 3480dca0ad
15 changed files with 51 additions and 100 deletions

View File

@ -1,7 +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 OpenTK.Graphics;
using osu.Game.Beatmaps.Timing;
using osu.Game.Database;
using osu.Game.Modes;
using osu.Game.Modes.Objects;
using System.Collections.Generic;
@ -10,23 +12,31 @@ using System.Linq;
namespace osu.Game.Beatmaps
{
/// <summary>
/// A Beatmap containing HitObjects.
/// A Beatmap containing converted HitObjects.
/// </summary>
public class Beatmap<T> : BeatmapBase
public class Beatmap<T>
where T : HitObject
{
public BeatmapInfo BeatmapInfo;
public List<ControlPoint> ControlPoints;
public List<Color4> ComboColors;
public BeatmapMetadata Metadata => BeatmapInfo?.Metadata ?? BeatmapInfo?.BeatmapSet?.Metadata;
/// <summary>
/// The HitObjects this Beatmap contains.
/// </summary>
public List<T> HitObjects;
/// <summary>
/// Constructs a new Beatmap containing HitObjects.
/// Constructs a new beatmap.
/// </summary>
/// <param name="original">If this Beatmap is a convert, the original Beatmap to use the properties of.</param>
public Beatmap(BeatmapBase original = null)
: base(original)
/// <param name="original">The original beatmap to use the parameters of.</param>
public Beatmap(Beatmap original = null)
{
BeatmapInfo = original?.BeatmapInfo;
ControlPoints = original?.ControlPoints;
ComboColors = original?.ComboColors;
}
public double BPMMaximum => 60000 / (ControlPoints?.Where(c => c.BeatLength != 0).OrderBy(c => c.BeatLength).FirstOrDefault() ?? ControlPoint.Default).BeatLength;
@ -81,15 +91,5 @@ namespace osu.Game.Beatmaps
/// </summary>
/// <returns>The star difficulty.</returns>
public double CalculateStarDifficulty() => Ruleset.GetRuleset(BeatmapInfo.Mode).CreateDifficultyCalculator(this).Calculate();
/// <summary>
/// Converts this Beatmap to a <see cref="Beatmap{T}"/> containing another type of <see cref="HitObject"/>.
/// </summary>
/// <typeparam name="T">The type of HitObject the new Beatmap should contain.</typeparam>
/// <returns></returns>
public Beatmap<T> ConvertTo<T>(PlayMode playMode) where T : HitObject
{
return Ruleset.GetRuleset(playMode).CreateBeatmapConverter<T>().Convert(this);
}
}
}

View File

@ -1,51 +0,0 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK.Graphics;
using osu.Game.Beatmaps.Timing;
using osu.Game.Database;
using System.Collections.Generic;
namespace osu.Game.Beatmaps
{
/// <summary>
/// Contains basic beatmap properties.
/// <para>
/// This allows converted beatmaps (<see cref="Beatmap{T}"/>) to refer to an original "base" Beatmap
/// for properties that shouldn't change unless in exceptional circumstances.
/// Properties here may be set to be overriden in such exceptional cases.
/// </para>
/// </summary>
public class BeatmapBase
{
private BeatmapBase original;
public BeatmapBase(BeatmapBase original = null)
{
this.original = original;
}
private BeatmapInfo beatmapInfo;
public BeatmapInfo BeatmapInfo
{
get { return beatmapInfo ?? original?.BeatmapInfo; }
set { beatmapInfo = value; }
}
private List<ControlPoint> controlPoints;
public List<ControlPoint> ControlPoints
{
get { return controlPoints ?? original?.ControlPoints; }
set { controlPoints = value; }
}
private List<Color4> comboColors;
public List<Color4> ComboColors
{
get { return comboColors ?? original?.ComboColors; }
set { comboColors = value; }
}
public BeatmapMetadata Metadata => BeatmapInfo?.Metadata ?? BeatmapInfo?.BeatmapSet?.Metadata;
}
}

View File

@ -1,20 +1,16 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Modes;
using osu.Game.Modes.Objects;
using System;
using System.Collections.Generic;
namespace osu.Game.Beatmaps
{
public abstract class DifficultyCalculator
{
protected abstract PlayMode PlayMode { get; }
protected double TimeRate = 1;
protected abstract double CalculateInternal(Dictionary<String, String> categoryDifficulty);
protected abstract double CalculateInternal(Dictionary<string, string> categoryDifficulty);
private void loadTiming()
{
@ -37,12 +33,14 @@ namespace osu.Game.Beatmaps
protected DifficultyCalculator(Beatmap beatmap)
{
Objects = beatmap.ConvertTo<T>(PlayMode).HitObjects;
Objects = CreateBeatmapConverter().Convert(beatmap).HitObjects;
PreprocessHitObjects();
}
protected virtual void PreprocessHitObjects()
{
}
protected abstract IBeatmapConverter<T> CreateBeatmapConverter();
}
}