Skip to content

Commit

Permalink
Add strum leniency to five fret guitar (YARC-Official#83)
Browse files Browse the repository at this point in the history
* Ignore .idea folder

* Strum leniency added to FiveFretTrack

* Adjusted strum leniency to 65ms
  • Loading branch information
RileyTheFox authored Apr 13, 2023
1 parent 18fbd34 commit c5affd6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
44 changes: 29 additions & 15 deletions Assets/Script/PlayMode/FiveFretTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
namespace YARG.PlayMode {
public class FiveFretTrack : AbstractTrack {
private bool strummed = false;
private float strumLeniency;

private FiveFretInputStrategy input;

[Space]
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
Expand All @@ -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();

Expand Down Expand Up @@ -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;
}
Expand All @@ -250,6 +260,7 @@ private void UpdateInput() {
expectedHits.Dequeue();

Combo++;
strumLeniency = 0f;
foreach (var hit in chord) {
hitChartIndex++;
// Hit notes
Expand Down Expand Up @@ -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--) {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions Assets/Script/PlayMode/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit c5affd6

Please sign in to comment.