mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 00:02:54 +08:00
Move autospin logic to mods
This commit is contained in:
parent
0dee6ceab7
commit
4d9232a895
@ -3,15 +3,18 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.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
|
||||
{
|
||||
public class OsuModSpunOut : Mod, IApplicableToDrawableHitObjects
|
||||
public class OsuModSpunOut : Mod, IApplicableToDrawableHitObjects, IUpdatableByPlayfield
|
||||
{
|
||||
public override string Name => "Spun Out";
|
||||
public override string Acronym => "SO";
|
||||
@ -22,15 +25,32 @@ namespace osu.Game.Rulesets.Osu.Mods
|
||||
public override bool Ranked => true;
|
||||
public override Type[] IncompatibleMods => new[] { typeof(ModAutoplay), typeof(OsuModAutopilot) };
|
||||
|
||||
private double lastFrameTime;
|
||||
private double frameDelay;
|
||||
|
||||
public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables)
|
||||
{
|
||||
foreach (var hitObject in drawables)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
||||
protected override void Update()
|
||||
{
|
||||
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);
|
||||
|
||||
base.Update();
|
||||
|
@ -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)
|
||||
{
|
||||
@ -95,22 +96,14 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
||||
protected override void 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)
|
||||
Rotate(6f);
|
||||
else
|
||||
{
|
||||
var thisAngle = -MathUtils.RadiansToDegrees(MathF.Atan2(mousePosition.X - DrawSize.X / 2, mousePosition.Y - DrawSize.Y / 2));
|
||||
if (Valid && tracking && Trackable)
|
||||
Rotate(delta);
|
||||
|
||||
var delta = thisAngle - lastAngle;
|
||||
|
||||
if (valid && tracking)
|
||||
Rotate(delta);
|
||||
|
||||
lastAngle = thisAngle;
|
||||
}
|
||||
lastAngle = thisAngle;
|
||||
|
||||
if (Complete && updateCompleteTick())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user