lua - implement tastudio.getselection(), tastudio.insertframes(), tastudio.deleteframes()

This commit is contained in:
adelikat 2017-04-22 20:50:03 -05:00
parent 865b04d234
commit 1184e8ed05
4 changed files with 107 additions and 14 deletions

View File

@ -114,6 +114,7 @@ namespace BizHawk.Client.Common
ChangeLog.EndBatch(); ChangeLog.EndBatch();
} }
// TODO: consider making this IEnumerable<int> instead of forcing the collection to be an array
public void RemoveFrames(int[] frames) public void RemoveFrames(int[] frames)
{ {
if (frames.Any()) if (frames.Any())

View File

@ -297,5 +297,64 @@ namespace BizHawk.Client.EmuHawk
}; };
} }
} }
[LuaMethodAttributes(
"getselection",
"gets the currently selected frames"
)]
public LuaTable GetSelection()
{
LuaTable table = Lua.NewTable();
if (Engaged())
{
var selection = Tastudio.GetSelection();
foreach (var row in selection)
{
table[row] = row;
}
}
return table;
}
[LuaMethodAttributes(
"insertframes",
"inserts the given number of blank frames at the given insertion frame"
)]
public void InsertNumFrames(int insertionFrame, int numberOfFrames)
{
if (Engaged())
{
if (insertionFrame < Tastudio.CurrentTasMovie.InputLogLength)
{
Tastudio.InsertNumFrames(insertionFrame, numberOfFrames);
}
else
{
Log(insertionFrame.ToString() + " is out of range");
}
}
}
[LuaMethodAttributes(
"deleteframes",
"deletes the given number of blank frames beginning at the given frame"
)]
public void DeleteFrames(int beginningFrame, int numberOfFrames)
{
if (Engaged())
{
if (beginningFrame < Tastudio.CurrentTasMovie.InputLogLength)
{
Tastudio.DeleteFrames(beginningFrame, numberOfFrames);
}
else
{
Log(beginningFrame.ToString() + " is out of range");
}
}
}
} }
} }

View File

@ -561,7 +561,6 @@ namespace BizHawk.Client.EmuHawk
{ {
if (TasView.AnyRowsSelected) if (TasView.AnyRowsSelected)
{ {
var wasPaused = Mainform.EmulatorPaused;
var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame;
var rollBackFrame = TasView.FirstSelectedIndex.Value; var rollBackFrame = TasView.FirstSelectedIndex.Value;
if (rollBackFrame >= CurrentTasMovie.InputLogLength) if (rollBackFrame >= CurrentTasMovie.InputLogLength)
@ -633,25 +632,13 @@ namespace BizHawk.Client.EmuHawk
private void InsertNumFramesMenuItem_Click(object sender, EventArgs e) private void InsertNumFramesMenuItem_Click(object sender, EventArgs e)
{ {
bool wasPaused = Mainform.EmulatorPaused;
int insertionFrame = TasView.AnyRowsSelected ? TasView.FirstSelectedIndex.Value : 0; int insertionFrame = TasView.AnyRowsSelected ? TasView.FirstSelectedIndex.Value : 0;
bool needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame;
FramesPrompt framesPrompt = new FramesPrompt(); FramesPrompt framesPrompt = new FramesPrompt();
DialogResult result = framesPrompt.ShowDialog(); DialogResult result = framesPrompt.ShowDialog();
if (result == DialogResult.OK) if (result == DialogResult.OK)
{ {
CurrentTasMovie.InsertEmptyFrame(insertionFrame, framesPrompt.Frames); InsertNumFrames(insertionFrame, framesPrompt.Frames);
}
if (needsToRollback)
{
GoToLastEmulatedFrameIfNecessary(insertionFrame);
DoAutoRestore();
}
else
{
RefreshDialog();
} }
} }

View File

@ -716,6 +716,11 @@ namespace BizHawk.Client.EmuHawk
} }
} }
public IEnumerable<int> GetSelection()
{
return TasView.SelectedRows;
}
public void RefreshDialog(bool refreshTasView = true) public void RefreshDialog(bool refreshTasView = true)
{ {
if (_exiting) if (_exiting)
@ -886,6 +891,47 @@ namespace BizHawk.Client.EmuHawk
} }
} }
public void InsertNumFrames(int insertionFrame, int numberOfFrames)
{
if (insertionFrame < CurrentTasMovie.InputLogLength)
{
bool needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame;
CurrentTasMovie.InsertEmptyFrame(insertionFrame, numberOfFrames);
if (needsToRollback)
{
GoToLastEmulatedFrameIfNecessary(insertionFrame);
DoAutoRestore();
}
else
{
RefreshDialog();
}
}
}
public void DeleteFrames(int beginningFrame, int numberofFrames)
{
if (beginningFrame < CurrentTasMovie.InputLogLength)
{
int[] framesToRemove = Enumerable.Range(beginningFrame, numberofFrames).ToArray();
CurrentTasMovie.RemoveFrames(framesToRemove);
SetSplicer();
var needsToRollback = beginningFrame < Emulator.Frame;
if (needsToRollback)
{
GoToLastEmulatedFrameIfNecessary(beginningFrame);
DoAutoRestore();
}
else
{
RefreshDialog();
}
}
}
#region Dialog Events #region Dialog Events
private void Tastudio_Closing(object sender, FormClosingEventArgs e) private void Tastudio_Closing(object sender, FormClosingEventArgs e)