Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,19 @@ public void SetBranchText(string text, int? index = null)
}
}

[LuaMethodExample("""
tastudio.set_branch_text_by_id("97021544-2454-4483-824f-47f75e7fcb6a", "success at frame "..emu.framecount());
""")]
Comment thread
SuuperW marked this conversation as resolved.
[LuaMethod(
name: "set_branch_text_by_id",
description: "Loads the branch with the given ID.")]
public void SetBranchTextByID(string id, string/*?*/ text)
{
var found = GetBranchObjByID(id: id, callerFunctionName: "set_branch_text_by_id");
if (found is not null) found.UserText = text;
// else already logged error
}

[LuaMethodExample("local nltasget = tastudio.getbranches( );")]
[LuaMethod("getbranches", "Returns a list of the current tastudio branches. Each entry will have the Id, Frame, and Text properties of the branch")]
[return: LuaZeroIndexed]
Expand All @@ -471,12 +484,12 @@ public LuaTable GetBranches()
""")]
[LuaMethod(
name: "get_branch_index_by_id",
description: "Finds the branch with the given UUID (0-indexed). Returns nil if not found.")]
description: "Finds the branch with the given ID (0-indexed). Returns nil if not found.")]
public int? GetBranchIndexByID(string id)
{
if (!Guid.TryParseExact(id, format: "D", out var parsed))
{
Log($"not a valid UUID: {id}");
Log($"[tastudio.get_branch_index_by_id] not a valid UUID: {id}");
return null;
}
return Tastudio.CurrentTasMovie.Branches.Index()
Expand Down Expand Up @@ -506,6 +519,31 @@ public LuaTable GetBranchInput(string branchId, int frame)
return table;
}

[LuaMethodExample("""
tastudio.load_branch_by_id("97021544-2454-4483-824f-47f75e7fcb6a");
""")]
[LuaMethod(
name: "load_branch_by_id",
description: "Loads the branch with the given ID.")]
public void LoadBranchByID(string id)
{
var found = GetBranchObjByID(id: id, callerFunctionName: "load_branch_by_id");
if (found is not null) Tastudio.LoadBranch(found);
// else already logged error
}

private TasBranch/*?*/ GetBranchObjByID(string id, string callerFunctionName)
{
if (!Guid.TryParseExact(id, format: "D", out var parsed))
{
Log($"[tastudio.{callerFunctionName}] not a valid UUID: {id}");
return null;
}
var found = Tastudio.CurrentTasMovie.Branches.FirstOrDefault(b => b.Uuid == parsed);
if (found is null) Log($"[tastudio.{callerFunctionName}] no such branch: {id}");
return found;
}

[LuaMethodExample("tastudio.loadbranch(0)")]
[LuaMethod("loadbranch", "Loads a branch at the given index, if a branch at that index exists.")]
public void LoadBranch(int index)
Expand All @@ -525,6 +563,36 @@ public void LoadBranch(int index)
}
}

[LuaMethodExample("""
local branch_id = tastudio.create_branch("automated attempt");
""")]
[LuaMethod(
name: "create_branch",
description: "Creates a new branch at the end of the list, and returns its ID.")]
public string CreateBranch(string/*?*/ text = null)
{
Tastudio.BookMarkControl.Branch();
var index = Tastudio.CurrentTasMovie.Branches.Count - 1;
var branch = Tastudio.CurrentTasMovie.Branches[index];
branch.UserText = text;
Tastudio.BranchSavedCallback?.Invoke(index);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer changing the Branch method to return the instance, instead of grabbing it by index here.

Also, I think the Branch method should handle calling BranchSavedCallback. It looks like from reading related code that the callback isn't called if you branch with the context menu item, so you'd be fixing that too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other existing callsites use the index.

The callback can't be moved to the end of Branch because of this:

Branch();
EditBranchTextPopUp(Branches.Current);
Tastudio.BranchSavedCallback?.Invoke(Branches.Count - 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other existing callsites use the index.

So? They don't grab the branch, and updating Branch to return the branch will not require changing any existing uses.

The callback can't be moved to the end of Branch because of this:

Because of what? The branch not having text at the end of Branch? It should be easy enough to place a call to EditBranchTextPopUp inside Branch depending on a parameter.

return branch.Uuid.ToString("D");
}

[LuaMethodExample("""
tastudio.delete_branch_by_id("97021544-2454-4483-824f-47f75e7fcb6a");
""")]
[LuaMethod(
name: "delete_branch_by_id",
description: "Deletes the branch with the given ID."
+ " There is no confirmation, so remember to back up your project before botting with it.")]
public void DeleteBranchByID(string id)
{
var found = GetBranchObjByID(id: id, callerFunctionName: "delete_branch_by_id");
if (found is not null) Tastudio.CurrentTasMovie.Branches.Remove(found);
// else already logged error
}

[LuaMethodExample("local sttasget = tastudio.getmarker( 500 );")]
[LuaMethod(
name: "getmarker",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading