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

53 lines
2.3 KiB
C#
Raw Normal View History

// 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.
2018-04-13 09:19:50 +00:00
using System;
2020-02-10 06:14:04 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Utils;
2018-04-13 09:19:50 +00:00
using osu.Game.Graphics;
using osu.Game.Rulesets.Mods;
2020-02-08 00:59:35 +00:00
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Rulesets.Osu.Mods
{
public class OsuModSpunOut : Mod, IApplicableToDrawableHitObject
2018-04-13 09:19:50 +00:00
{
public override string Name => "Spun Out";
public override string Acronym => "SO";
public override IconUsage? Icon => OsuIcon.ModSpunOut;
2020-02-09 05:33:43 +00:00
public override ModType Type => ModType.Automation;
2018-04-13 09:19:50 +00:00
public override string Description => @"Spinners will be automatically completed.";
public override double ScoreMultiplier => 0.9;
public override Type[] IncompatibleMods => new[] { typeof(ModAutoplay), typeof(OsuModAutopilot) };
2020-02-08 00:59:35 +00:00
public void ApplyToDrawableHitObject(DrawableHitObject hitObject)
2020-02-08 00:59:35 +00:00
{
if (hitObject is DrawableSpinner spinner)
2020-02-08 00:59:35 +00:00
{
spinner.HandleUserInput = false;
spinner.OnUpdate += onSpinnerUpdate;
2020-02-08 00:59:35 +00:00
}
}
2020-02-10 20:42:34 +00:00
private void onSpinnerUpdate(Drawable drawable)
2020-02-10 20:42:34 +00:00
{
var spinner = (DrawableSpinner)drawable;
spinner.RotationTracker.Tracking = true;
// early-return if we were paused to avoid division-by-zero in the subsequent calculations.
if (Precision.AlmostEquals(spinner.Clock.Rate, 0))
return;
// because the spinner is under the gameplay clock, it is affected by rate adjustments on the track;
// for that reason using ElapsedFrameTime directly leads to fewer SPM with Half Time and more SPM with Double Time.
// for spinners we want the real (wall clock) elapsed time; to achieve that, unapply the clock rate locally here.
double rateIndependentElapsedTime = spinner.Clock.ElapsedFrameTime / spinner.Clock.Rate;
float rotationSpeed = (float)(spinner.HitObject.SpinsRequired / (spinner.HitObject.Duration / 1.01));
2022-02-13 07:16:06 +00:00
spinner.RotationTracker.AddRotation(MathUtils.RadiansToDegrees((float)rateIndependentElapsedTime * rotationSpeed * MathF.PI * 2.0f));
2020-02-10 20:42:34 +00:00
}
2018-04-13 09:19:50 +00:00
}
}