Skip to content

Commit

Permalink
privatise checkCorrectAction, add abstract CheckValidNewAction function
Browse files Browse the repository at this point in the history
  • Loading branch information
tsunyoku committed Jul 13, 2022
1 parent be3187c commit 0da1bd3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 40 deletions.
13 changes: 11 additions & 2 deletions osu.Game.Rulesets.Osu/Mods/InputBlockingMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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;
}

Expand All @@ -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)
{
Expand Down
17 changes: 1 addition & 16 deletions osu.Game.Rulesets.Osu/Mods/OsuModAlternate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;

namespace osu.Game.Rulesets.Osu.Mods
Expand All @@ -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;
}
}
23 changes: 1 addition & 22 deletions osu.Game.Rulesets.Osu/Mods/OsuModSingleTap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Linq;
using osu.Framework.Graphics;

namespace osu.Game.Rulesets.Osu.Mods
{
Expand All @@ -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;
}
}

0 comments on commit 0da1bd3

Please sign in to comment.