From c5affd6fbfab0508c89d4c9a9aaccc8c2588fef2 Mon Sep 17 00:00:00 2001 From: RileyTheFox Date: Thu, 13 Apr 2023 02:44:36 +0100 Subject: [PATCH] Add strum leniency to five fret guitar (#83) * Ignore .idea folder * Strum leniency added to FiveFretTrack * Adjusted strum leniency to 65ms --- Assets/Script/PlayMode/FiveFretTrack.cs | 44 ++++++++++++++++--------- Assets/Script/PlayMode/Play.cs | 1 + 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Assets/Script/PlayMode/FiveFretTrack.cs b/Assets/Script/PlayMode/FiveFretTrack.cs index 98f352703..e857d4c63 100644 --- a/Assets/Script/PlayMode/FiveFretTrack.cs +++ b/Assets/Script/PlayMode/FiveFretTrack.cs @@ -9,6 +9,8 @@ namespace YARG.PlayMode { public class FiveFretTrack : AbstractTrack { private bool strummed = false; + private float strumLeniency; + private FiveFretInputStrategy input; [Space] @@ -147,6 +149,15 @@ protected override void UpdateTrack() { } private void UpdateInput() { + // Only want to decrease strum leniency on frames where we didn't strum + if (strumLeniency > 0f && !strummed) { + strumLeniency -= Time.deltaTime; + + if (strumLeniency <= 0f) { + UpdateOverstrums(); + } + } + // Handle misses (multiple a frame in case of lag) while (Play.Instance.SongTime - expectedHits.PeekOrNull()?[0].time > Play.HIT_MARGIN) { var missedChord = expectedHits.Dequeue(); @@ -161,20 +172,19 @@ private void UpdateInput() { } if (expectedHits.Count <= 0) { - UpdateOverstrums(); return; } // Handle hits (one per frame so no double hits) var chord = expectedHits.Peek(); - // If the note is not a HOPO and the player did not strum, nothing happened. - if (!chord[0].hopo && !strummed) { + // If the note is not a HOPO and the player has not strummed, nothing happens. + if (!chord[0].hopo && !strummed && strumLeniency == 0f) { return; } - // If the note is a HOPOm the player did not strum, and the HOPO can't be hit, nothing happened. - if (chord[0].hopo && !strummed) { + // If the note is a HOPOm the player has not strummed, and the HOPO can't be hit, nothing happens. + if (chord[0].hopo && !strummed && strumLeniency == 0f) { if (Combo <= 0) { return; } @@ -187,7 +197,7 @@ private void UpdateInput() { // If strumming to recover combo, skip to first valid note within the timing window. // This will make it easier to recover. - if (strummed && !ChordPressed(chord)) { + if ((strummed || strumLeniency > 0f) && !ChordPressed(chord)) { RemoveOldAllowedOverstrums(); var overstrumForgiven = IsOverstrumForgiven(); @@ -223,9 +233,9 @@ private void UpdateInput() { // Check if correct chord is pressed if (!ChordPressed(chord)) { - if (!chord[0].hopo) { - UpdateOverstrums(); - } + // if (!chord[0].hopo && strumLeniency == 0f) { + // UpdateOverstrums(); + // } return; } @@ -250,6 +260,7 @@ private void UpdateInput() { expectedHits.Dequeue(); Combo++; + strumLeniency = 0f; foreach (var hit in chord) { hitChartIndex++; // Hit notes @@ -315,17 +326,13 @@ private bool IsOverstrumForgiven() { private void UpdateOverstrums() { RemoveOldAllowedOverstrums(); - // Don't do anything else if we didn't strum - if (!strummed) { - return; - } - // Look in the allowed overstrums first if (IsOverstrumForgiven()) { return; } - + Combo = 0; + strumLeniency = 0f; // Let go of held notes for (int i = heldNotes.Count - 1; i >= 0; i--) { @@ -436,6 +443,13 @@ private void StrumAction() { latestInputIsStrum = true; strummed = true; + + // Strum leniency already active and another strum inputted, a double strum occurred (must overstrum) + if (strumLeniency > 0f) { + UpdateOverstrums(); + } + + strumLeniency = Play.STRUM_LENIENCY; } private void SpawnNote(NoteInfo noteInfo, float time) { diff --git a/Assets/Script/PlayMode/Play.cs b/Assets/Script/PlayMode/Play.cs index e8e12c326..1a2c2a552 100644 --- a/Assets/Script/PlayMode/Play.cs +++ b/Assets/Script/PlayMode/Play.cs @@ -23,6 +23,7 @@ public static Play Instance { public const float SONG_START_OFFSET = 1f; public const float HIT_MARGIN = 0.095f; + public const float STRUM_LENIENCY = 0.065f; public const bool ANCHORING = true; public const bool INFINITE_FRONTEND = false;