Tastudio/lua - implement tastudio.ongreenzoneinvalidated

This commit is contained in:
adelikat 2015-07-02 14:51:42 -04:00
parent 105b8d3a64
commit 19423092cd
4 changed files with 38 additions and 0 deletions

View File

@ -25,6 +25,16 @@ namespace BizHawk.Client.Common
}
}
public Action<int> InvalidateCallback { get; set; }
private void CallInvalidateCallback(int index)
{
if (InvalidateCallback != null)
{
InvalidateCallback(index);
}
}
private readonly SortedList<int, byte[]> States = new SortedList<int, byte[]>();
private string statePath
{
@ -329,6 +339,8 @@ namespace BizHawk.Client.Common
accessed.Remove(state.Key);
States.Remove(state.Key);
}
CallInvalidateCallback(frame);
}
}

View File

@ -173,5 +173,20 @@ namespace BizHawk.Client.EmuHawk
};
}
}
[LuaMethodAttributes(
"ongreenzoneinvalidated",
"called whenever the greenzone is invalidated and returns the first frame that was invalidated"
)]
public void OnGreenzoneInvalidated(LuaFunction luaf)
{
if (Engaged())
{
Tastudio.GreenzoneInvalidatedCallback = (int index) =>
{
luaf.Call(index);
};
}
}
}
}

View File

@ -121,6 +121,15 @@ namespace BizHawk.Client.EmuHawk
return null;
}
public Action<int> GreenzoneInvalidatedCallback { get; set; }
private void GreenzoneInvalidated(int index)
{
if (GreenzoneInvalidatedCallback != null)
{
GreenzoneInvalidatedCallback(index);
}
}
#endregion
private void TasView_QueryItemBkColor(int index, InputRoll.RollColumn column, ref Color color)

View File

@ -328,6 +328,7 @@ namespace BizHawk.Client.EmuHawk
if (CurrentTasMovie == null)
{
Global.MovieSession.Movie = new TasMovie(false, _saveBackgroundWorker);
(Global.MovieSession.Movie as TasMovie).TasStateManager.InvalidateCallback = GreenzoneInvalidated;
}
CurrentTasMovie.Filename = file.FullName;
@ -357,6 +358,7 @@ namespace BizHawk.Client.EmuHawk
if (AskSaveChanges())
{
Global.MovieSession.Movie = new TasMovie(false, _saveBackgroundWorker);
(Global.MovieSession.Movie as TasMovie).TasStateManager.InvalidateCallback = GreenzoneInvalidated;
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();