-
Notifications
You must be signed in to change notification settings - Fork 401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tastudio Lua Branch Action Callbacks, getselectedbranch() #4216
base: master
Are you sure you want to change the base?
Conversation
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.
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.
SavedCallback also doesn't work here.
Since Adding Branches can't be reverted.
Missing callback for branch reordering |
Add that too. Returns the index of the first selected branch in the branches list, nil if none selected or TAStudio not engaged.
Should the branch indices be +1? |
@@ -358,7 +366,7 @@ private void UndoBranchToolStripMenuItem_Click(object sender, EventArgs e) | |||
if (_branchUndo == BranchUndo.Load) | |||
{ | |||
LoadBranch(_backupBranch); | |||
LoadedCallback?.Invoke(Branches.IndexOf(_backupBranch)); | |||
LoadUndoneCallback?.Invoke(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick glance at this PR and it seems you're adding a bunch more callbacks when ones already exist? Would it not be suitable to subscribe to those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently it only properly works with undoing branch loads, because there it's possible to get that a branch action undo has been occured, since the the index of the backup branch is -1 when doing an undo load.
For Saving and Removing it's not possible to figure out in lua whether it was a normal action or an undo. The index for undoing saving is just the same as doing a regular branch save, so no chance to figure out which occured. And remove undo is just like adding a new branch.
The user might want to do different things in lua depending on what has happened with the branches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand—you're changing this callsite to differentiate it from the callsite in PrepareHistoryAndLoadSelectedBranch
? I think adding an argument would be a better approach. @feos Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's something I thought about doing too, but only have one onbranchaction method and make luaf a function that takes an integer for the index and a string for every action "save", "load", "remove", "undoload" "undoupdate" and "undoremove" and make the current deprecated. Reordering then still has it's own method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think adding an argument would be a better approach.
Agreed.
That's something I thought about doing too, but only have one onbranchaction method and make luaf a function that takes an integer for the index and a string for every action "save", "load", "remove", "undoload" "undoupdate" and "undoremove" and make the current deprecated.
That's not what Yoshi is suggesting. Just expand the existing ones a little bit to include the info on whether they come from the undo operation. Combining everything into one megacallback passing around strings is not better (tho I can't verbalize why).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because then the script author would be forced to care.
If you add a parameter to the existing callback, existing scripts will continue to work, and authors can opt-in to caring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing with string would mean the user can then just make a lua table with functions and make each table index a string. Then there wouldn't be many if-statements in the callback function.
Either way, I don't mind how it's done as long as it finally works
@@ -592,5 +604,57 @@ public void OnBranchRemove(LuaFunction luaf) | |||
}; | |||
} | |||
} | |||
|
|||
[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")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use existing docs as inspiration because they suck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What needs rewrite? LuaMethodExample or LuaMethod?
Implements proper callbacks for branch load/update/remove undos.
Previously it didn't work, since it wasn't possible to receive in Lua whether the callback came from a regular action or an undo.
Add a callback when the user reorders branches in the branches list.
Add a lua method for getting the index in the first selected branch in the branches list.