-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "Single Tap" mod for osu! ruleset #17781
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
154 changes: 154 additions & 0 deletions
154
osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModSingleTap.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
using osu.Game.Beatmaps; | ||
using osu.Game.Beatmaps.Timing; | ||
using osu.Game.Rulesets.Objects; | ||
using osu.Game.Rulesets.Osu.Mods; | ||
using osu.Game.Rulesets.Osu.Objects; | ||
using osu.Game.Rulesets.Osu.Replays; | ||
using osu.Game.Rulesets.Replays; | ||
using osuTK; | ||
|
||
namespace osu.Game.Rulesets.Osu.Tests.Mods | ||
{ | ||
public class TestSceneOsuModSingleTap : OsuModTestScene | ||
{ | ||
[Test] | ||
public void TestInputAtIntro() => CreateModTest(new ModTestData | ||
{ | ||
Mod = new OsuModSingleTap(), | ||
PassCondition = () => Player.ScoreProcessor.Combo.Value == 1, | ||
Autoplay = false, | ||
Beatmap = new Beatmap | ||
{ | ||
HitObjects = new List<HitObject> | ||
{ | ||
new HitCircle | ||
{ | ||
StartTime = 1000, | ||
Position = new Vector2(100), | ||
}, | ||
}, | ||
}, | ||
ReplayFrames = new List<ReplayFrame> | ||
{ | ||
new OsuReplayFrame(500, new Vector2(200), OsuAction.LeftButton), | ||
new OsuReplayFrame(501, new Vector2(200)), | ||
new OsuReplayFrame(1000, new Vector2(100), OsuAction.LeftButton), | ||
} | ||
}); | ||
|
||
[Test] | ||
public void TestInputAlternating() => CreateModTest(new ModTestData | ||
{ | ||
Mod = new OsuModSingleTap(), | ||
PassCondition = () => Player.ScoreProcessor.Combo.Value == 1, | ||
Autoplay = false, | ||
Beatmap = new Beatmap | ||
{ | ||
HitObjects = new List<HitObject> | ||
{ | ||
new HitCircle | ||
{ | ||
StartTime = 500, | ||
Position = new Vector2(100), | ||
}, | ||
new HitCircle | ||
{ | ||
StartTime = 1000, | ||
Position = new Vector2(200, 100), | ||
}, | ||
new HitCircle | ||
{ | ||
StartTime = 1500, | ||
Position = new Vector2(300, 100), | ||
}, | ||
new HitCircle | ||
{ | ||
StartTime = 2000, | ||
Position = new Vector2(400, 100), | ||
}, | ||
}, | ||
}, | ||
ReplayFrames = new List<ReplayFrame> | ||
{ | ||
new OsuReplayFrame(500, new Vector2(100), OsuAction.LeftButton), | ||
new OsuReplayFrame(501, new Vector2(100)), | ||
new OsuReplayFrame(1000, new Vector2(200, 100), OsuAction.RightButton), | ||
new OsuReplayFrame(1001, new Vector2(200, 100)), | ||
new OsuReplayFrame(1500, new Vector2(300, 100), OsuAction.LeftButton), | ||
new OsuReplayFrame(1501, new Vector2(300, 100)), | ||
new OsuReplayFrame(2000, new Vector2(400, 100), OsuAction.RightButton), | ||
new OsuReplayFrame(2001, new Vector2(400, 100)), | ||
} | ||
}); | ||
|
||
[Test] | ||
public void TestInputSingular() => CreateModTest(new ModTestData | ||
{ | ||
Mod = new OsuModSingleTap(), | ||
PassCondition = () => Player.ScoreProcessor.HighestCombo.Value == 1, | ||
Autoplay = false, | ||
Beatmap = new Beatmap | ||
{ | ||
HitObjects = new List<HitObject> | ||
{ | ||
new HitCircle | ||
{ | ||
StartTime = 500, | ||
Position = new Vector2(100), | ||
}, | ||
new HitCircle | ||
{ | ||
StartTime = 1000, | ||
Position = new Vector2(200, 100), | ||
}, | ||
}, | ||
}, | ||
ReplayFrames = new List<ReplayFrame> | ||
{ | ||
new OsuReplayFrame(500, new Vector2(100), OsuAction.LeftButton), | ||
new OsuReplayFrame(501, new Vector2(100)), | ||
new OsuReplayFrame(1000, new Vector2(200, 100), OsuAction.LeftButton), | ||
} | ||
}); | ||
|
||
[Test] | ||
public void TestInputSingularWithBreak() => CreateModTest(new ModTestData | ||
{ | ||
Mod = new OsuModSingleTap(), | ||
PassCondition = () => Player.ScoreProcessor.Combo.Value == 2, | ||
Autoplay = false, | ||
Beatmap = new Beatmap | ||
{ | ||
Breaks = new List<BreakPeriod> | ||
{ | ||
new BreakPeriod(500, 2250), | ||
}, | ||
HitObjects = new List<HitObject> | ||
{ | ||
new HitCircle | ||
{ | ||
StartTime = 500, | ||
Position = new Vector2(100), | ||
}, | ||
new HitCircle | ||
{ | ||
StartTime = 2500, | ||
Position = new Vector2(100), | ||
} | ||
} | ||
}, | ||
ReplayFrames = new List<ReplayFrame> | ||
{ | ||
new OsuReplayFrame(500, new Vector2(100), OsuAction.LeftButton), | ||
new OsuReplayFrame(501, new Vector2(100)), | ||
new OsuReplayFrame(2500, new Vector2(100), OsuAction.RightButton), | ||
new OsuReplayFrame(2501, new Vector2(100)), | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Input.Bindings; | ||
using osu.Framework.Input.Events; | ||
using osu.Game.Rulesets.Mods; | ||
using osu.Game.Rulesets.Scoring; | ||
using osu.Game.Rulesets.UI; | ||
using osu.Game.Rulesets.Osu.Objects; | ||
using osu.Game.Screens.Play; | ||
|
||
namespace osu.Game.Rulesets.Osu.Mods | ||
{ | ||
|
||
public abstract class InputBlockingMod : Mod, IApplicableToDrawableRuleset<OsuHitObject>, IApplicableToPlayer | ||
{ | ||
|
||
public override double ScoreMultiplier => 1.0; | ||
public override ModType Type => ModType.Conversion; | ||
|
||
protected IFrameStableClock gameplayClock; | ||
protected IBindable<bool> isBreakTime; | ||
protected double firstObjectValidJudgementTime; | ||
protected const double flash_duration = 1000; | ||
|
||
protected OsuAction? lastActionPressed; | ||
|
||
protected DrawableRuleset<OsuHitObject> ruleset; | ||
|
||
public virtual bool checkCorrectAction(OsuAction action){ | ||
if (isBreakTime.Value) | ||
return true; | ||
|
||
if (gameplayClock.CurrentTime < firstObjectValidJudgementTime) | ||
return true; | ||
|
||
switch (action) | ||
{ | ||
case OsuAction.LeftButton: | ||
case OsuAction.RightButton: | ||
break; | ||
|
||
// Any action which is not left or right button should be ignored. | ||
default: | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset) | ||
{ | ||
ruleset = drawableRuleset; | ||
drawableRuleset.KeyBindingInputManager.Add(new InputInterceptor(this)); | ||
|
||
OsuHitObject firstHitObject; | ||
try | ||
{ | ||
firstHitObject = ruleset.Beatmap.HitObjects[0]; | ||
} | ||
catch(IndexOutOfRangeException) | ||
{ | ||
firstHitObject = null; | ||
} | ||
|
||
firstObjectValidJudgementTime = (firstHitObject?.StartTime ?? 0) - (firstHitObject?.HitWindows.WindowFor(HitResult.Meh) ?? 0); | ||
|
||
gameplayClock = drawableRuleset.FrameStableClock; | ||
} | ||
|
||
public void ApplyToPlayer(Player player) | ||
{ | ||
isBreakTime = player.IsBreakTime.GetBoundCopy(); | ||
isBreakTime.ValueChanged += e => | ||
{ | ||
if (e.NewValue) | ||
lastActionPressed = null; | ||
}; | ||
} | ||
|
||
|
||
private class InputInterceptor : Component, IKeyBindingHandler<OsuAction> | ||
{ | ||
private readonly InputBlockingMod mod; | ||
|
||
public InputInterceptor(InputBlockingMod mod) | ||
{ | ||
this.mod = mod; | ||
} | ||
|
||
public bool OnPressed(KeyBindingPressEvent<OsuAction> e) | ||
=> !mod.checkCorrectAction(e.Action); | ||
|
||
public void OnReleased(KeyBindingReleaseEvent<OsuAction> e) | ||
{ | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,78 +2,25 @@ | |
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Linq; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Input.Bindings; | ||
using osu.Framework.Input.Events; | ||
using osu.Game.Rulesets.Mods; | ||
using osu.Game.Rulesets.Osu.Objects; | ||
using osu.Game.Rulesets.Scoring; | ||
using osu.Game.Rulesets.UI; | ||
using osu.Game.Screens.Play; | ||
|
||
namespace osu.Game.Rulesets.Osu.Mods | ||
{ | ||
public class OsuModAlternate : Mod, IApplicableToDrawableRuleset<OsuHitObject>, IApplicableToPlayer | ||
public class OsuModAlternate : InputBlockingMod | ||
{ | ||
public override string Name => @"Alternate"; | ||
public override string Acronym => @"AL"; | ||
public override string Name => "Alternate"; | ||
public override string Acronym => "AL"; | ||
Comment on lines
-21
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert this |
||
public override string Description => @"Don't use the same key twice in a row!"; | ||
public override double ScoreMultiplier => 1.0; | ||
public override Type[] IncompatibleMods => new[] { typeof(ModAutoplay) }; | ||
public override ModType Type => ModType.Conversion; | ||
public override IconUsage? Icon => FontAwesome.Solid.Keyboard; | ||
public override Type[] IncompatibleMods => new[] { typeof(ModAutoplay) }; | ||
public override bool checkCorrectAction(OsuAction action) | ||
|
||
private double firstObjectValidJudgementTime; | ||
private IBindable<bool> isBreakTime; | ||
private const double flash_duration = 1000; | ||
private OsuAction? lastActionPressed; | ||
private DrawableRuleset<OsuHitObject> ruleset; | ||
|
||
private IFrameStableClock gameplayClock; | ||
|
||
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset) | ||
{ | ||
ruleset = drawableRuleset; | ||
drawableRuleset.KeyBindingInputManager.Add(new InputInterceptor(this)); | ||
|
||
var firstHitObject = ruleset.Objects.FirstOrDefault(); | ||
firstObjectValidJudgementTime = (firstHitObject?.StartTime ?? 0) - (firstHitObject?.HitWindows.WindowFor(HitResult.Meh) ?? 0); | ||
|
||
gameplayClock = drawableRuleset.FrameStableClock; | ||
} | ||
|
||
public void ApplyToPlayer(Player player) | ||
{ | ||
isBreakTime = player.IsBreakTime.GetBoundCopy(); | ||
isBreakTime.ValueChanged += e => | ||
{ | ||
if (e.NewValue) | ||
lastActionPressed = null; | ||
}; | ||
} | ||
|
||
private bool checkCorrectAction(OsuAction action) | ||
{ | ||
if (isBreakTime.Value) | ||
return true; | ||
|
||
if (gameplayClock.CurrentTime < firstObjectValidJudgementTime) | ||
if(base.checkCorrectAction(action)) | ||
return true; | ||
|
||
switch (action) | ||
{ | ||
case OsuAction.LeftButton: | ||
case OsuAction.RightButton: | ||
break; | ||
|
||
// Any action which is not left or right button should be ignored. | ||
default: | ||
return true; | ||
} | ||
|
||
if (lastActionPressed != action) | ||
{ | ||
// User alternated correctly. | ||
|
@@ -84,23 +31,5 @@ private bool checkCorrectAction(OsuAction action) | |
ruleset.Cursor.FlashColour(Colour4.Red, flash_duration, Easing.OutQuint); | ||
return false; | ||
} | ||
|
||
private class InputInterceptor : Component, IKeyBindingHandler<OsuAction> | ||
{ | ||
private readonly OsuModAlternate mod; | ||
|
||
public InputInterceptor(OsuModAlternate mod) | ||
{ | ||
this.mod = mod; | ||
} | ||
|
||
public bool OnPressed(KeyBindingPressEvent<OsuAction> e) | ||
// if the pressed action is incorrect, block it from reaching gameplay. | ||
=> !mod.checkCorrectAction(e.Action); | ||
|
||
public void OnReleased(KeyBindingReleaseEvent<OsuAction> e) | ||
{ | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just use
.FirstOrDefault()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to add that there's not really any reason to alter existing modern code if it doesn't affect anything, to avoid actually making it worse.