Refactor tasmovie input roll settings handling

this allows loading the input roll settings stored in a tasproj even after it was initially `Load()`ed. This fixes those settings not getting applied when loading an existing, playing tasmovie into TAStudio.
This commit is contained in:
Morilli 2024-09-26 18:51:00 +02:00
parent 81b6c2793c
commit 2ad7fc095c
3 changed files with 19 additions and 31 deletions

View File

@ -11,8 +11,8 @@ namespace BizHawk.Client.Common
IMovieChangeLog ChangeLog { get; }
IStateManager TasStateManager { get; }
Func<string> ClientSettingsForSave { get; set; }
Action<string> GetClientSettingsOnLoad { get; set; }
Func<string> InputRollSettingsForSave { get; set; }
string InputRollSettings { get; }
ITasMovieRecord this[int index] { get; }
ITasSession TasSession { get; }
TasMovieMarkerList Markers { get; }

View File

@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using System.Linq;
using BizHawk.Common.StringExtensions;
@ -9,8 +9,8 @@ namespace BizHawk.Client.Common
{
internal partial class TasMovie
{
public Func<string> ClientSettingsForSave { get; set; }
public Action<string> GetClientSettingsOnLoad { get; set; }
public Func<string> InputRollSettingsForSave { get; set; }
public string InputRollSettings { get; private set; }
protected override void AddLumps(ZipStateSaver bs, bool isBackup = false)
{
@ -27,10 +27,10 @@ namespace BizHawk.Client.Common
bs.PutLump(BinaryStateLump.LagLog, tw => LagLog.Save(tw));
bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString()));
if (ClientSettingsForSave != null)
if (InputRollSettingsForSave != null)
{
var clientSettingsJson = ClientSettingsForSave();
bs.PutLump(BinaryStateLump.ClientSettings, (TextWriter tw) => tw.Write(clientSettingsJson));
var inputRollSettingsJson = InputRollSettingsForSave();
bs.PutLump(BinaryStateLump.ClientSettings, (TextWriter tw) => tw.Write(inputRollSettingsJson));
}
if (VerificationLog.Any())
@ -99,16 +99,13 @@ namespace BizHawk.Client.Common
}
});
if (GetClientSettingsOnLoad != null)
bl.GetLump(BinaryStateLump.ClientSettings, abort: false, tr =>
{
bl.GetLump(BinaryStateLump.ClientSettings, abort: false, tr =>
{
string clientSettings = tr.ReadToEnd();
string inputRollSettings = tr.ReadToEnd();
if (!string.IsNullOrEmpty(clientSettings))
GetClientSettingsOnLoad(clientSettings);
});
}
if (!string.IsNullOrEmpty(inputRollSettings))
InputRollSettings = inputRollSettings;
});
bl.GetLump(BinaryStateLump.VerificationLog, abort: false, tr =>
{

View File

@ -331,12 +331,6 @@ namespace BizHawk.Client.EmuHawk
}
}
private void SetTasMovieCallbacks(ITasMovie movie)
{
movie.ClientSettingsForSave = () => TasView.UserSettingsSerialized();
movie.GetClientSettingsOnLoad = json => TasView.LoadSettingsSerialized(json);
}
private static readonly string[] N64CButtonSuffixes = { " C Up", " C Down", " C Left", " C Right" };
private void SetUpColumns()
@ -574,7 +568,7 @@ namespace BizHawk.Client.EmuHawk
{
_initializing = true;
SetTasMovieCallbacks(movie);
movie.InputRollSettingsForSave = () => TasView.UserSettingsSerialized();
movie.BindMarkersToInput = Settings.BindMarkersToInput;
movie.GreenzoneInvalidated = GreenzoneInvalidated;
movie.PropertyChanged += TasMovie_OnPropertyChanged;
@ -590,6 +584,10 @@ namespace BizHawk.Client.EmuHawk
MarkerControl.UpdateTextColumnWidth();
TastudioPlayMode();
UpdateWindowTitle();
if (CurrentTasMovie.InputRollSettings != null)
{
TasView.LoadSettingsSerialized(CurrentTasMovie.InputRollSettings);
}
}
_initializing = false;
@ -615,14 +613,7 @@ namespace BizHawk.Client.EmuHawk
}
else
{
var movie = MovieSession.Get(path, loadMovie: false);
// we can't load the movie yet, we need to set the callbacks first...
if (movie is ITasMovie pendingTasMovie)
{
SetTasMovieCallbacks(pendingTasMovie);
}
movie.Load();
var movie = MovieSession.Get(path, loadMovie: true);
var tasMovie = movie as ITasMovie ?? movie.ToTasMovie();
movieLoadSucceeded = LoadMovie(tasMovie);
}