osu/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
3.3 KiB
C#
Raw Normal View History

2019-08-19 20:54:07 +00:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2022-06-17 07:37:17 +00:00
#nullable disable
2019-08-19 20:54:07 +00:00
using System;
using osu.Framework.Bindables;
2019-08-19 20:54:07 +00:00
using osu.Framework.Graphics.Sprites;
using osu.Framework.Utils;
using osu.Game.Configuration;
2019-08-19 20:54:07 +00:00
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
2019-08-19 20:54:07 +00:00
using osu.Game.Rulesets.Osu.Objects.Drawables;
2019-08-20 15:23:50 +00:00
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.UI;
2019-08-21 19:37:56 +00:00
using osuTK;
2019-08-19 20:54:07 +00:00
namespace osu.Game.Rulesets.Osu.Mods
{
internal class OsuModMagnetised : Mod, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>
2019-08-19 20:54:07 +00:00
{
public override string Name => "Magnetised";
public override string Acronym => "MG";
public override IconUsage? Icon => FontAwesome.Solid.Magnet;
2019-08-19 20:54:07 +00:00
public override ModType Type => ModType.Fun;
public override string Description => "No need to chase the circles your cursor is a magnet!";
2019-08-19 20:54:07 +00:00
public override double ScoreMultiplier => 1;
public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay), typeof(OsuModRelax) };
2019-08-19 20:54:07 +00:00
private IFrameStableClock gameplayClock;
[SettingSource("Attraction strength", "How strong the pull is.", 0)]
public BindableFloat AttractionStrength { get; } = new BindableFloat(0.5f)
{
Precision = 0.05f,
2022-02-02 07:26:10 +00:00
MinValue = 0.05f,
MaxValue = 1.0f,
};
2022-01-05 12:05:22 +00:00
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
{
gameplayClock = drawableRuleset.FrameStableClock;
2022-02-02 07:26:10 +00:00
// 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.
2022-01-06 09:38:30 +00:00
drawableRuleset.Playfield.DisplayJudgements.Value = false;
(drawableRuleset.Playfield as OsuPlayfield)?.FollowPoints.Hide();
2022-01-05 12:05:22 +00:00
}
2019-08-19 20:54:07 +00:00
public void Update(Playfield playfield)
{
2022-02-02 06:10:56 +00:00
var cursorPos = playfield.Cursor.ActiveCursor.DrawPosition;
2022-01-06 15:31:30 +00:00
2022-02-02 07:26:10 +00:00
foreach (var drawable in playfield.HitObjectContainer.AliveObjects)
2019-08-19 20:54:07 +00:00
{
2022-02-02 06:10:56 +00:00
switch (drawable)
2019-08-19 20:54:07 +00:00
{
2022-02-02 06:10:56 +00:00
case DrawableHitCircle circle:
easeTo(circle, cursorPos);
2022-02-02 06:10:56 +00:00
break;
case DrawableSlider slider:
if (!slider.HeadCircle.Result.HasResult)
easeTo(slider, cursorPos);
2022-02-02 06:10:56 +00:00
else
easeTo(slider, cursorPos - slider.Ball.DrawPosition);
2019-08-19 20:54:07 +00:00
2022-02-02 06:10:56 +00:00
break;
2019-08-21 19:37:56 +00:00
}
}
}
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);
2022-01-06 15:04:38 +00:00
hitObject.Position = new Vector2(x, y);
2019-08-19 20:54:07 +00:00
}
}
}