Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

c7fab
Copy link
Contributor

@c7fab c7fab commented Feb 9, 2025

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.

c7fab added 5 commits February 8, 2025 22:00
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.
@c7fab c7fab marked this pull request as draft February 9, 2025 04:45
@c7fab
Copy link
Contributor Author

c7fab commented Feb 9, 2025

Missing callback for branch reordering

c7fab added 3 commits February 9, 2025 20:37
Add that too. Returns the index of the first selected branch in the branches list, nil if none selected or TAStudio not engaged.
@c7fab c7fab changed the title Tastudio Lua Branch Undo Callbacks Tastudio Lua Branch Action Callbacks, getselectedbranch() Feb 9, 2025
@c7fab c7fab marked this pull request as ready for review February 9, 2025 20:53
@c7fab
Copy link
Contributor Author

c7fab commented Feb 9, 2025

Should the branch indices be +1?
For now every index is off by one compared to the indices in the branches list. Would make it more userfriendly.

@@ -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();
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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).

Copy link
Member

@YoshiRulz YoshiRulz Feb 10, 2025

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.

Copy link
Contributor Author

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")]
Copy link
Member

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

Copy link
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants