Skip to content

Commit

Permalink
Abort song load on failed validation (#592)
Browse files Browse the repository at this point in the history
+ Updates YARG.Core
  • Loading branch information
sonicfind authored Nov 9, 2023
1 parent f05da1a commit 1fa12cc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
39 changes: 31 additions & 8 deletions Assets/Script/Gameplay/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ public partial class GameManager : MonoBehaviour

public bool IsSongStarted { get; private set; } = false;

private bool _loadFailure;
private enum LoadFailureState
{
None,
Rescan,
Error
}

private LoadFailureState _loadState;
private string _loadFailureMessage;

// All access to chart data must be done through this event,
Expand Down Expand Up @@ -201,7 +208,14 @@ private async UniTaskVoid Start()
LoadingManager.Instance.Queue(LoadAudio, "Loading audio...");
await LoadingManager.Instance.StartLoad();

if (_loadFailure)
if (_loadState == LoadFailureState.Rescan)
{
ToastManager.ToastWarning("Chart requires a rescan!");
GlobalVariables.Instance.LoadScene(SceneIndex.Menu);
return;
}

if (_loadState == LoadFailureState.Error)
{
Debug.LogError(_loadFailureMessage);
ToastManager.ToastError(_loadFailureMessage);
Expand Down Expand Up @@ -370,17 +384,18 @@ private async UniTask LoadReplay()
}
catch (Exception ex)
{
_loadFailure = true;
_loadState = LoadFailureState.Error;
_loadFailureMessage = "Failed to load replay!";
Debug.LogException(ex, this);
return;
}

Song = GlobalVariables.Instance.SongContainer.SongsByHash[
GlobalVariables.Instance.CurrentReplay.SongChecksum][0];

if (Song is null || result != ReplayReadResult.Valid)
{
_loadFailure = true;
_loadState = LoadFailureState.Error;
_loadFailureMessage = "Failed to load replay!";
return;
}
Expand Down Expand Up @@ -411,12 +426,18 @@ await UniTask.RunOnThreadPool(() =>
}
catch (Exception ex)
{
_loadFailure = true;
_loadState = LoadFailureState.Error;
_loadFailureMessage = "Failed to load chart!";
Debug.LogException(ex, this);
return;
}
if (Chart is null)
{
_loadState = LoadFailureState.Rescan;
return;
}
// Ensure sync track is present
var syncTrack = Chart.SyncTrack;
if (syncTrack.Beatlines is null or { Count: < 1 })
Expand All @@ -433,7 +454,8 @@ await UniTask.RunOnThreadPool(() =>
}
});

if (_loadFailure) return;
if (_loadState != LoadFailureState.None)
return;

_chartLoaded?.Invoke(Chart);
}
Expand All @@ -453,13 +475,14 @@ await UniTask.RunOnThreadPool(() =>
}
catch (Exception ex)
{
_loadFailure = true;
_loadState = LoadFailureState.Error;
_loadFailureMessage = "Failed to load audio!";
Debug.LogException(ex, this);
}
});

if (_loadFailure) return;
if (_loadState != LoadFailureState.None)
return;

_songLoaded?.Invoke();
}
Expand Down

0 comments on commit 1fa12cc

Please sign in to comment.