1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 10:02:59 +08:00

Move autospin logic to mods

This commit is contained in:
mcendu 2020-02-08 09:51:32 +08:00
parent 0dee6ceab7
commit 4d9232a895
3 changed files with 30 additions and 17 deletions

View File

@ -3,15 +3,18 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu.Mods namespace osu.Game.Rulesets.Osu.Mods
{ {
public class OsuModSpunOut : Mod, IApplicableToDrawableHitObjects public class OsuModSpunOut : Mod, IApplicableToDrawableHitObjects, IUpdatableByPlayfield
{ {
public override string Name => "Spun Out"; public override string Name => "Spun Out";
public override string Acronym => "SO"; public override string Acronym => "SO";
@ -22,15 +25,32 @@ namespace osu.Game.Rulesets.Osu.Mods
public override bool Ranked => true; public override bool Ranked => true;
public override Type[] IncompatibleMods => new[] { typeof(ModAutoplay), typeof(OsuModAutopilot) }; public override Type[] IncompatibleMods => new[] { typeof(ModAutoplay), typeof(OsuModAutopilot) };
private double lastFrameTime;
private double frameDelay;
public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables) public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables)
{ {
foreach (var hitObject in drawables) foreach (var hitObject in drawables)
{ {
if (hitObject is DrawableSpinner spinner) if (hitObject is DrawableSpinner spinner)
{ {
spinner.Disc.AutoSpin = true; spinner.Disc.Trackable = false;
spinner.Disc.OnUpdate += d =>
{
if (d is SpinnerDisc s)
{
if (s.Valid)
s.Rotate((float)frameDelay);
}
};
} }
} }
} }
public void Update(Playfield playfield)
{
frameDelay = playfield.Time.Current - lastFrameTime;
lastFrameTime = playfield.Time.Current;
}
} }
} }

View File

@ -177,7 +177,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
protected override void Update() protected override void Update()
{ {
Disc.Tracking = OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false; Disc.Tracking = OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false;
if (!SpmCounter.IsPresent && (Disc.Tracking || Disc.AutoSpin)) if (!SpmCounter.IsPresent && (Disc.Tracking || !Disc.Trackable))
SpmCounter.FadeIn(HitObject.TimeFadeIn); SpmCounter.FadeIn(HitObject.TimeFadeIn);
base.Update(); base.Update();

View File

@ -73,7 +73,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
} }
} }
public bool AutoSpin { get; set; } = false; public bool Valid => spinner.StartTime <= Time.Current && spinner.EndTime > Time.Current;
public bool Trackable { get; set; }
protected override bool OnMouseMove(MouseMoveEvent e) protected override bool OnMouseMove(MouseMoveEvent e)
{ {
@ -95,22 +96,14 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
var thisAngle = -MathUtils.RadiansToDegrees(MathF.Atan2(mousePosition.X - DrawSize.X / 2, mousePosition.Y - DrawSize.Y / 2));
bool valid = spinner.StartTime <= Time.Current && spinner.EndTime > Time.Current; var delta = thisAngle - lastAngle;
if (valid && AutoSpin) if (Valid && tracking && Trackable)
Rotate(6f); Rotate(delta);
else
{
var thisAngle = -MathUtils.RadiansToDegrees(MathF.Atan2(mousePosition.X - DrawSize.X / 2, mousePosition.Y - DrawSize.Y / 2));
var delta = thisAngle - lastAngle; lastAngle = thisAngle;
if (valid && tracking)
Rotate(delta);
lastAngle = thisAngle;
}
if (Complete && updateCompleteTick()) if (Complete && updateCompleteTick())
{ {