From 10287e01505880f236667a636968c814f250c137 Mon Sep 17 00:00:00 2001 From: Gabe Livengood <47010459+ggliv@users.noreply.github.com> Date: Thu, 26 May 2022 00:08:00 -0400 Subject: [PATCH] initial implementation --- .../Mods/OsuEaseHitObjectPositionsMod.cs | 75 +++++++++++++++++++ .../Mods/OsuModMagnetised.cs | 59 ++------------- osu.Game.Rulesets.Osu/Mods/OsuModRepel.cs | 39 ++++++++++ osu.Game.Rulesets.Osu/OsuRuleset.cs | 2 +- 4 files changed, 121 insertions(+), 54 deletions(-) create mode 100644 osu.Game.Rulesets.Osu/Mods/OsuEaseHitObjectPositionsMod.cs create mode 100644 osu.Game.Rulesets.Osu/Mods/OsuModRepel.cs diff --git a/osu.Game.Rulesets.Osu/Mods/OsuEaseHitObjectPositionsMod.cs b/osu.Game.Rulesets.Osu/Mods/OsuEaseHitObjectPositionsMod.cs new file mode 100644 index 0000000000..d81d86dc65 --- /dev/null +++ b/osu.Game.Rulesets.Osu/Mods/OsuEaseHitObjectPositionsMod.cs @@ -0,0 +1,75 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Bindables; +using osu.Framework.Utils; +using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Rulesets.Osu.Objects.Drawables; +using osu.Game.Rulesets.Osu.UI; +using osu.Game.Rulesets.UI; +using osuTK; + +namespace osu.Game.Rulesets.Osu.Mods +{ + public abstract class OsuEaseHitObjectPositionsMod : Mod, IUpdatableByPlayfield, IApplicableToDrawableRuleset + { + public override ModType Type => ModType.Fun; + public override double ScoreMultiplier => 1; + public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay) }; + + protected BindableFloat EasementStrength = new BindableFloat(0.5f); + protected Vector2 CursorPosition; + protected DrawableHitObject WorkingHitObject; + protected abstract Vector2 DestinationVector { get; } + + private IFrameStableClock gameplayClock; + + public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) + { + gameplayClock = drawableRuleset.FrameStableClock; + + // Hide judgment displays and follow points as they won't make any sense. + // Judgements can potentially be turned on in a future where they display at a position relative to their drawable counterpart. + drawableRuleset.Playfield.DisplayJudgements.Value = false; + (drawableRuleset.Playfield as OsuPlayfield)?.FollowPoints.Hide(); + } + + public void Update(Playfield playfield) + { + CursorPosition = playfield.Cursor.ActiveCursor.DrawPosition; + + foreach (var drawable in playfield.HitObjectContainer.AliveObjects) + { + WorkingHitObject = drawable; + switch (drawable) + { + case DrawableHitCircle circle: + easeHitObjectPositionToVector(circle, DestinationVector); + break; + + case DrawableSlider slider: + + if (!slider.HeadCircle.Result.HasResult) + easeHitObjectPositionToVector(slider, DestinationVector); + else + easeHitObjectPositionToVector(slider, DestinationVector - slider.Ball.DrawPosition); + + break; + } + } + } + + private void easeHitObjectPositionToVector(DrawableHitObject hitObject, Vector2 destination) + { + double dampLength = Interpolation.Lerp(3000, 40, EasementStrength.Value); + + float x = (float)Interpolation.DampContinuously(hitObject.X, Math.Clamp(destination.X, 0, OsuPlayfield.BASE_SIZE.X), dampLength, gameplayClock.ElapsedFrameTime); + float y = (float)Interpolation.DampContinuously(hitObject.Y, Math.Clamp(destination.Y, 0, OsuPlayfield.BASE_SIZE.Y), dampLength, gameplayClock.ElapsedFrameTime); + + hitObject.Position = new Vector2(x, y); + } + } +} diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs b/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs index ca6e9cfb1d..ca69085e31 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs @@ -2,31 +2,23 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics.Sprites; -using osu.Framework.Utils; using osu.Game.Configuration; -using osu.Game.Rulesets.Mods; -using osu.Game.Rulesets.Objects.Drawables; -using osu.Game.Rulesets.Osu.Objects; -using osu.Game.Rulesets.Osu.Objects.Drawables; -using osu.Game.Rulesets.Osu.UI; -using osu.Game.Rulesets.UI; using osuTK; namespace osu.Game.Rulesets.Osu.Mods { - internal class OsuModMagnetised : Mod, IUpdatableByPlayfield, IApplicableToDrawableRuleset + internal class OsuModMagnetised : OsuEaseHitObjectPositionsMod { public override string Name => "Magnetised"; public override string Acronym => "MG"; public override IconUsage? Icon => FontAwesome.Solid.Magnet; - public override ModType Type => ModType.Fun; public override string Description => "No need to chase the circles – your cursor is a magnet!"; - public override double ScoreMultiplier => 1; - public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay), typeof(OsuModRelax) }; + public override Type[] IncompatibleMods => base.IncompatibleMods.Concat(new[] { typeof(OsuModRelax), typeof(OsuModRepel) }).ToArray(); - private IFrameStableClock gameplayClock; + protected override Vector2 DestinationVector => CursorPosition; [SettingSource("Attraction strength", "How strong the pull is.", 0)] public BindableFloat AttractionStrength { get; } = new BindableFloat(0.5f) @@ -36,48 +28,9 @@ internal class OsuModMagnetised : Mod, IUpdatableByPlayfield, IApplicableToDrawa MaxValue = 1.0f, }; - public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) + public OsuModMagnetised() { - gameplayClock = drawableRuleset.FrameStableClock; - - // Hide judgment displays and follow points as they won't make any sense. - // Judgements can potentially be turned on in a future where they display at a position relative to their drawable counterpart. - drawableRuleset.Playfield.DisplayJudgements.Value = false; - (drawableRuleset.Playfield as OsuPlayfield)?.FollowPoints.Hide(); - } - - public void Update(Playfield playfield) - { - var cursorPos = playfield.Cursor.ActiveCursor.DrawPosition; - - foreach (var drawable in playfield.HitObjectContainer.AliveObjects) - { - switch (drawable) - { - case DrawableHitCircle circle: - easeTo(circle, cursorPos); - break; - - case DrawableSlider slider: - - if (!slider.HeadCircle.Result.HasResult) - easeTo(slider, cursorPos); - else - easeTo(slider, cursorPos - slider.Ball.DrawPosition); - - break; - } - } - } - - private void easeTo(DrawableHitObject hitObject, Vector2 destination) - { - double dampLength = Interpolation.Lerp(3000, 40, AttractionStrength.Value); - - float x = (float)Interpolation.DampContinuously(hitObject.X, destination.X, dampLength, gameplayClock.ElapsedFrameTime); - float y = (float)Interpolation.DampContinuously(hitObject.Y, destination.Y, dampLength, gameplayClock.ElapsedFrameTime); - - hitObject.Position = new Vector2(x, y); + EasementStrength.BindTo(AttractionStrength); } } } diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModRepel.cs b/osu.Game.Rulesets.Osu/Mods/OsuModRepel.cs new file mode 100644 index 0000000000..35f369d9c5 --- /dev/null +++ b/osu.Game.Rulesets.Osu/Mods/OsuModRepel.cs @@ -0,0 +1,39 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Linq; +using osu.Framework.Bindables; +using osu.Framework.Graphics.Sprites; +using osu.Game.Configuration; +using osuTK; + +namespace osu.Game.Rulesets.Osu.Mods +{ + internal class OsuModRepel : OsuEaseHitObjectPositionsMod + { + public override string Name => "Repel"; + public override string Acronym => "RP"; + public override IconUsage? Icon => FontAwesome.Solid.ExpandArrowsAlt; + public override string Description => "Run away!"; + public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModMagnetised)).ToArray(); + + [SettingSource("Repulsion strength", "How strong the repulsion is.", 0)] + public BindableFloat RepulsionStrength { get; } = new BindableFloat(0.5f) + { + Precision = 0.05f, + MinValue = 0.05f, + MaxValue = 1.0f, + }; + + protected override Vector2 DestinationVector => new Vector2( + 2 * WorkingHitObject.X - CursorPosition.X, + 2 * WorkingHitObject.Y - CursorPosition.Y + ); + + public OsuModRepel() + { + EasementStrength.BindTo(RepulsionStrength); + } + } +} diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 207e7a4ab0..09b85726ca 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -195,7 +195,7 @@ public override IEnumerable GetModsFor(ModType type) new OsuModApproachDifferent(), new OsuModMuted(), new OsuModNoScope(), - new OsuModMagnetised(), + new MultiMod(new OsuModMagnetised(), new OsuModRepel()), new ModAdaptiveSpeed() };