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

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Modes.Catch.Beatmaps;
using osu.Game.Modes.Catch.Objects; using osu.Game.Modes.Catch.Objects;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -10,15 +11,15 @@ namespace osu.Game.Modes.Catch
{ {
public class CatchDifficultyCalculator : DifficultyCalculator<CatchBaseHit> public class CatchDifficultyCalculator : DifficultyCalculator<CatchBaseHit>
{ {
protected override PlayMode PlayMode => PlayMode.Catch;
public CatchDifficultyCalculator(Beatmap beatmap) : base(beatmap) public CatchDifficultyCalculator(Beatmap beatmap) : base(beatmap)
{ {
} }
protected override double CalculateInternal(Dictionary<String, String> categoryDifficulty) protected override double CalculateInternal(Dictionary<string, string> categoryDifficulty)
{ {
return 0; return 0;
} }
protected override IBeatmapConverter<CatchBaseHit> CreateBeatmapConverter() => new CatchBeatmapConverter();
} }
} }

View File

@ -93,9 +93,9 @@ namespace osu.Game.Modes.Catch
public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new CatchDifficultyCalculator(beatmap); public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new CatchDifficultyCalculator(beatmap);
public override IBeatmapConverter<T> CreateBeatmapConverter<T>() public override IBeatmapConverter<CatchBaseHit> CreateBeatmapConverter<CatchBaseHit>()
{ {
return (IBeatmapConverter<T>)new CatchBeatmapConverter(); return (IBeatmapConverter<CatchBaseHit>)new CatchBeatmapConverter();
} }
} }
} }

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Modes.Catch.Beatmaps;
using osu.Game.Modes.Catch.Objects; using osu.Game.Modes.Catch.Objects;
using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.UI; using osu.Game.Modes.UI;
@ -15,7 +16,7 @@ namespace osu.Game.Modes.Catch.UI
{ {
} }
protected override PlayMode PlayMode => PlayMode.Catch; protected override IBeatmapConverter<CatchBaseHit> CreateBeatmapConverter() => new CatchBeatmapConverter();
protected override Playfield<CatchBaseHit> CreatePlayfield() => new CatchPlayfield(); protected override Playfield<CatchBaseHit> CreatePlayfield() => new CatchPlayfield();

View File

@ -2,24 +2,24 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Modes.Mania.Beatmaps;
using osu.Game.Modes.Mania.Objects; using osu.Game.Modes.Mania.Objects;
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace osu.Game.Modes.Mania namespace osu.Game.Modes.Mania
{ {
public class ManiaDifficultyCalculator : DifficultyCalculator<ManiaBaseHit> public class ManiaDifficultyCalculator : DifficultyCalculator<ManiaBaseHit>
{ {
protected override PlayMode PlayMode => PlayMode.Mania;
public ManiaDifficultyCalculator(Beatmap beatmap) public ManiaDifficultyCalculator(Beatmap beatmap)
: base(beatmap) : base(beatmap)
{ {
} }
protected override double CalculateInternal(Dictionary<String, String> categoryDifficulty) protected override double CalculateInternal(Dictionary<string, string> categoryDifficulty)
{ {
return 0; return 0;
} }
protected override IBeatmapConverter<ManiaBaseHit> CreateBeatmapConverter() => new ManiaBeatmapConverter();
} }
} }

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Modes.Mania.Beatmaps;
using osu.Game.Modes.Mania.Objects; using osu.Game.Modes.Mania.Objects;
using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.UI; using osu.Game.Modes.UI;
@ -18,7 +19,7 @@ namespace osu.Game.Modes.Mania.UI
this.columns = columns; this.columns = columns;
} }
protected override PlayMode PlayMode => PlayMode.Mania; protected override IBeatmapConverter<ManiaBaseHit> CreateBeatmapConverter() => new ManiaBeatmapConverter();
protected override Playfield<ManiaBaseHit> CreatePlayfield() => new ManiaPlayfield(columns); protected override Playfield<ManiaBaseHit> CreatePlayfield() => new ManiaPlayfield(columns);

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Modes.Osu.Beatmaps;
using osu.Game.Modes.Osu.Objects; using osu.Game.Modes.Osu.Objects;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -13,8 +14,6 @@ namespace osu.Game.Modes.Osu
private const double star_scaling_factor = 0.0675; private const double star_scaling_factor = 0.0675;
private const double extreme_scaling_factor = 0.5; private const double extreme_scaling_factor = 0.5;
protected override PlayMode PlayMode => PlayMode.Osu;
/// <summary> /// <summary>
/// HitObjects are stored as a member variable. /// HitObjects are stored as a member variable.
/// </summary> /// </summary>
@ -31,7 +30,7 @@ namespace osu.Game.Modes.Osu
((Slider)h).Curve.Calculate(); ((Slider)h).Curve.Calculate();
} }
protected override double CalculateInternal(Dictionary<String, String> categoryDifficulty) protected override double CalculateInternal(Dictionary<string, string> categoryDifficulty)
{ {
// Fill our custom DifficultyHitObject class, that carries additional information // Fill our custom DifficultyHitObject class, that carries additional information
DifficultyHitObjects.Clear(); DifficultyHitObjects.Clear();
@ -181,6 +180,8 @@ namespace osu.Game.Modes.Osu
return difficulty; return difficulty;
} }
protected override IBeatmapConverter<OsuHitObject> CreateBeatmapConverter() => new OsuBeatmapConverter();
// Those values are used as array indices. Be careful when changing them! // Those values are used as array indices. Be careful when changing them!
public enum DifficultyType public enum DifficultyType
{ {

View File

@ -3,6 +3,7 @@
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Osu.Beatmaps;
using osu.Game.Modes.Osu.Objects; using osu.Game.Modes.Osu.Objects;
using osu.Game.Modes.Osu.Objects.Drawables; using osu.Game.Modes.Osu.Objects.Drawables;
using osu.Game.Modes.UI; using osu.Game.Modes.UI;
@ -16,7 +17,7 @@ namespace osu.Game.Modes.Osu.UI
{ {
} }
protected override PlayMode PlayMode => PlayMode.Osu; protected override IBeatmapConverter<OsuHitObject> CreateBeatmapConverter() => new OsuBeatmapConverter();
protected override Playfield<OsuHitObject> CreatePlayfield() => new OsuPlayfield(); protected override Playfield<OsuHitObject> CreatePlayfield() => new OsuPlayfield();

View File

@ -2,23 +2,23 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Modes.Taiko.Beatmaps;
using osu.Game.Modes.Taiko.Objects; using osu.Game.Modes.Taiko.Objects;
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace osu.Game.Modes.Taiko namespace osu.Game.Modes.Taiko
{ {
public class TaikoDifficultyCalculator : DifficultyCalculator<TaikoBaseHit> public class TaikoDifficultyCalculator : DifficultyCalculator<TaikoBaseHit>
{ {
protected override PlayMode PlayMode => PlayMode.Taiko;
public TaikoDifficultyCalculator(Beatmap beatmap) : base(beatmap) public TaikoDifficultyCalculator(Beatmap beatmap) : base(beatmap)
{ {
} }
protected override double CalculateInternal(Dictionary<String, String> categoryDifficulty) protected override double CalculateInternal(Dictionary<string, string> categoryDifficulty)
{ {
return 0; return 0;
} }
protected override IBeatmapConverter<TaikoBaseHit> CreateBeatmapConverter() => new TaikoBeatmapConverter();
} }
} }

View File

@ -3,6 +3,7 @@
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Taiko.Beatmaps;
using osu.Game.Modes.Taiko.Objects; using osu.Game.Modes.Taiko.Objects;
using osu.Game.Modes.UI; using osu.Game.Modes.UI;
@ -15,7 +16,7 @@ namespace osu.Game.Modes.Taiko.UI
{ {
} }
protected override PlayMode PlayMode => PlayMode.Taiko; protected override IBeatmapConverter<TaikoBaseHit> CreateBeatmapConverter() => new TaikoBeatmapConverter();
protected override Playfield<TaikoBaseHit> CreatePlayfield() => new TaikoPlayfield(); protected override Playfield<TaikoBaseHit> CreatePlayfield() => new TaikoPlayfield();

View File

@ -1,7 +1,9 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK.Graphics;
using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Timing;
using osu.Game.Database;
using osu.Game.Modes; using osu.Game.Modes;
using osu.Game.Modes.Objects; using osu.Game.Modes.Objects;
using System.Collections.Generic; using System.Collections.Generic;
@ -10,23 +12,31 @@ using System.Linq;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
/// <summary> /// <summary>
/// A Beatmap containing HitObjects. /// A Beatmap containing converted HitObjects.
/// </summary> /// </summary>
public class Beatmap<T> : BeatmapBase public class Beatmap<T>
where T : HitObject where T : HitObject
{ {
public BeatmapInfo BeatmapInfo;
public List<ControlPoint> ControlPoints;
public List<Color4> ComboColors;
public BeatmapMetadata Metadata => BeatmapInfo?.Metadata ?? BeatmapInfo?.BeatmapSet?.Metadata;
/// <summary> /// <summary>
/// The HitObjects this Beatmap contains. /// The HitObjects this Beatmap contains.
/// </summary> /// </summary>
public List<T> HitObjects; public List<T> HitObjects;
/// <summary> /// <summary>
/// Constructs a new Beatmap containing HitObjects. /// Constructs a new beatmap.
/// </summary> /// </summary>
/// <param name="original">If this Beatmap is a convert, the original Beatmap to use the properties of.</param> /// <param name="original">The original beatmap to use the parameters of.</param>
public Beatmap(BeatmapBase original = null) public Beatmap(Beatmap original = null)
: base(original)
{ {
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; 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> /// </summary>
/// <returns>The star difficulty.</returns> /// <returns>The star difficulty.</returns>
public double CalculateStarDifficulty() => Ruleset.GetRuleset(BeatmapInfo.Mode).CreateDifficultyCalculator(this).Calculate(); 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>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Modes;
using osu.Game.Modes.Objects; using osu.Game.Modes.Objects;
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
public abstract class DifficultyCalculator public abstract class DifficultyCalculator
{ {
protected abstract PlayMode PlayMode { get; }
protected double TimeRate = 1; protected double TimeRate = 1;
protected abstract double CalculateInternal(Dictionary<String, String> categoryDifficulty); protected abstract double CalculateInternal(Dictionary<string, string> categoryDifficulty);
private void loadTiming() private void loadTiming()
{ {
@ -37,12 +33,14 @@ namespace osu.Game.Beatmaps
protected DifficultyCalculator(Beatmap beatmap) protected DifficultyCalculator(Beatmap beatmap)
{ {
Objects = beatmap.ConvertTo<T>(PlayMode).HitObjects; Objects = CreateBeatmapConverter().Convert(beatmap).HitObjects;
PreprocessHitObjects(); PreprocessHitObjects();
} }
protected virtual void PreprocessHitObjects() protected virtual void PreprocessHitObjects()
{ {
} }
protected abstract IBeatmapConverter<T> CreateBeatmapConverter();
} }
} }

View File

@ -1,12 +1,12 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Linq;
using osu.Game.Beatmaps.Samples; using osu.Game.Beatmaps.Samples;
using osu.Game.Modes; using osu.Game.Modes;
using SQLite.Net.Attributes; using SQLite.Net.Attributes;
using SQLiteNetExtensions.Attributes; using SQLiteNetExtensions.Attributes;
using System;
using System.Linq;
namespace osu.Game.Database namespace osu.Game.Database
{ {
@ -82,7 +82,7 @@ namespace osu.Game.Database
{ {
return starDifficulty < 0 ? (BaseDifficulty?.OverallDifficulty ?? 5) : starDifficulty; return starDifficulty < 0 ? (BaseDifficulty?.OverallDifficulty ?? 5) : starDifficulty;
} }
set { starDifficulty = value; } set { starDifficulty = value; }
} }

View File

@ -50,8 +50,6 @@ namespace osu.Game.Modes.UI
protected override Container<Drawable> Content => content; protected override Container<Drawable> Content => content;
protected override bool AllObjectsJudged => Playfield.HitObjects.Children.All(h => h.Judgement.Result.HasValue); protected override bool AllObjectsJudged => Playfield.HitObjects.Children.All(h => h.Judgement.Result.HasValue);
protected abstract PlayMode PlayMode { get; }
protected Playfield<TObject> Playfield; protected Playfield<TObject> Playfield;
protected Beatmap<TObject> Beatmap; protected Beatmap<TObject> Beatmap;
@ -59,7 +57,7 @@ namespace osu.Game.Modes.UI
protected HitRenderer(Beatmap beatmap) protected HitRenderer(Beatmap beatmap)
{ {
Beatmap = beatmap.ConvertTo<TObject>(PlayMode); Beatmap = CreateBeatmapConverter().Convert(beatmap);
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
@ -103,5 +101,6 @@ namespace osu.Game.Modes.UI
protected abstract DrawableHitObject<TObject> GetVisualRepresentation(TObject h); protected abstract DrawableHitObject<TObject> GetVisualRepresentation(TObject h);
protected abstract Playfield<TObject> CreatePlayfield(); protected abstract Playfield<TObject> CreatePlayfield();
protected abstract IBeatmapConverter<TObject> CreateBeatmapConverter();
} }
} }

View File

@ -71,7 +71,6 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Beatmaps\BeatmapBase.cs" />
<Compile Include="Beatmaps\Drawables\BeatmapBackgroundSprite.cs" /> <Compile Include="Beatmaps\Drawables\BeatmapBackgroundSprite.cs" />
<Compile Include="Beatmaps\DifficultyCalculator.cs" /> <Compile Include="Beatmaps\DifficultyCalculator.cs" />
<Compile Include="Beatmaps\IBeatmapCoverter.cs" /> <Compile Include="Beatmaps\IBeatmapCoverter.cs" />