privatise checkCorrectAction, add abstract CheckValidNewAction function

This commit is contained in:
James 2022-07-13 14:26:44 +01:00
parent be3187c3a4
commit 0da1bd393c
3 changed files with 13 additions and 40 deletions

View File

@ -62,7 +62,9 @@ public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset
gameplayClock = drawableRuleset.FrameStableClock;
}
protected virtual bool CheckCorrectAction(OsuAction action)
protected abstract bool CheckValidNewAction(OsuAction action);
private bool checkCorrectAction(OsuAction action)
{
if (nonGameplayPeriods.IsInAny(gameplayClock.CurrentTime))
{
@ -81,6 +83,13 @@ protected virtual bool CheckCorrectAction(OsuAction action)
return true;
}
if (CheckValidNewAction(action))
{
LastActionPressed = action;
return true;
}
ruleset.Cursor.FlashColour(Colour4.Red, flash_duration, Easing.OutQuint);
return false;
}
@ -95,7 +104,7 @@ public InputInterceptor(InputBlockingMod mod)
public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
// if the pressed action is incorrect, block it from reaching gameplay.
=> !mod.CheckCorrectAction(e.Action);
=> !mod.checkCorrectAction(e.Action);
public void OnReleased(KeyBindingReleaseEvent<OsuAction> e)
{

View File

@ -3,7 +3,6 @@
using System;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
namespace osu.Game.Rulesets.Osu.Mods
@ -16,20 +15,6 @@ public class OsuModAlternate : InputBlockingMod
public override IconUsage? Icon => FontAwesome.Solid.Keyboard;
public override Type[] IncompatibleMods => base.IncompatibleMods.Concat(new[] { typeof(OsuModSingleTap) }).ToArray();
protected override bool CheckCorrectAction(OsuAction action)
{
if (base.CheckCorrectAction(action))
return true;
if (LastActionPressed != action)
{
// User alternated correctly.
LastActionPressed = action;
return true;
}
Ruleset.Cursor.FlashColour(Colour4.Red, FLASH_DURATION, Easing.OutQuint);
return false;
}
protected override bool CheckValidNewAction(OsuAction action) => LastActionPressed != action;
}
}

View File

@ -3,7 +3,6 @@
using System;
using System.Linq;
using osu.Framework.Graphics;
namespace osu.Game.Rulesets.Osu.Mods
{
@ -14,26 +13,6 @@ public class OsuModSingleTap : InputBlockingMod
public override string Description => @"You must only use one key!";
public override Type[] IncompatibleMods => base.IncompatibleMods.Concat(new[] { typeof(OsuModAlternate) }).ToArray();
protected override bool CheckCorrectAction(OsuAction action)
{
if (base.CheckCorrectAction(action))
return true;
if (LastActionPressed == null)
{
// First keypress, store the expected action.
LastActionPressed = action;
return true;
}
if (LastActionPressed == action)
{
// User singletapped correctly.
return true;
}
Ruleset.Cursor.FlashColour(Colour4.Red, FLASH_DURATION, Easing.OutQuint);
return false;
}
protected override bool CheckValidNewAction(OsuAction action) => LastActionPressed == null || LastActionPressed == action;
}
}