Skip to content

Commit

Permalink
FIve-fret Anti-ghosting (#160)
Browse files Browse the repository at this point in the history
* WIP anti-ghosting (pending hopo chords)

* WIP anti-ghosting (pending hopo chords)

* make anti-ghosting take taps into account

* Take chord hopos/taps into account

* ^

* Make anti-ghosting togglable
  • Loading branch information
raphaelgoulart authored Apr 21, 2023
1 parent 084647e commit 3bcfe3d
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 8 deletions.
1 change: 1 addition & 0 deletions Assets/Script/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public static class Constants {
public const bool ANCHORING = true;
public const bool INFINITE_FRONTEND = false;
public const bool ANCHOR_CHORD_HOPO = true;
public const int EXTRA_ALLOWED_GHOSTS = 0;
}
}
88 changes: 81 additions & 7 deletions Assets/Script/PlayMode/FiveFretTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using YARG.Data;
using YARG.Input;
using YARG.Pools;
using YARG.Settings;
using YARG.Util;

namespace YARG.PlayMode {
Expand All @@ -29,6 +30,10 @@ public class FiveFretTrack : AbstractTrack {
private float? latestInput = null;
private bool latestInputIsStrum = false;
private bool[] extendedSustain = new bool[] { false, false, false, false, false };
private int allowedGhostsDefault = Constants.EXTRA_ALLOWED_GHOSTS + 1;
private int allowedGhosts = Constants.EXTRA_ALLOWED_GHOSTS + 1;
private int[] allowedChordGhosts = new int[] { -1, -1, -1, -1, -1 }; // -1 = not a chord; 0 = ghosted; 1 = ghost allowed
private bool antiGhosting = false;

private int notesHit = 0;
// private int notesMissed = 0;
Expand All @@ -37,6 +42,9 @@ protected override void StartTrack() {
notePool.player = player;
genericPool.player = player;

// Engine tweak
antiGhosting = SettingsManager.GetSettingValue<bool>("antiGhosting");

// Lefty flip

if (player.leftyFlip) {
Expand Down Expand Up @@ -195,7 +203,8 @@ private void UpdateInput() {
// Handle misses (multiple a frame in case of lag)
while (Play.Instance.SongTime - expectedHits.PeekOrNull()?[0].time > Constants.HIT_MARGIN) {
var missedChord = expectedHits.Dequeue();

allowedGhosts = allowedGhostsDefault;
ResetAllowedChordGhosts();
// Call miss for each component
Combo = 0;
foreach (var hit in missedChord) {
Expand Down Expand Up @@ -223,7 +232,7 @@ private void UpdateInput() {

// If the note is a HOPO, the player has not strummed, and the HOPO can't be hit, nothing happens.
if ((chord[0].hopo || chord[0].tap) && !strummed && strumLeniency == 0f) {
if (Combo <= 0 && chord[0].hopo) {
if ((Combo <= 0 && chord[0].hopo) || allowedGhosts <= 0) {
return;
}

Expand Down Expand Up @@ -296,6 +305,8 @@ private void UpdateInput() {
// If correct chord is pressed, and is not a multi-hit, hit it!
expectedHits.Dequeue();

allowedGhosts = allowedGhostsDefault;
ResetAllowedChordGhosts();
Combo++;
strummedCurrentNote = strummedCurrentNote || strummed || strumLeniency > 0f;
strumLeniency = 0f;
Expand All @@ -322,7 +333,7 @@ private void UpdateInput() {
// Check if it's extended sustain;
var nextNote = GetNextNote(hit.time);
if (nextNote != null) {
extendedSustain[hit.fret] = hit.EndTime > nextNote.time;
extendedSustain[hit.fret] = hit.EndTime > nextNote[0].time;
}
} else if (hit.fret != 5) {
extendedSustain[hit.fret] = false;
Expand Down Expand Up @@ -466,7 +477,7 @@ private bool ChordPressed(List<NoteInfo> chordList, bool overstrumCheck = false)
return false;
} else if (!contains && frets[i].IsPressed) {
if (Constants.ANCHORING && Constants.ANCHOR_CHORD_HOPO &&
chordList[0].hopo && !(strummed || strumLeniency > 0f || overstrumCheck) &&
(chordList[0].hopo || chordList[0].tap) && !(strummed || strumLeniency > 0f || overstrumCheck) &&
i < chordList[0].fret) {

// Allow anchoring chord HO/POs
Expand All @@ -485,6 +496,37 @@ private void FretChangedAction(bool pressed, int fret) {
latestInput = Play.Instance.SongTime;
latestInputIsStrum = false;

// Should it check ghosting?
if (antiGhosting && allowedGhosts > 0 && pressed && hitChartIndex > 0) {
bool checkGhosting = true;
for (var i = 0; i < 5; i++) {
if (i == fret) {
continue;
}
if (frets[i].IsPressed) {
if (fret < i) { // Don't check ghosting if pressed fret is below currently held fret
checkGhosting = false;
break;
}
}
}
if (checkGhosting) {
var nextNote = GetNextNote(Chart[hitChartIndex-1].time);
if (nextNote != null && (nextNote[0].hopo || nextNote[0].tap)) {
if (nextNote.Count == 1 && fret != nextNote[0].fret) { // Hitting wrong button = ghosted = bad
allowedGhosts--;
}
if (nextNote.Count > 1) { // If chord...
if (allowedChordGhosts[fret] == 1) { // Fret is part of chord, and hasn't been ghosted yet
allowedChordGhosts[fret] = 0;
} else { // Actual ghost input
allowedGhosts--;
}
}
}
}
}

frets[fret].SetPressed(pressed);

if (pressed) {
Expand Down Expand Up @@ -616,15 +658,47 @@ private bool ChordsOverlap(List<NoteInfo> chordList1, List<NoteInfo> chordList2)
return false;
}

private NoteInfo GetNextNote(float currentChordTime) {
private List<NoteInfo> GetNextNote(float currentChordTime) {
var i = hitChartIndex;
List<NoteInfo> chord = new();
while (Chart.Count > i) {
if (Chart[i].time > currentChordTime) {
return Chart[i];
var nextChordTime = Chart[i].time;
chord.Add(Chart[i]);
i++;
while (Chart.Count > i) {
if (Chart[i].time > nextChordTime) {
break;
} else {
chord.Add(Chart[i]);
i++;
}
}
break;
}
i++;
}
return null;
if (chord.Count == 0) {
return null;
} else {
// If it's a chord, set allowed ghosts accordingly
if (chord.Count > 1) {
foreach (NoteInfo hit in chord) {
if (allowedChordGhosts[hit.fret] == -1) {
allowedChordGhosts[hit.fret] = 1;
}
}
} else {
ResetAllowedChordGhosts();
}
return chord;
}
}

private void ResetAllowedChordGhosts() {
for (var i = 0; i < 5; i++) {
allowedChordGhosts[i] = -1;
}
}

private bool IsExtendedSustain() {
Expand Down
7 changes: 6 additions & 1 deletion Assets/Script/Settings/SettingsManager.Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,15 @@ public void UseChipmunkSpeedChange() {
GameManager.AudioManager.IsChipmunkSpeedup = useChipmunkSpeed;
}

[SettingSpace]
[SettingShowInGame]
[SettingLocation("general", 29)]
[SettingType("Toggle")]
public bool antiGhosting = true;

[SettingSpace]
[SettingShowInGame]
[SettingLocation("general", 30)]
[SettingType("Toggle")]
public bool amIAwesome = false;
}
}
Expand Down
4 changes: 4 additions & 0 deletions Assets/Settings/Localization/Settings Shared Data.asset
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ MonoBehaviour:
m_Key: amIAwesome
m_Metadata:
m_Items: []
- m_Id: 7304579734953985
m_Key: antiGhosting
m_Metadata:
m_Items: []
- m_Id: 7405541279522816
m_Key: copyCurrentSongTextFilePath
m_Metadata:
Expand Down
4 changes: 4 additions & 0 deletions Assets/Settings/Localization/Settings_en-US.asset
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ MonoBehaviour:
m_Localized: Awesomeness Detection
m_Metadata:
m_Items: []
- m_Id: 7304579734953985
m_Localized: Anti-Ghosting
m_Metadata:
m_Items: []
- m_Id: 7405541279522816
m_Localized: Copy "Current Song" Text File Path
m_Metadata:
Expand Down

0 comments on commit 3bcfe3d

Please sign in to comment.