1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 11:22:57 +08:00

Clean up logic and variables

This commit is contained in:
Dean Herbert 2018-08-16 18:18:15 +09:00
parent 870f6bea47
commit bc22a28fef

View File

@ -7,13 +7,14 @@ using System.Linq;
using osu.Framework.Input.States; using osu.Framework.Input.States;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using static osu.Game.Input.Handlers.ReplayInputHandler; using static osu.Game.Input.Handlers.ReplayInputHandler;
namespace osu.Game.Rulesets.Osu.Mods namespace osu.Game.Rulesets.Osu.Mods
{ {
public class OsuModRelax : ModRelax, IApplicableFailOverride, IUpdatableByPlayfield public class OsuModRelax : ModRelax, IApplicableFailOverride, IUpdatableByPlayfield, IApplicableToRulesetContainer<OsuHitObject>
{ {
public override string Description => @"You don't need to click. Give your clicking/tapping fingers a break from the heat of things."; public override string Description => @"You don't need to click. Give your clicking/tapping fingers a break from the heat of things.";
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModAutopilot)).ToArray(); public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModAutopilot)).ToArray();
@ -22,8 +23,8 @@ namespace osu.Game.Rulesets.Osu.Mods
public void Update(Playfield playfield) public void Update(Playfield playfield)
{ {
bool hitStill = false; bool requiresHold = false;
bool hitOnce = false; bool requiresHit = false;
const float relax_leniency = 3; const float relax_leniency = 3;
@ -35,45 +36,54 @@ namespace osu.Game.Rulesets.Osu.Mods
double time = osuHit.Clock.CurrentTime; double time = osuHit.Clock.CurrentTime;
double relativetime = time - osuHit.HitObject.StartTime; double relativetime = time - osuHit.HitObject.StartTime;
if (osuHit.IsAlive && time >= osuHit.HitObject.StartTime - relax_leniency) if (time < osuHit.HitObject.StartTime - relax_leniency) continue;
{
if (osuHit.HitObject is IHasEndTime hasEnd && time > hasEnd.EndTime || osuHit.IsHit)
continue;
hitStill |= osuHit is DrawableSlider slider && (slider.Ball.IsHovered || osuHit.IsHovered) || osuHit is DrawableSpinner; if (osuHit.HitObject is IHasEndTime hasEnd && time > hasEnd.EndTime || osuHit.IsHit)
continue;
hitOnce |= osuHit is DrawableHitCircle && osuHit.IsHovered && osuHit.HitObject.HitWindows.CanBeHit(relativetime); requiresHit |= osuHit is DrawableHitCircle && osuHit.IsHovered && osuHit.HitObject.HitWindows.CanBeHit(relativetime);
} requiresHold |= osuHit is DrawableSlider slider && (slider.Ball.IsHovered || osuHit.IsHovered) || osuHit is DrawableSpinner;
} }
var osuHitSample = playfield.HitObjects.Objects.First(d => d is DrawableOsuHitObject) as DrawableOsuHitObject; if (requiresHit)
if (hitOnce)
{ {
hit(osuHitSample, false); addAction(false);
hit(osuHitSample, true); addAction(true);
} }
hit(osuHitSample, hitStill);
addAction(requiresHold);
} }
private bool wasHit; private bool wasHit;
private bool wasLeft; private bool wasLeft;
private void hit(DrawableOsuHitObject osuHit, bool hitting) private OsuInputManager osuInputManager;
private void addAction(bool hitting)
{ {
if (wasHit == hitting) if (wasHit == hitting)
return; return;
wasHit = hitting; wasHit = hitting;
var state = new ReplayState<OsuAction> var state = new ReplayState<OsuAction>
{ {
PressedActions = new List<OsuAction>() PressedActions = new List<OsuAction>()
}; };
if (hitting) if (hitting)
{ {
state.PressedActions.Add(wasLeft ? OsuAction.LeftButton : OsuAction.RightButton); state.PressedActions.Add(wasLeft ? OsuAction.LeftButton : OsuAction.RightButton);
wasLeft = !wasLeft; wasLeft = !wasLeft;
} }
osuHit.OsuActionInputManager.HandleCustomInput(new InputState(), state);
osuInputManager.HandleCustomInput(new InputState(), state);
}
public void ApplyToRulesetContainer(RulesetContainer<OsuHitObject> rulesetContainer)
{
// grab the input manager for future use.
osuInputManager = (OsuInputManager)rulesetContainer.KeyBindingInputManager;
} }
} }
} }