From 1184e8ed05fd4ffd6dcbd3e7bd26b04ca04e3d5e Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 22 Apr 2017 20:50:03 -0500 Subject: [PATCH] lua - implement tastudio.getselection(), tastudio.insertframes(), tastudio.deleteframes() --- .../movie/tasproj/TasMovie.Editing.cs | 1 + .../Lua/Libraries/EmuLuaLibrary.Tastudio.cs | 59 +++++++++++++++++++ .../tools/TAStudio/TAStudio.MenuItems.cs | 15 +---- .../tools/TAStudio/TAStudio.cs | 46 +++++++++++++++ 4 files changed, 107 insertions(+), 14 deletions(-) diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs index 4c81a43ca1..21f2cc62a6 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs @@ -114,6 +114,7 @@ namespace BizHawk.Client.Common ChangeLog.EndBatch(); } + // TODO: consider making this IEnumerable instead of forcing the collection to be an array public void RemoveFrames(int[] frames) { if (frames.Any()) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Tastudio.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Tastudio.cs index 94578e1b32..d4be02d7b2 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Tastudio.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Tastudio.cs @@ -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"); + } + } + } } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs index edbf5f910c..c86792400b 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs @@ -561,7 +561,6 @@ namespace BizHawk.Client.EmuHawk { if (TasView.AnyRowsSelected) { - var wasPaused = Mainform.EmulatorPaused; var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; var rollBackFrame = TasView.FirstSelectedIndex.Value; if (rollBackFrame >= CurrentTasMovie.InputLogLength) @@ -633,25 +632,13 @@ namespace BizHawk.Client.EmuHawk private void InsertNumFramesMenuItem_Click(object sender, EventArgs e) { - bool wasPaused = Mainform.EmulatorPaused; int insertionFrame = TasView.AnyRowsSelected ? TasView.FirstSelectedIndex.Value : 0; - bool needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; FramesPrompt framesPrompt = new FramesPrompt(); DialogResult result = framesPrompt.ShowDialog(); if (result == DialogResult.OK) { - CurrentTasMovie.InsertEmptyFrame(insertionFrame, framesPrompt.Frames); - } - - if (needsToRollback) - { - GoToLastEmulatedFrameIfNecessary(insertionFrame); - DoAutoRestore(); - } - else - { - RefreshDialog(); + InsertNumFrames(insertionFrame, framesPrompt.Frames); } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index b019936ee7..586e66514d 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -716,6 +716,11 @@ namespace BizHawk.Client.EmuHawk } } + public IEnumerable GetSelection() + { + return TasView.SelectedRows; + } + public void RefreshDialog(bool refreshTasView = true) { 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 private void Tastudio_Closing(object sender, FormClosingEventArgs e)