From ed3ff8a4f90a4e5ae96f3aa1ae1b670602faf582 Mon Sep 17 00:00:00 2001 From: c7fab <26490633+c7fab@users.noreply.github.com> Date: Sat, 8 Feb 2025 22:00:11 +0100 Subject: [PATCH 1/8] Branch Load Undone Lua Callback Implements a proper callback for undoing branch loading. No branch index as parameter is required as the index of the backup branch is always -1. --- .../tools/Lua/Libraries/TAStudioLuaLibrary.cs | 13 +++++++++++++ .../tools/TAStudio/BookmarksBranchesBox.cs | 4 +++- .../tools/TAStudio/TAStudio.Callbacks.cs | 6 ++++++ .../tools/TAStudio/TAStudio.cs | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs index f2bb6d35f27..fe8e15ea772 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs @@ -592,5 +592,18 @@ public void OnBranchRemove(LuaFunction luaf) }; } } + + [LuaMethodExample("function LoadUndone()\r\nconsole.log(\"You did a branch load undo\")\r\nend\r\ntastudio.onbranchundoload(LoadUndone)")] + [LuaMethod("onbranchundoload", "called whenever a branch load is undone. luaf must be a function without parameters")] + public void OnBranchUndoLoad(LuaFunction luaf) + { + if (Engaged()) + { + Tastudio.BranchLoadUndoneCallback = () => + { + luaf.Call(); + }; + } + } } } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index c36c37904c9..7f0ab5e45eb 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -37,6 +37,8 @@ private enum BranchUndo public Action RemovedCallback { get; set; } + public Action LoadUndoneCallback { get; set; } + public TAStudio Tastudio { get; set; } public IDialogController DialogController => Tastudio.MainForm; @@ -358,7 +360,7 @@ private void UndoBranchToolStripMenuItem_Click(object sender, EventArgs e) if (_branchUndo == BranchUndo.Load) { LoadBranch(_backupBranch); - LoadedCallback?.Invoke(Branches.IndexOf(_backupBranch)); + LoadUndoneCallback?.Invoke(); Tastudio.MainForm.AddOnScreenMessage("Branch Load canceled"); } else if (_branchUndo == BranchUndo.Update) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs index 637837fbac7..01e7983e131 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs @@ -13,6 +13,7 @@ public partial class TAStudio public Action BranchLoadedCallback { get; set; } public Action BranchSavedCallback { get; set; } public Action BranchRemovedCallback { get; set; } + public Action BranchLoadUndoneCallback { get; set; } private void GreenzoneInvalidated(int index) { @@ -33,5 +34,10 @@ private void BranchRemoved(int index) { BranchRemovedCallback?.Invoke(index); } + + private void BranchLoadUndone() + { + BranchLoadUndoneCallback?.Invoke(); + } } } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index ac7988b824d..b85497cde1f 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -148,6 +148,7 @@ public TAStudio() BookMarkControl.LoadedCallback = BranchLoaded; BookMarkControl.SavedCallback = BranchSaved; BookMarkControl.RemovedCallback = BranchRemoved; + BookMarkControl.LoadUndoneCallback = BranchLoadUndone; TasView.MouseLeave += TAStudio_MouseLeave; TasView.CellHovered += (_, e) => { From b26edfa2ff456233d2b5eabb413a4a4105e6fa70 Mon Sep 17 00:00:00 2001 From: c7fab <26490633+c7fab@users.noreply.github.com> Date: Sun, 9 Feb 2025 02:57:37 +0100 Subject: [PATCH 2/8] Branch Save Undone Lua Callback Just doing SavedCallback doesn't work, since it's not possible to receive in Lua whether it was a normally update or it came from an undo. --- .../tools/Lua/Libraries/TAStudioLuaLibrary.cs | 13 +++++++++++++ .../tools/TAStudio/BookmarksBranchesBox.cs | 4 +++- .../tools/TAStudio/TAStudio.Callbacks.cs | 6 ++++++ .../tools/TAStudio/TAStudio.cs | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs index fe8e15ea772..5a963921a08 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs @@ -605,5 +605,18 @@ public void OnBranchUndoLoad(LuaFunction luaf) }; } } + + [LuaMethodExample("function SaveUndone(index)\r\nconsole.log(\"You did a branch save undo for branch \"..index)\r\nend\r\ntastudio.onbranchundosave(SaveUndone)")] + [LuaMethod("onbranchundosave", "called whenever a branch save is undone. luaf must be a function that takes the integer branch index as a parameter")] + public void OnBranchUndoSave(LuaFunction luaf) + { + if (Engaged()) + { + Tastudio.BranchSaveUndoneCallback = index => + { + luaf.Call(index); + }; + } + } } } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index 7f0ab5e45eb..b0f6df17b24 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -39,6 +39,8 @@ private enum BranchUndo public Action LoadUndoneCallback { get; set; } + public Action SaveUndoneCallback { get; set; } + public TAStudio Tastudio { get; set; } public IDialogController DialogController => Tastudio.MainForm; @@ -369,7 +371,7 @@ private void UndoBranchToolStripMenuItem_Click(object sender, EventArgs e) if (branch != null) { Branches.Replace(branch, _backupBranch); - SavedCallback?.Invoke(Branches.IndexOf(_backupBranch)); + SaveUndoneCallback?.Invoke(Branches.IndexOf(_backupBranch)); Tastudio.MainForm.AddOnScreenMessage("Branch Update canceled"); } } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs index 01e7983e131..c62dfe17a85 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs @@ -14,6 +14,7 @@ public partial class TAStudio public Action BranchSavedCallback { get; set; } public Action BranchRemovedCallback { get; set; } public Action BranchLoadUndoneCallback { get; set; } + public Action BranchSaveUndoneCallback { get; set; } private void GreenzoneInvalidated(int index) { @@ -39,5 +40,10 @@ private void BranchLoadUndone() { BranchLoadUndoneCallback?.Invoke(); } + + private void BranchSaveUndone(int index) + { + BranchSaveUndoneCallback?.Invoke(index); + } } } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index b85497cde1f..e050d8d2fd8 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -149,6 +149,7 @@ public TAStudio() BookMarkControl.SavedCallback = BranchSaved; BookMarkControl.RemovedCallback = BranchRemoved; BookMarkControl.LoadUndoneCallback = BranchLoadUndone; + BookMarkControl.SaveUndoneCallback = BranchSaveUndone; TasView.MouseLeave += TAStudio_MouseLeave; TasView.CellHovered += (_, e) => { From cfe9354e3deb7cb8d0f5c5b716ab09b509d57e92 Mon Sep 17 00:00:00 2001 From: c7fab <26490633+c7fab@users.noreply.github.com> Date: Sun, 9 Feb 2025 03:18:29 +0100 Subject: [PATCH 3/8] Branch Remove Undone Lua Callback SavedCallback also doesn't work here. --- .../tools/Lua/Libraries/TAStudioLuaLibrary.cs | 13 +++++++++++++ .../tools/TAStudio/BookmarksBranchesBox.cs | 4 +++- .../tools/TAStudio/TAStudio.Callbacks.cs | 6 ++++++ .../tools/TAStudio/TAStudio.cs | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs index 5a963921a08..485d2877085 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs @@ -618,5 +618,18 @@ public void OnBranchUndoSave(LuaFunction luaf) }; } } + + [LuaMethodExample("function RemoveUndone(index)\r\nconsole.log(\"You did a branch remove undo for branch \"..index)\r\nend\r\ntastudio.onbranchundoremove(RemoveUndone)")] + [LuaMethod("onbranchundoremove", "called whenever a branch removal is undone. luaf must be a function that takes the integer branch index as a parameter")] + public void OnBranchUndoREmove(LuaFunction luaf) + { + if (Engaged()) + { + Tastudio.BranchRemoveUndoneCallback = index => + { + luaf.Call(index); + }; + } + } } } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index b0f6df17b24..8f2f0270ed6 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -41,6 +41,8 @@ private enum BranchUndo public Action SaveUndoneCallback { get; set; } + public Action RemoveUndoneCallback { get; set; } + public TAStudio Tastudio { get; set; } public IDialogController DialogController => Tastudio.MainForm; @@ -389,7 +391,7 @@ private void UndoBranchToolStripMenuItem_Click(object sender, EventArgs e) { Branches.Add(_backupBranch); BranchView.RowCount = Branches.Count; - SavedCallback?.Invoke(Branches.IndexOf(_backupBranch)); + RemoveUndoneCallback?.Invoke(Branches.IndexOf(_backupBranch)); Tastudio.MainForm.AddOnScreenMessage("Branch Removal canceled"); } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs index c62dfe17a85..b2b22f9a983 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs @@ -15,6 +15,7 @@ public partial class TAStudio public Action BranchRemovedCallback { get; set; } public Action BranchLoadUndoneCallback { get; set; } public Action BranchSaveUndoneCallback { get; set; } + public Action BranchRemoveUndoneCallback { get; set; } private void GreenzoneInvalidated(int index) { @@ -45,5 +46,10 @@ private void BranchSaveUndone(int index) { BranchSaveUndoneCallback?.Invoke(index); } + + private void BranchRemoveUndone(int index) + { + BranchRemoveUndoneCallback?.Invoke(index); + } } } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index e050d8d2fd8..c39e56943ab 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -150,6 +150,7 @@ public TAStudio() BookMarkControl.RemovedCallback = BranchRemoved; BookMarkControl.LoadUndoneCallback = BranchLoadUndone; BookMarkControl.SaveUndoneCallback = BranchSaveUndone; + BookMarkControl.RemoveUndoneCallback = BranchRemoveUndone; TasView.MouseLeave += TAStudio_MouseLeave; TasView.CellHovered += (_, e) => { From 46ae71df78e912b8dbf774ad0bdd6a3acce31de9 Mon Sep 17 00:00:00 2001 From: c7fab <26490633+c7fab@users.noreply.github.com> Date: Sun, 9 Feb 2025 03:25:17 +0100 Subject: [PATCH 4/8] tabs --- .../tools/Lua/Libraries/TAStudioLuaLibrary.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs index 485d2877085..f278be8120f 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs @@ -593,7 +593,7 @@ public void OnBranchRemove(LuaFunction luaf) } } - [LuaMethodExample("function LoadUndone()\r\nconsole.log(\"You did a branch load undo\")\r\nend\r\ntastudio.onbranchundoload(LoadUndone)")] + [LuaMethodExample("function LoadUndone()\r\n\tconsole.log(\"You did a branch load undo\")\r\nend\r\ntastudio.onbranchundoload(LoadUndone)")] [LuaMethod("onbranchundoload", "called whenever a branch load is undone. luaf must be a function without parameters")] public void OnBranchUndoLoad(LuaFunction luaf) { @@ -606,7 +606,7 @@ public void OnBranchUndoLoad(LuaFunction luaf) } } - [LuaMethodExample("function SaveUndone(index)\r\nconsole.log(\"You did a branch save undo for branch \"..index)\r\nend\r\ntastudio.onbranchundosave(SaveUndone)")] + [LuaMethodExample("function SaveUndone(index)\r\n\tconsole.log(\"You did a branch save undo for branch \"..index)\r\nend\r\ntastudio.onbranchundosave(SaveUndone)")] [LuaMethod("onbranchundosave", "called whenever a branch save is undone. luaf must be a function that takes the integer branch index as a parameter")] public void OnBranchUndoSave(LuaFunction luaf) { @@ -619,7 +619,7 @@ public void OnBranchUndoSave(LuaFunction luaf) } } - [LuaMethodExample("function RemoveUndone(index)\r\nconsole.log(\"You did a branch remove undo for branch \"..index)\r\nend\r\ntastudio.onbranchundoremove(RemoveUndone)")] + [LuaMethodExample("function RemoveUndone(index)\r\n\tconsole.log(\"You did a branch remove undo for branch \"..index)\r\nend\r\ntastudio.onbranchundoremove(RemoveUndone)")] [LuaMethod("onbranchundoremove", "called whenever a branch removal is undone. luaf must be a function that takes the integer branch index as a parameter")] public void OnBranchUndoREmove(LuaFunction luaf) { From 74e2628b5a79f473f29b0254c1986ce4f0ad20fe Mon Sep 17 00:00:00 2001 From: c7fab <26490633+c7fab@users.noreply.github.com> Date: Sun, 9 Feb 2025 03:34:03 +0100 Subject: [PATCH 5/8] Rename Save to Update Since Adding Branches can't be reverted. --- .../tools/Lua/Libraries/TAStudioLuaLibrary.cs | 8 ++++---- .../tools/TAStudio/BookmarksBranchesBox.cs | 4 ++-- .../tools/TAStudio/TAStudio.Callbacks.cs | 6 +++--- src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs index f278be8120f..0c0eca4c93a 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs @@ -606,13 +606,13 @@ public void OnBranchUndoLoad(LuaFunction luaf) } } - [LuaMethodExample("function SaveUndone(index)\r\n\tconsole.log(\"You did a branch save undo for branch \"..index)\r\nend\r\ntastudio.onbranchundosave(SaveUndone)")] - [LuaMethod("onbranchundosave", "called whenever a branch save is undone. luaf must be a function that takes the integer branch index as a parameter")] - public void OnBranchUndoSave(LuaFunction luaf) + [LuaMethodExample("function UpdateUndone(index)\r\n\tconsole.log(\"You did a branch updaate undo for branch \"..index)\r\nend\r\ntastudio.onbranchundoupdate(UpdateUndone)")] + [LuaMethod("onbranchundoupdate", "called whenever a branch update is undone. luaf must be a function that takes the integer branch index as a parameter")] + public void OnBranchUndoUpdate(LuaFunction luaf) { if (Engaged()) { - Tastudio.BranchSaveUndoneCallback = index => + Tastudio.BranchUpdateUndoneCallback = index => { luaf.Call(index); }; diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index 8f2f0270ed6..ceab375d1ed 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -39,7 +39,7 @@ private enum BranchUndo public Action LoadUndoneCallback { get; set; } - public Action SaveUndoneCallback { get; set; } + public Action UpdateUndoneCallback { get; set; } public Action RemoveUndoneCallback { get; set; } @@ -373,7 +373,7 @@ private void UndoBranchToolStripMenuItem_Click(object sender, EventArgs e) if (branch != null) { Branches.Replace(branch, _backupBranch); - SaveUndoneCallback?.Invoke(Branches.IndexOf(_backupBranch)); + UpdateUndoneCallback?.Invoke(Branches.IndexOf(_backupBranch)); Tastudio.MainForm.AddOnScreenMessage("Branch Update canceled"); } } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs index b2b22f9a983..4b37a294b70 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs @@ -14,7 +14,7 @@ public partial class TAStudio public Action BranchSavedCallback { get; set; } public Action BranchRemovedCallback { get; set; } public Action BranchLoadUndoneCallback { get; set; } - public Action BranchSaveUndoneCallback { get; set; } + public Action BranchUpdateUndoneCallback { get; set; } public Action BranchRemoveUndoneCallback { get; set; } private void GreenzoneInvalidated(int index) @@ -42,9 +42,9 @@ private void BranchLoadUndone() BranchLoadUndoneCallback?.Invoke(); } - private void BranchSaveUndone(int index) + private void BranchUpdateUndone(int index) { - BranchSaveUndoneCallback?.Invoke(index); + BranchUpdateUndoneCallback?.Invoke(index); } private void BranchRemoveUndone(int index) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index c39e56943ab..be325bc254e 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -149,7 +149,7 @@ public TAStudio() BookMarkControl.SavedCallback = BranchSaved; BookMarkControl.RemovedCallback = BranchRemoved; BookMarkControl.LoadUndoneCallback = BranchLoadUndone; - BookMarkControl.SaveUndoneCallback = BranchSaveUndone; + BookMarkControl.UpdateUndoneCallback = BranchUpdateUndone; BookMarkControl.RemoveUndoneCallback = BranchRemoveUndone; TasView.MouseLeave += TAStudio_MouseLeave; TasView.CellHovered += (_, e) => From 429298350e3fdcee15cc5cb3ea0b7616b872517c Mon Sep 17 00:00:00 2001 From: c7fab <26490633+c7fab@users.noreply.github.com> Date: Sun, 9 Feb 2025 20:37:48 +0100 Subject: [PATCH 6/8] Branch Reordering Lua Callback --- .../tools/Lua/Libraries/TAStudioLuaLibrary.cs | 13 +++++++++++++ .../tools/TAStudio/BookmarksBranchesBox.cs | 3 +++ .../tools/TAStudio/TAStudio.Callbacks.cs | 6 ++++++ .../tools/TAStudio/TAStudio.cs | 1 + 4 files changed, 23 insertions(+) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs index 0c0eca4c93a..0370f566268 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs @@ -631,5 +631,18 @@ public void OnBranchUndoREmove(LuaFunction luaf) }; } } + + [LuaMethodExample("function Reordered(oldindex, newindex)\r\n\tconsole.log(\"You reordered branches from \"..oldIndex..\" to \"..newIndex)\r\nend\r\ntastudio.onbranchesreorder(Reordered)")] + [LuaMethod("onbranchesreorder", "called whenever branches are reordered in the branches box. luaf must be a function that takes two integers for the branch indices as parameters")] + public void OnBranchesReorder(LuaFunction luaf) + { + if (Engaged()) + { + Tastudio.BranchesReorderedCallback = (oldIndex, newIndex) => + { + luaf.Call(oldIndex, newIndex); + }; + } + } } } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index ceab375d1ed..0891706c549 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -43,6 +43,8 @@ private enum BranchUndo public Action RemoveUndoneCallback { get; set; } + public Action ReorderedCallback { get; set; } + public TAStudio Tastudio { get; set; } public IDialogController DialogController => Tastudio.MainForm; @@ -641,6 +643,7 @@ private void BranchView_CellDropped(object sender, InputRoll.CellEventArgs e) : Branches[Branches.Current].Uuid; Branches.Swap(e.OldCell.RowIndex.Value, e.NewCell.RowIndex.Value); + ReorderedCallback?.Invoke(e.OldCell.RowIndex.Value, e.NewCell.RowIndex.Value); int newIndex = Branches.IndexOfHash(guid); Branches.Current = newIndex; Select(newIndex, true); diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs index 4b37a294b70..47f43a6bad6 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs @@ -16,6 +16,7 @@ public partial class TAStudio public Action BranchLoadUndoneCallback { get; set; } public Action BranchUpdateUndoneCallback { get; set; } public Action BranchRemoveUndoneCallback { get; set; } + public Action BranchesReorderedCallback { get; set; } private void GreenzoneInvalidated(int index) { @@ -51,5 +52,10 @@ private void BranchRemoveUndone(int index) { BranchRemoveUndoneCallback?.Invoke(index); } + + private void BranchesReordered(int oldIndex, int newIndex) + { + BranchesReorderedCallback?.Invoke(oldIndex, newIndex); + } } } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index be325bc254e..151a65a31f1 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -151,6 +151,7 @@ public TAStudio() BookMarkControl.LoadUndoneCallback = BranchLoadUndone; BookMarkControl.UpdateUndoneCallback = BranchUpdateUndone; BookMarkControl.RemoveUndoneCallback = BranchRemoveUndone; + BookMarkControl.ReorderedCallback = BranchesReordered; TasView.MouseLeave += TAStudio_MouseLeave; TasView.CellHovered += (_, e) => { From a348b9a465742d85bed4e78223637d8dd9dd82b8 Mon Sep 17 00:00:00 2001 From: c7fab <26490633+c7fab@users.noreply.github.com> Date: Sun, 9 Feb 2025 20:41:15 +0100 Subject: [PATCH 7/8] fix typo --- .../tools/Lua/Libraries/TAStudioLuaLibrary.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs index 0370f566268..eb64f29da09 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs @@ -621,7 +621,7 @@ public void OnBranchUndoUpdate(LuaFunction luaf) [LuaMethodExample("function RemoveUndone(index)\r\n\tconsole.log(\"You did a branch remove undo for branch \"..index)\r\nend\r\ntastudio.onbranchundoremove(RemoveUndone)")] [LuaMethod("onbranchundoremove", "called whenever a branch removal is undone. luaf must be a function that takes the integer branch index as a parameter")] - public void OnBranchUndoREmove(LuaFunction luaf) + public void OnBranchUndoRemove(LuaFunction luaf) { if (Engaged()) { From 77ebc468ae0f587d5868087f5a982444546fcc74 Mon Sep 17 00:00:00 2001 From: c7fab <26490633+c7fab@users.noreply.github.com> Date: Sun, 9 Feb 2025 21:45:59 +0100 Subject: [PATCH 8/8] GetSelectedBranch Lua function Add that too. Returns the index of the first selected branch in the branches list, nil if none selected or TAStudio not engaged. --- .../tools/Lua/Libraries/TAStudioLuaLibrary.cs | 12 ++++++++++++ .../tools/TAStudio/BookmarksBranchesBox.cs | 5 +++++ .../tools/TAStudio/TAStudio.cs | 1 + 3 files changed, 18 insertions(+) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs index eb64f29da09..8caad035ec8 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs @@ -401,6 +401,18 @@ public LuaTable GetBranches() indexFrom: 0); } + [LuaMethodExample("local branch = tastudio.getselectedbranch();")] + [LuaMethod("getselectedbranch", "gets the index of the first selected branch in the branches list")] + public int? GetSelectedBranch() + { + if (Engaged()) + { + return Tastudio.GetSelectedBranch(); + } + + return null; + } + [LuaMethodExample("local nltasget = tastudio.getbranchinput( \"97021544-2454-4483-824f-47f75e7fcb6a\", 500 );")] [LuaMethod("getbranchinput", "Gets the controller state of the given frame with the given branch identifier")] public LuaTable GetBranchInput(string branchId, int frame) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index 0891706c549..eab694e1dc0 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -461,6 +461,11 @@ public void RemoveBranchExternal() RemoveBranchToolStripMenuItem_Click(null, null); } + public int? GetSelectedBranch() + { + return BranchView.SelectionStartIndex; + } + public void SelectBranchExternal(int slot) { if (Tastudio.AxisEditingMode) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 151a65a31f1..949a103e553 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -440,6 +440,7 @@ public void AddColumn(string name, string text, int widthUnscaled) public void SelectAllExternal() => SelectAllMenuItem_Click(null, null); public void ReselectClipboardExternal() => ReselectClipboardMenuItem_Click(null, null); + public int? GetSelectedBranch() => BookMarkControl.GetSelectedBranch(); public IMovieController GetBranchInput(string branchId, int frame) { var branch = CurrentTasMovie.Branches.FirstOrDefault(b => b.Uuid.ToString() == branchId);