Minor refactors to `MovieSession.HandlePlaybackEnd`

This commit is contained in:
YoshiRulz 2024-06-24 00:29:18 +10:00
parent 8935a3a676
commit 478d375fe5
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 12 additions and 12 deletions

View File

@ -342,25 +342,25 @@ namespace BizHawk.Client.Common
private void HandlePlaybackEnd()
{
#if false // invariants given by single call-site
Debug.Assert(Movie.IsPlaying());
Debug.Assert(Movie.Emulator.Frame >= Movie.InputLogLength);
#endif
if (Movie.IsAtEnd() && Movie.Emulator.HasCycleTiming())
{
var coreValue = Movie.Emulator.AsCycleTiming().CycleCount;
var movieHasValue = Movie.HeaderEntries.TryGetValue(HeaderKeys.CycleCount, out var movieValueStr);
var movieValue = movieHasValue ? Convert.ToInt64(movieValueStr) : 0;
var valuesMatch = movieValue == coreValue;
if (!movieHasValue || !valuesMatch)
if (!Movie.HeaderEntries.TryGetValue(HeaderKeys.CycleCount, out var movieValueStr)
|| !long.TryParse(movieValueStr, out var movieValue))
{
//TODO ideally this would just save indiscriminately, maybe skip if read-only, but I don't think we should be bothering the user in this case --yoshi
PopupMessage("The cycle count (running time) hasn't been saved into this movie yet.\nEnsure you've paused at the end, then save the movie again to add the cycle count.");
}
else if (coreValue != movieValue)
{
var previousState = !movieHasValue
? $"The movie is currently missing a cycle count."
: $"The cycle count in the movie ({movieValue}) doesn't match the current value.";
// TODO: Ideally, this would be a Yes/No MessageBox that saves when "Yes" is pressed.
PopupMessage($"The end of the movie has been reached.\n\n{previousState}\n\nSave the movie to update to the current cycle count ({coreValue}).");
PopupMessage($"The cycle count (running time) saved into this movie ({movieValue}) doesn't match the measured count ({coreValue}) here at the end.\nEnsure you've paused at the end, then save the movie again to update the cycle count.");
}
}
// TODO: mainform callback to update on mode change
switch (Settings.MovieEndAction)
{
case MovieEndAction.Stop: