From 3480dca0add9b9b28ea0e5fe672f1c67939b4c13 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Sun, 12 Mar 2017 14:32:50 +0900 Subject: [PATCH] Remove PlayMode enum requirement. Clean things up a lot. --- .../CatchDifficultyCalculator.cs | 7 +-- osu.Game.Modes.Catch/CatchRuleset.cs | 4 +- osu.Game.Modes.Catch/UI/CatchHitRenderer.cs | 3 +- .../ManiaDifficultyCalculator.cs | 8 +-- osu.Game.Modes.Mania/UI/ManiaHitRenderer.cs | 3 +- osu.Game.Modes.Osu/OsuDifficultyCalculator.cs | 7 +-- osu.Game.Modes.Osu/UI/OsuHitRenderer.cs | 3 +- .../TaikoDifficultyCalculator.cs | 8 +-- osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs | 3 +- osu.Game/Beatmaps/Beatmap.cs | 32 ++++++------ osu.Game/Beatmaps/BeatmapBase.cs | 51 ------------------- osu.Game/Beatmaps/DifficultyCalculator.cs | 10 ++-- osu.Game/Database/BeatmapInfo.cs | 6 +-- osu.Game/Modes/UI/HitRenderer.cs | 5 +- osu.Game/osu.Game.csproj | 1 - 15 files changed, 51 insertions(+), 100 deletions(-) delete mode 100644 osu.Game/Beatmaps/BeatmapBase.cs diff --git a/osu.Game.Modes.Catch/CatchDifficultyCalculator.cs b/osu.Game.Modes.Catch/CatchDifficultyCalculator.cs index 01fa1a00d4..c85cb8a8f1 100644 --- a/osu.Game.Modes.Catch/CatchDifficultyCalculator.cs +++ b/osu.Game.Modes.Catch/CatchDifficultyCalculator.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.Beatmaps; +using osu.Game.Modes.Catch.Beatmaps; using osu.Game.Modes.Catch.Objects; using System; using System.Collections.Generic; @@ -10,15 +11,15 @@ namespace osu.Game.Modes.Catch { public class CatchDifficultyCalculator : DifficultyCalculator { - protected override PlayMode PlayMode => PlayMode.Catch; - public CatchDifficultyCalculator(Beatmap beatmap) : base(beatmap) { } - protected override double CalculateInternal(Dictionary categoryDifficulty) + protected override double CalculateInternal(Dictionary categoryDifficulty) { return 0; } + + protected override IBeatmapConverter CreateBeatmapConverter() => new CatchBeatmapConverter(); } } \ No newline at end of file diff --git a/osu.Game.Modes.Catch/CatchRuleset.cs b/osu.Game.Modes.Catch/CatchRuleset.cs index f3eda9ff37..2cdd35cf3a 100644 --- a/osu.Game.Modes.Catch/CatchRuleset.cs +++ b/osu.Game.Modes.Catch/CatchRuleset.cs @@ -93,9 +93,9 @@ namespace osu.Game.Modes.Catch public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new CatchDifficultyCalculator(beatmap); - public override IBeatmapConverter CreateBeatmapConverter() + public override IBeatmapConverter CreateBeatmapConverter() { - return (IBeatmapConverter)new CatchBeatmapConverter(); + return (IBeatmapConverter)new CatchBeatmapConverter(); } } } diff --git a/osu.Game.Modes.Catch/UI/CatchHitRenderer.cs b/osu.Game.Modes.Catch/UI/CatchHitRenderer.cs index 990ec083cb..1537227d8f 100644 --- a/osu.Game.Modes.Catch/UI/CatchHitRenderer.cs +++ b/osu.Game.Modes.Catch/UI/CatchHitRenderer.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.Beatmaps; +using osu.Game.Modes.Catch.Beatmaps; using osu.Game.Modes.Catch.Objects; using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.UI; @@ -15,7 +16,7 @@ namespace osu.Game.Modes.Catch.UI { } - protected override PlayMode PlayMode => PlayMode.Catch; + protected override IBeatmapConverter CreateBeatmapConverter() => new CatchBeatmapConverter(); protected override Playfield CreatePlayfield() => new CatchPlayfield(); diff --git a/osu.Game.Modes.Mania/ManiaDifficultyCalculator.cs b/osu.Game.Modes.Mania/ManiaDifficultyCalculator.cs index 7ee93b84cf..02a5a3acdc 100644 --- a/osu.Game.Modes.Mania/ManiaDifficultyCalculator.cs +++ b/osu.Game.Modes.Mania/ManiaDifficultyCalculator.cs @@ -2,24 +2,24 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.Beatmaps; +using osu.Game.Modes.Mania.Beatmaps; using osu.Game.Modes.Mania.Objects; -using System; using System.Collections.Generic; namespace osu.Game.Modes.Mania { public class ManiaDifficultyCalculator : DifficultyCalculator { - protected override PlayMode PlayMode => PlayMode.Mania; - public ManiaDifficultyCalculator(Beatmap beatmap) : base(beatmap) { } - protected override double CalculateInternal(Dictionary categoryDifficulty) + protected override double CalculateInternal(Dictionary categoryDifficulty) { return 0; } + + protected override IBeatmapConverter CreateBeatmapConverter() => new ManiaBeatmapConverter(); } } \ No newline at end of file diff --git a/osu.Game.Modes.Mania/UI/ManiaHitRenderer.cs b/osu.Game.Modes.Mania/UI/ManiaHitRenderer.cs index 916d919851..911742b222 100644 --- a/osu.Game.Modes.Mania/UI/ManiaHitRenderer.cs +++ b/osu.Game.Modes.Mania/UI/ManiaHitRenderer.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.Beatmaps; +using osu.Game.Modes.Mania.Beatmaps; using osu.Game.Modes.Mania.Objects; using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.UI; @@ -18,7 +19,7 @@ namespace osu.Game.Modes.Mania.UI this.columns = columns; } - protected override PlayMode PlayMode => PlayMode.Mania; + protected override IBeatmapConverter CreateBeatmapConverter() => new ManiaBeatmapConverter(); protected override Playfield CreatePlayfield() => new ManiaPlayfield(columns); diff --git a/osu.Game.Modes.Osu/OsuDifficultyCalculator.cs b/osu.Game.Modes.Osu/OsuDifficultyCalculator.cs index 86c6596138..5ef0f0059d 100644 --- a/osu.Game.Modes.Osu/OsuDifficultyCalculator.cs +++ b/osu.Game.Modes.Osu/OsuDifficultyCalculator.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.Beatmaps; +using osu.Game.Modes.Osu.Beatmaps; using osu.Game.Modes.Osu.Objects; using System; using System.Collections.Generic; @@ -13,8 +14,6 @@ namespace osu.Game.Modes.Osu private const double star_scaling_factor = 0.0675; private const double extreme_scaling_factor = 0.5; - protected override PlayMode PlayMode => PlayMode.Osu; - /// /// HitObjects are stored as a member variable. /// @@ -31,7 +30,7 @@ namespace osu.Game.Modes.Osu ((Slider)h).Curve.Calculate(); } - protected override double CalculateInternal(Dictionary categoryDifficulty) + protected override double CalculateInternal(Dictionary categoryDifficulty) { // Fill our custom DifficultyHitObject class, that carries additional information DifficultyHitObjects.Clear(); @@ -181,6 +180,8 @@ namespace osu.Game.Modes.Osu return difficulty; } + protected override IBeatmapConverter CreateBeatmapConverter() => new OsuBeatmapConverter(); + // Those values are used as array indices. Be careful when changing them! public enum DifficultyType { diff --git a/osu.Game.Modes.Osu/UI/OsuHitRenderer.cs b/osu.Game.Modes.Osu/UI/OsuHitRenderer.cs index 040543fe1b..8b7606e61e 100644 --- a/osu.Game.Modes.Osu/UI/OsuHitRenderer.cs +++ b/osu.Game.Modes.Osu/UI/OsuHitRenderer.cs @@ -3,6 +3,7 @@ using osu.Game.Beatmaps; using osu.Game.Modes.Objects.Drawables; +using osu.Game.Modes.Osu.Beatmaps; using osu.Game.Modes.Osu.Objects; using osu.Game.Modes.Osu.Objects.Drawables; using osu.Game.Modes.UI; @@ -16,7 +17,7 @@ namespace osu.Game.Modes.Osu.UI { } - protected override PlayMode PlayMode => PlayMode.Osu; + protected override IBeatmapConverter CreateBeatmapConverter() => new OsuBeatmapConverter(); protected override Playfield CreatePlayfield() => new OsuPlayfield(); diff --git a/osu.Game.Modes.Taiko/TaikoDifficultyCalculator.cs b/osu.Game.Modes.Taiko/TaikoDifficultyCalculator.cs index a90e2f40fa..4a133ea896 100644 --- a/osu.Game.Modes.Taiko/TaikoDifficultyCalculator.cs +++ b/osu.Game.Modes.Taiko/TaikoDifficultyCalculator.cs @@ -2,23 +2,23 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.Beatmaps; +using osu.Game.Modes.Taiko.Beatmaps; using osu.Game.Modes.Taiko.Objects; -using System; using System.Collections.Generic; namespace osu.Game.Modes.Taiko { public class TaikoDifficultyCalculator : DifficultyCalculator { - protected override PlayMode PlayMode => PlayMode.Taiko; - public TaikoDifficultyCalculator(Beatmap beatmap) : base(beatmap) { } - protected override double CalculateInternal(Dictionary categoryDifficulty) + protected override double CalculateInternal(Dictionary categoryDifficulty) { return 0; } + + protected override IBeatmapConverter CreateBeatmapConverter() => new TaikoBeatmapConverter(); } } \ No newline at end of file diff --git a/osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs b/osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs index 365ab94dcb..dc0276aacc 100644 --- a/osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs +++ b/osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs @@ -3,6 +3,7 @@ using osu.Game.Beatmaps; using osu.Game.Modes.Objects.Drawables; +using osu.Game.Modes.Taiko.Beatmaps; using osu.Game.Modes.Taiko.Objects; using osu.Game.Modes.UI; @@ -15,7 +16,7 @@ namespace osu.Game.Modes.Taiko.UI { } - protected override PlayMode PlayMode => PlayMode.Taiko; + protected override IBeatmapConverter CreateBeatmapConverter() => new TaikoBeatmapConverter(); protected override Playfield CreatePlayfield() => new TaikoPlayfield(); diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index 99a212adf4..de869192b9 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -1,7 +1,9 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // 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 { /// - /// A Beatmap containing HitObjects. + /// A Beatmap containing converted HitObjects. /// - public class Beatmap : BeatmapBase + public class Beatmap where T : HitObject { + public BeatmapInfo BeatmapInfo; + public List ControlPoints; + public List ComboColors; + + public BeatmapMetadata Metadata => BeatmapInfo?.Metadata ?? BeatmapInfo?.BeatmapSet?.Metadata; + /// /// The HitObjects this Beatmap contains. /// public List HitObjects; /// - /// Constructs a new Beatmap containing HitObjects. + /// Constructs a new beatmap. /// - /// If this Beatmap is a convert, the original Beatmap to use the properties of. - public Beatmap(BeatmapBase original = null) - : base(original) + /// The original beatmap to use the parameters of. + 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 /// /// The star difficulty. public double CalculateStarDifficulty() => Ruleset.GetRuleset(BeatmapInfo.Mode).CreateDifficultyCalculator(this).Calculate(); - - /// - /// Converts this Beatmap to a containing another type of . - /// - /// The type of HitObject the new Beatmap should contain. - /// - public Beatmap ConvertTo(PlayMode playMode) where T : HitObject - { - return Ruleset.GetRuleset(playMode).CreateBeatmapConverter().Convert(this); - } } } diff --git a/osu.Game/Beatmaps/BeatmapBase.cs b/osu.Game/Beatmaps/BeatmapBase.cs deleted file mode 100644 index f7256f4a54..0000000000 --- a/osu.Game/Beatmaps/BeatmapBase.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// 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 -{ - /// - /// Contains basic beatmap properties. - /// - /// This allows converted beatmaps () 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. - /// - /// - 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 controlPoints; - public List ControlPoints - { - get { return controlPoints ?? original?.ControlPoints; } - set { controlPoints = value; } - } - - private List comboColors; - public List ComboColors - { - get { return comboColors ?? original?.ComboColors; } - set { comboColors = value; } - } - - public BeatmapMetadata Metadata => BeatmapInfo?.Metadata ?? BeatmapInfo?.BeatmapSet?.Metadata; - } -} diff --git a/osu.Game/Beatmaps/DifficultyCalculator.cs b/osu.Game/Beatmaps/DifficultyCalculator.cs index 1443d55068..9c057d5f77 100644 --- a/osu.Game/Beatmaps/DifficultyCalculator.cs +++ b/osu.Game/Beatmaps/DifficultyCalculator.cs @@ -1,20 +1,16 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // 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 categoryDifficulty); + protected abstract double CalculateInternal(Dictionary categoryDifficulty); private void loadTiming() { @@ -37,12 +33,14 @@ namespace osu.Game.Beatmaps protected DifficultyCalculator(Beatmap beatmap) { - Objects = beatmap.ConvertTo(PlayMode).HitObjects; + Objects = CreateBeatmapConverter().Convert(beatmap).HitObjects; PreprocessHitObjects(); } protected virtual void PreprocessHitObjects() { } + + protected abstract IBeatmapConverter CreateBeatmapConverter(); } } diff --git a/osu.Game/Database/BeatmapInfo.cs b/osu.Game/Database/BeatmapInfo.cs index 28c9e51d2a..017f34726b 100644 --- a/osu.Game/Database/BeatmapInfo.cs +++ b/osu.Game/Database/BeatmapInfo.cs @@ -1,12 +1,12 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // 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.Modes; using SQLite.Net.Attributes; using SQLiteNetExtensions.Attributes; +using System; +using System.Linq; namespace osu.Game.Database { @@ -82,7 +82,7 @@ namespace osu.Game.Database { return starDifficulty < 0 ? (BaseDifficulty?.OverallDifficulty ?? 5) : starDifficulty; } - + set { starDifficulty = value; } } diff --git a/osu.Game/Modes/UI/HitRenderer.cs b/osu.Game/Modes/UI/HitRenderer.cs index c7c1c82781..e08570522f 100644 --- a/osu.Game/Modes/UI/HitRenderer.cs +++ b/osu.Game/Modes/UI/HitRenderer.cs @@ -50,8 +50,6 @@ namespace osu.Game.Modes.UI protected override Container Content => content; protected override bool AllObjectsJudged => Playfield.HitObjects.Children.All(h => h.Judgement.Result.HasValue); - protected abstract PlayMode PlayMode { get; } - protected Playfield Playfield; protected Beatmap Beatmap; @@ -59,7 +57,7 @@ namespace osu.Game.Modes.UI protected HitRenderer(Beatmap beatmap) { - Beatmap = beatmap.ConvertTo(PlayMode); + Beatmap = CreateBeatmapConverter().Convert(beatmap); RelativeSizeAxes = Axes.Both; @@ -103,5 +101,6 @@ namespace osu.Game.Modes.UI protected abstract DrawableHitObject GetVisualRepresentation(TObject h); protected abstract Playfield CreatePlayfield(); + protected abstract IBeatmapConverter CreateBeatmapConverter(); } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index c3097437c4..3d4a763cb8 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -71,7 +71,6 @@ -