From e6cec0f52fb4bb6bb7e6ec72ac602f81372d4eee Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 14 Oct 2014 18:09:30 +0000 Subject: [PATCH] Tastudio - Saving and loading of column info to the .tasproj file, loading is still problematic because it is being whacked by code that rebuilds the columns later, need to unspeghettify some things --- BizHawk.Client.Common/BinarySaveStates.cs | 4 ++- .../movie/tasproj/TasMovie.IO.cs | 32 ++++++++++++++++--- .../tools/TAStudio/TAStudio.cs | 29 +++++++++++++++-- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/BizHawk.Client.Common/BinarySaveStates.cs b/BizHawk.Client.Common/BinarySaveStates.cs index b72284579e..85926806d0 100644 --- a/BizHawk.Client.Common/BinarySaveStates.cs +++ b/BizHawk.Client.Common/BinarySaveStates.cs @@ -25,7 +25,8 @@ namespace BizHawk.Client.Common LagLog, Greenzone, GreenzoneSettings, - Markers + Markers, + ClientSettings } public static class BinaryStateFileNames @@ -59,6 +60,7 @@ namespace BizHawk.Client.Common AddLumpName(BinaryStateLump.Greenzone, "GreenZone"); AddLumpName(BinaryStateLump.GreenzoneSettings, "GreenZoneSettings.txt"); AddLumpName(BinaryStateLump.Markers, "Markers.txt"); + AddLumpName(BinaryStateLump.ClientSettings, "ClientSettings.json"); } public static string GetReadName(BinaryStateLump lump) diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs index dc966cfc3c..0d83152424 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs @@ -10,6 +10,9 @@ namespace BizHawk.Client.Common { public partial class TasMovie { + public Func ClientSettingsForSave { get; set; } + public Action GetClientSettingsOnLoad { get; set; } + protected override void Write(string fn) { var file = new FileInfo(fn); @@ -48,6 +51,12 @@ namespace BizHawk.Client.Common bs.PutLump(BinaryStateLump.Corestate, (BinaryWriter bw) => bw.Write(BinarySavestate)); } } + + if (ClientSettingsForSave != null) + { + var clientSettingsJson = ClientSettingsForSave(); + bs.PutLump(BinaryStateLump.ClientSettings, (TextWriter tw) => tw.Write(clientSettingsJson)); + } } Changes = false; @@ -173,6 +182,24 @@ namespace BizHawk.Client.Common } } }); + + if (GetClientSettingsOnLoad != null) + { + string clientSettings = string.Empty; + bl.GetLump(BinaryStateLump.ClientSettings, true, delegate(TextReader tr) + { + string line; + while ((line = tr.ReadLine()) != null) + { + if (!string.IsNullOrWhiteSpace(line)) + { + clientSettings = line; + } + } + }); + + GetClientSettingsOnLoad(clientSettings); + } } Changes = false; @@ -184,10 +211,5 @@ namespace BizHawk.Client.Common LagLog.Clear(); StateManager.Clear(); } - - private void RestoreLagLog(byte[] buffer) - { - - } } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 09df53118c..8335c5c3f3 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -76,6 +76,7 @@ namespace BizHawk.Client.EmuHawk GlobalWin.MainForm.PauseOnFrame = null; GlobalWin.OSD.AddMessage("TAStudio engaged"); _currentTasMovie = Global.MovieSession.Movie as TasMovie; + SetTasMovieCallbacks(); SetTextProperty(); GlobalWin.MainForm.PauseEmulator(); GlobalWin.MainForm.RelinquishControl(this); @@ -99,6 +100,7 @@ namespace BizHawk.Client.EmuHawk { Global.MovieSession.Movie = new TasMovie(); _currentTasMovie = Global.MovieSession.Movie as TasMovie; + SetTasMovieCallbacks(); _currentTasMovie.PropertyChanged += new PropertyChangedEventHandler(this.TasMovie_OnPropertyChanged); _currentTasMovie.Filename = DefaultTasProjName(); // TODO don't do this, take over any mainform actions that can crash without a filename _currentTasMovie.PopulateWithDefaultHeaderValues(); @@ -112,6 +114,12 @@ namespace BizHawk.Client.EmuHawk PathManager.FilesystemSafeName(Global.Game) + "." + TasMovie.Extension); } + private void SetTasMovieCallbacks() + { + _currentTasMovie.ClientSettingsForSave = ClientSettingsForSave; + _currentTasMovie.GetClientSettingsOnLoad = GetClientSettingsOnLoad; + } + private void StartNewTasMovie() { if (AskSaveChanges()) @@ -125,6 +133,17 @@ namespace BizHawk.Client.EmuHawk } } + private string ClientSettingsForSave() + { + return TasView.UserSettingsSerialized(); + } + + private void GetClientSettingsOnLoad(string settingsJson) + { + TasView.LoadSettingsSerialized(settingsJson); + TasView.Refresh(); + } + private void SetTextProperty() { var text = "TAStudio"; @@ -140,9 +159,11 @@ namespace BizHawk.Client.EmuHawk { if (AskSaveChanges()) { - var movie = new TasMovie() + var movie = new TasMovie { - Filename = path + Filename = path, + ClientSettingsForSave = ClientSettingsForSave, + GetClientSettingsOnLoad = GetClientSettingsOnLoad }; movie.PropertyChanged += TasMovie_OnPropertyChanged; @@ -168,8 +189,10 @@ namespace BizHawk.Client.EmuHawk return false; } - WantsToControlStopMovie = true; _currentTasMovie = Global.MovieSession.Movie as TasMovie; + SetTasMovieCallbacks(); + + WantsToControlStopMovie = true; Global.Config.RecentTas.Add(path); Text = "TAStudio - " + _currentTasMovie.Name;