From 18f2e92a48b4ba9e044143d04972470980666fc4 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 16 Nov 2017 20:35:57 +0900 Subject: [PATCH] Rework mod applications to hitobject/rulesetcontainer for DifficultyCalculator --- osu.Game.Rulesets.Mania/Mods/ManiaMod.cs | 6 ++--- osu.Game.Rulesets.Osu/Mods/OsuMod.cs | 27 ++++++++++++------- osu.Game/Beatmaps/DifficultyCalculator.cs | 4 +++ osu.Game/Rulesets/Mods/IApplicableMod.cs | 22 --------------- .../Rulesets/Mods/IApplicableToHitObject.cs | 20 ++++++++++++++ .../Mods/IApplicableToRulesetContainer.cs | 21 +++++++++++++++ osu.Game/Rulesets/Mods/ModAutoplay.cs | 4 +-- osu.Game/Rulesets/UI/RulesetContainer.cs | 6 ++++- osu.Game/osu.Game.csproj | 3 ++- 9 files changed, 74 insertions(+), 39 deletions(-) delete mode 100644 osu.Game/Rulesets/Mods/IApplicableMod.cs create mode 100644 osu.Game/Rulesets/Mods/IApplicableToHitObject.cs create mode 100644 osu.Game/Rulesets/Mods/IApplicableToRulesetContainer.cs diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs b/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs index 037c3bd567..164309c227 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs @@ -86,18 +86,17 @@ namespace osu.Game.Rulesets.Mania.Mods public override Type[] IncompatibleMods => new[] { typeof(ModFlashlight) }; } - public class ManiaModRandom : Mod, IApplicableMod + public class ManiaModRandom : Mod, IApplicableToRulesetContainer { public override string Name => "Random"; public override string ShortenedName => "RD"; - public override FontAwesome Icon => FontAwesome.fa_osu_dice; + public override FontAwesome Icon => FontAwesome.fa_osu_dice; public override string Description => @"Shuffle around the notes!"; public override double ScoreMultiplier => 1; public void ApplyToRulesetContainer(RulesetContainer rulesetContainer) { int availableColumns = ((ManiaRulesetContainer)rulesetContainer).AvailableColumns; - var shuffledColumns = Enumerable.Range(0, availableColumns).OrderBy(item => RNG.Next()).ToList(); rulesetContainer.Objects.OfType().ForEach(h => h.Column = shuffledColumns[h.Column]); @@ -188,6 +187,7 @@ namespace osu.Game.Rulesets.Mania.Mods base.ApplyToRulesetContainer(rulesetContainer); } + protected override Score CreateReplayScore(Beatmap beatmap) => new Score { User = new User { Username = "osu!topus!" }, diff --git a/osu.Game.Rulesets.Osu/Mods/OsuMod.cs b/osu.Game.Rulesets.Osu/Mods/OsuMod.cs index 2970055bff..596fe27504 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuMod.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuMod.cs @@ -33,22 +33,29 @@ namespace osu.Game.Rulesets.Osu.Mods public override double ScoreMultiplier => 1.06; } - public class OsuModHardRock : ModHardRock, IApplicableMod + public class OsuModHardRock : ModHardRock, IApplicableToHitObject { public override double ScoreMultiplier => 1.06; public override bool Ranked => true; - public void ApplyToRulesetContainer(RulesetContainer rulesetContainer) + public void ApplyToHitObject(OsuHitObject hitObject) + { + hitObject.Position = new Vector2(hitObject.Position.X, OsuPlayfield.BASE_SIZE.Y - hitObject.Y); + + var slider = hitObject as Slider; + if (slider == null) + return; + + var newControlPoints = new List(); + slider.ControlPoints.ForEach(c => newControlPoints.Add(new Vector2(c.X, OsuPlayfield.BASE_SIZE.Y - c.Y))); + + slider.ControlPoints = newControlPoints; + slider.Curve?.Calculate(); // Recalculate the slider curve + } + + public void ApplyToHitObjects(RulesetContainer rulesetContainer) { - rulesetContainer.Objects.OfType().ForEach(h => h.Position = new Vector2(h.Position.X, OsuPlayfield.BASE_SIZE.Y - h.Y)); - rulesetContainer.Objects.OfType().ForEach(s => - { - var newControlPoints = new List(); - s.ControlPoints.ForEach(c => newControlPoints.Add(new Vector2(c.X, OsuPlayfield.BASE_SIZE.Y - c.Y))); - s.ControlPoints = newControlPoints; - s.Curve?.Calculate(); // Recalculate the slider curve - }); } } diff --git a/osu.Game/Beatmaps/DifficultyCalculator.cs b/osu.Game/Beatmaps/DifficultyCalculator.cs index f6cc535aca..54dab07b31 100644 --- a/osu.Game/Beatmaps/DifficultyCalculator.cs +++ b/osu.Game/Beatmaps/DifficultyCalculator.cs @@ -49,6 +49,10 @@ namespace osu.Game.Beatmaps var clock = new StopwatchClock(); mods.OfType().ForEach(m => m.ApplyToClock(clock)); + foreach (var mod in mods.OfType>()) + foreach (var obj in Objects) + mod.ApplyToHitObject(obj); + TimeRate = clock.Rate; } diff --git a/osu.Game/Rulesets/Mods/IApplicableMod.cs b/osu.Game/Rulesets/Mods/IApplicableMod.cs deleted file mode 100644 index 1957952720..0000000000 --- a/osu.Game/Rulesets/Mods/IApplicableMod.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Game.Rulesets.Objects; -using osu.Game.Rulesets.UI; - -namespace osu.Game.Rulesets.Mods -{ - /// - /// An interface for mods that are applied to a RulesetContainer. - /// - /// The type of HitObject the RulesetContainer contains. - public interface IApplicableMod - where TObject : HitObject - { - /// - /// Applies the mod to a RulesetContainer. - /// - /// The RulesetContainer to apply the mod to. - void ApplyToRulesetContainer(RulesetContainer rulesetContainer); - } -} diff --git a/osu.Game/Rulesets/Mods/IApplicableToHitObject.cs b/osu.Game/Rulesets/Mods/IApplicableToHitObject.cs new file mode 100644 index 0000000000..099234d9c1 --- /dev/null +++ b/osu.Game/Rulesets/Mods/IApplicableToHitObject.cs @@ -0,0 +1,20 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Objects; + +namespace osu.Game.Rulesets.Mods +{ + /// + /// An interface for s that can be applied to s. + /// + public interface IApplicableToHitObject + where TObject : HitObject + { + /// + /// Applies this to a . + /// + /// The to apply to. + void ApplyToHitObject(TObject hitObject); + } +} diff --git a/osu.Game/Rulesets/Mods/IApplicableToRulesetContainer.cs b/osu.Game/Rulesets/Mods/IApplicableToRulesetContainer.cs new file mode 100644 index 0000000000..9b23dd58f9 --- /dev/null +++ b/osu.Game/Rulesets/Mods/IApplicableToRulesetContainer.cs @@ -0,0 +1,21 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.UI; + +namespace osu.Game.Rulesets.Mods +{ + /// + /// An interface for s that can be applied to s. + /// + public interface IApplicableToRulesetContainer + where TObject : HitObject + { + /// + /// Applies this to a . + /// + /// The to apply to. + void ApplyToRulesetContainer(RulesetContainer rulesetContainer); + } +} diff --git a/osu.Game/Rulesets/Mods/ModAutoplay.cs b/osu.Game/Rulesets/Mods/ModAutoplay.cs index ece0deba84..d94d4ba0db 100644 --- a/osu.Game/Rulesets/Mods/ModAutoplay.cs +++ b/osu.Game/Rulesets/Mods/ModAutoplay.cs @@ -10,7 +10,7 @@ using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets.Mods { - public abstract class ModAutoplay : ModAutoplay, IApplicableMod + public abstract class ModAutoplay : ModAutoplay, IApplicableToRulesetContainer where T : HitObject { protected abstract Score CreateReplayScore(Beatmap beatmap); @@ -30,4 +30,4 @@ namespace osu.Game.Rulesets.Mods public override double ScoreMultiplier => 0; public override Type[] IncompatibleMods => new[] { typeof(ModRelax), typeof(ModSuddenDeath), typeof(ModNoFail) }; } -} \ No newline at end of file +} diff --git a/osu.Game/Rulesets/UI/RulesetContainer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs index 278814ea7e..6726d94995 100644 --- a/osu.Game/Rulesets/UI/RulesetContainer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -212,7 +212,11 @@ namespace osu.Game.Rulesets.UI if (mods == null) return; - foreach (var mod in mods.OfType>()) + foreach (var mod in mods.OfType>()) + foreach (var obj in Beatmap.HitObjects) + mod.ApplyToHitObject(obj); + + foreach (var mod in mods.OfType>()) mod.ApplyToRulesetContainer(this); } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index ac1498c9d9..7b479bdba2 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -549,9 +549,10 @@ - + +