tastudio: save/load TasSession variables in .tasproj.

right now only includes current frame and branch. current scroll is not needed as we GoToFrame anyway, current selection seems pointless.
This commit is contained in:
feos 2015-10-25 17:52:32 +03:00
parent 4fe51a1364
commit 19add0ec93
7 changed files with 85 additions and 14 deletions

View File

@ -47,9 +47,10 @@ namespace BizHawk.Client.Common
public static BinaryStateLump ClientSettings { get; private set; }
[Name("VerificationLog", "txt")]
public static BinaryStateLump VerificationLog { get; private set; }
[Name("UserData", "txt")]
public static BinaryStateLump UserData { get; private set; }
[Name("Session", "txt")]
public static BinaryStateLump Session { get; private set; }
// branchstuff
[Name("Branches\\CoreData", "bin")]

View File

@ -209,6 +209,7 @@
</Compile>
<Compile Include="movie\tasproj\TasMovie.cs" />
<Compile Include="movie\tasproj\TasMovieMarker.cs" />
<Compile Include="movie\tasproj\TasSession.cs" />
<Compile Include="movie\tasproj\TasStateManager.cs" />
<Compile Include="movie\tasproj\TasMovieRecord.cs" />
<Compile Include="movie\tasproj\TasStateManagerSettings.cs" />

View File

@ -105,6 +105,8 @@ namespace BizHawk.Client.Common
}
}
ReportProgress(PROGRESS_STEP);
bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(Session.ToString()));
}
Changes = false;
@ -298,6 +300,11 @@ namespace BizHawk.Client.Common
StateManager.LoadBranchStates(br);
});
}
bl.GetLump(BinaryStateLump.Session, false, delegate(TextReader tr)
{
Session.PopulateFromString(tr.ReadToEnd());
});
}
Changes = false;

View File

@ -18,10 +18,10 @@ namespace BizHawk.Client.Common
private readonly Bk2MnemonicConstants Mnemonics = new Bk2MnemonicConstants();
private readonly TasStateManager StateManager;
public readonly TasSession Session;
private readonly TasLagLog LagLog = new TasLagLog();
private readonly Dictionary<int, IController> InputStateCache = new Dictionary<int, IController>();
public readonly List<string> VerificationLog = new List<string>(); // For movies that do not begin with power-on, this is the input required to get into the initial state
public readonly TasBranchCollection Branches = new TasBranchCollection();
private BackgroundWorker _progressReportWorker = null;
@ -48,12 +48,14 @@ namespace BizHawk.Client.Common
ChangeLog = new TasMovieChangeLog(this);
StateManager = new TasStateManager(this);
Session = new TasSession(this);
Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0 Tasproj v1.0";
Markers = new TasMovieMarkerList(this);
Markers.CollectionChanged += Markers_CollectionChanged;
Markers.Add(0, startsFromSavestate ? "Savestate" : "Power on");
BindMarkersToInput = true;
CurrentBranch = -1;
}
public TasMovie(bool startsFromSavestate = false, BackgroundWorker progressReportWorker = null)
@ -68,12 +70,14 @@ namespace BizHawk.Client.Common
ChangeLog = new TasMovieChangeLog(this);
StateManager = new TasStateManager(this);
Session = new TasSession(this);
Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0 Tasproj v1.0";
Markers = new TasMovieMarkerList(this);
Markers.CollectionChanged += Markers_CollectionChanged;
Markers.Add(0, startsFromSavestate ? "Savestate" : "Power on");
BindMarkersToInput = true;
CurrentBranch = -1;
}
public TasLagLog TasLagLog { get { return LagLog; } }
@ -81,6 +85,7 @@ namespace BizHawk.Client.Common
public TasMovieMarkerList Markers { get; set; }
public bool BindMarkersToInput { get; set; }
public bool UseInputCache { get; set; }
public int CurrentBranch { get; set; }
public int BranchCount { get { return Branches.Count; } }
public TasBranch GetBranch(int index)
{

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Client.Common
{
public class TasSession
{
private TasMovie _movie;
public int CurrentFrame { get; set; }
public int CurrentBranch { get; set; }
public TasSession(TasMovie movie)
{
_movie = movie;
CurrentFrame = 0;
CurrentBranch = -1;
}
public void UpdateValues()
{
CurrentFrame = Global.Emulator.Frame;
CurrentBranch = _movie.CurrentBranch;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
UpdateValues();
sb.AppendLine(CurrentFrame.ToString());
sb.AppendLine(CurrentBranch.ToString());
return sb.ToString();
}
public void PopulateFromString(string session)
{
if (!string.IsNullOrWhiteSpace(session))
{
string[] lines = session.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
if (lines.Length > 0)
CurrentFrame = int.Parse(lines[0]);
else
CurrentFrame = 0;
if (lines.Length > 1)
CurrentBranch = int.Parse(lines[1]);
else
CurrentBranch = -1;
}
}
}
}

View File

@ -71,8 +71,6 @@ namespace BizHawk.Client.EmuHawk
}
}
private int CurrentBranch = -1;
private void QueryItemText(int index, InputRoll.RollColumn column, out string text, ref int offsetX, ref int offsetY)
{
text = string.Empty;
@ -102,7 +100,7 @@ namespace BizHawk.Client.EmuHawk
if (branch != null)
{
var record = Tastudio.CurrentTasMovie[branch.Frame];
if (index == CurrentBranch)
if (index == Movie.CurrentBranch)
color = TAStudio.CurrentFrame_InputLog; // SystemColors.HotTrack;
else if (record.Lagged.HasValue)
{
@ -147,9 +145,9 @@ namespace BizHawk.Client.EmuHawk
if (SelectedBranch != null)
{
int index = BranchView.SelectedRows.First();
//if (CurrentBranch == index) // if the current branch was edited, we should allow loading it. some day there might be a proper check
//if (Movie.CurrentBranchCurrentBranch == index) // if the current branch was edited, we should allow loading it. some day there might be a proper check
// return;
CurrentBranch = index;
Movie.CurrentBranch = index;
LoadBranch(SelectedBranch);
BranchView.Refresh();
}
@ -168,13 +166,13 @@ namespace BizHawk.Client.EmuHawk
if (SelectedBranch != null)
{
int index = BranchView.SelectedRows.First();
if (index == CurrentBranch)
if (index == Movie.CurrentBranch)
{
CurrentBranch = -1;
Movie.CurrentBranch = -1;
}
else if (index < CurrentBranch)
else if (index < Movie.CurrentBranch)
{
CurrentBranch--;
Movie.CurrentBranch--;
}
Movie.RemoveBranch(SelectedBranch);
@ -220,7 +218,7 @@ namespace BizHawk.Client.EmuHawk
TasBranch branch = CreateBranch();
Movie.AddBranch(branch);
BranchView.RowCount = Movie.BranchCount;
CurrentBranch = Movie.BranchCount - 1;
Movie.CurrentBranch = Movie.BranchCount - 1;
BranchView.Refresh();
Tastudio.RefreshDialog();
}
@ -302,7 +300,7 @@ namespace BizHawk.Client.EmuHawk
if (SelectedBranch != null)
{
UpdateBranch(SelectedBranch);
CurrentBranch = BranchView.SelectedRows.First();
Movie.CurrentBranch = BranchView.SelectedRows.First();
}
}

View File

@ -237,6 +237,9 @@ namespace BizHawk.Client.EmuHawk
BranchesMarkersSplit.SplitterDistance = Settings.BranchMarkerSplitDistance;
}
GoToFrame(CurrentTasMovie.Session.CurrentFrame);
CurrentTasMovie.CurrentBranch = CurrentTasMovie.Session.CurrentBranch;
////////////////
RefreshDialog();