TAStudio marker lua (#4272)

* getmarkers

Lua method to get a table with  all markers for the current TasMovie, with Frame and Text as fields

* getmarkerabove

Returns a table of the marker at or above the given frame

* getbranchmarkerabove

same as getbranchmarker, but for getting the marker from a branch

* getbranchmarkers

returns a list of all markers for the given branchId, with fields Frame and Text
This commit is contained in:
c7fab 2025-03-22 16:56:26 +01:00 committed by GitHub
parent df33165b5a
commit eb79f2e735
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 69 additions and 0 deletions

View File

@ -459,6 +459,75 @@ namespace BizHawk.Client.EmuHawk
return "";
}
[LuaMethodExample("local markerframe = tastudio.getmarkerabove(100).Frame")]
[LuaMethod("getmarkerabove", "returns a table of the marker at or above the given frame with fields Frame and Text")]
public LuaTable GetMarkerAbove(int frame)
{
var table = _th.CreateTable();
if (!Engaged()) return table;
var marker = Tastudio.CurrentTasMovie.Markers.PreviousOrCurrent(frame);
table["Frame"] = marker.Frame;
table["Text"] = marker.Message;
return table;
}
[LuaMethodExample("local branchmarkertext = tastudio.getbranchmarkerabove(0, 100).Text")]
[LuaMethod("getbranchmarkerabove", "returns a table of the marker at or above the given frame for the given branch index, starting at 0, with fields Frame and Text")]
public LuaTable GetBranchMarkerAbove(int index, int frame)
{
var table = _th.CreateTable();
if (!Engaged()) return table;
if (index >= Tastudio.CurrentTasMovie.Branches.Count) return table;
var branch = Tastudio.CurrentTasMovie.Branches[index];
var marker = branch.Markers.PreviousOrCurrent(frame);
table["Frame"] = marker.Frame;
table["Text"] = marker.Message;
return table;
}
[LuaMethodExample("local markertext = tastudio.getmarkers()[0].Text")]
[LuaMethod("getmarkers", "returns a table of all markers with fields Frame and Text")]
public LuaTable GetMarkers()
{
if (!Engaged()) return _th.CreateTable();
return _th.EnumerateToLuaTable(
Tastudio.CurrentTasMovie.Markers.Select(m =>
{
var table = _th.CreateTable();
table["Frame"] = m.Frame;
table["Text"] = m.Message;
return table;
}),
indexFrom: 0);
}
[LuaMethodExample("local branchmarkerframe = tastudio.getmarkers(0)[0].Frame")]
[LuaMethod("getbranchmarkers", "returns a table of all markers for the given branch index, starting at 0, with fields Frame and Text")]
public LuaTable GetBranchMarkers(int index)
{
if (!Engaged()) return _th.CreateTable();
if (index >= Tastudio.CurrentTasMovie.Branches.Count) return _th.CreateTable();
var branch = Tastudio.CurrentTasMovie.Branches[index];
return _th.EnumerateToLuaTable(
branch.Markers.Select(m =>
{
var table = _th.CreateTable();
table["Frame"] = m.Frame;
table["Text"] = m.Message;
return table;
}),
indexFrom: 0);
}
[LuaMethodExample("tastudio.removemarker( 500 );")]
[LuaMethod("removemarker", "if there is a marker for the given frame, it will be removed")]
public void RemoveMarker(int frame)