Skip to content

Commit f4d9829

Browse files
YoshiRulzc7fab
andcommitted
Return frame numbers, merge branch and non-, rename, and update docs
Co-Authored-By: c7fab <[email protected]>
1 parent 3de9146 commit f4d9829

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -459,40 +459,35 @@ public string GetMarker(int frame)
459459
return "";
460460
}
461461

462-
private LuaTable CreateMarkerTuple(TasMovieMarker marker)
463-
{
464-
var table = _th.CreateTable();
465-
table["Frame"] = marker.Frame;
466-
table["Text"] = marker.Message;
467-
return table;
468-
}
469-
470-
[LuaMethodExample("local markerframe = tastudio.getmarkerabove(100).Frame")]
471-
[LuaMethod("getmarkerabove", "returns a table of the marker at or above the given frame with fields Frame and Text")]
472-
public LuaTable GetMarkerAbove(int frame)
462+
/// <remarks>assumes a TAStudio project is loaded</remarks>
463+
private TasMovieMarkerList MarkerListForBranch(int? branchIndex)
464+
=> branchIndex is int i
465+
? Tastudio.CurrentTasMovie.Branches[i].Markers
466+
: Tastudio.CurrentTasMovie.Markers;
467+
468+
[LuaMethodExample("""
469+
local marker_label = tastudio.getmarker(tastudio.find_marker_on_or_before(100));
470+
""")]
471+
[LuaMethod(
472+
name: "find_marker_on_or_before",
473+
description: "Returns the frame number of the marker closest to the given frame (including that frame, but not after it)."
474+
+ " This may be the power-on marker at 0."
475+
+ " If branchIndex is specified, searches the markers in that branch instead.")]
476+
public int FindMarkerOnOrBefore(int frame, int? branchIndex = null)
473477
=> Engaged()
474-
? CreateMarkerTuple(Tastudio.CurrentTasMovie.Markers.PreviousOrCurrent(frame))
475-
: _th.CreateTable();
476-
477-
[LuaMethodExample("local branchmarkertext = tastudio.getbranchmarkerabove(0, 100).Text")]
478-
[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")]
479-
public LuaTable GetBranchMarkerAbove(int index, int frame)
480-
=> Engaged()
481-
? CreateMarkerTuple(Tastudio.CurrentTasMovie.Branches[index].Markers.PreviousOrCurrent(frame))
482-
: _th.CreateTable();
483-
484-
[LuaMethodExample("local markertext = tastudio.getmarkers()[1].Text")]
485-
[LuaMethod("getmarkers", "returns a table of all markers with fields Frame and Text")]
486-
public LuaTable GetMarkers()
487-
=> Engaged()
488-
? _th.EnumerateToLuaTable(Tastudio.CurrentTasMovie.Markers.Select(CreateMarkerTuple))
489-
: _th.CreateTable();
490-
491-
[LuaMethodExample("local branchmarkerframe = tastudio.getmarkers(0)[1].Frame")]
492-
[LuaMethod("getbranchmarkers", "returns a table of all markers for the given branch index, starting at 0, with fields Frame and Text")]
493-
public LuaTable GetBranchMarkers(int index)
478+
? MarkerListForBranch(branchIndex).PreviousOrCurrent(frame).Frame
479+
: default;
480+
481+
[LuaMethodExample("""
482+
local marker_label = tastudio.getmarker(tastudio.get_frames_with_markers()[2]);
483+
""")]
484+
[LuaMethod(
485+
name: "get_frames_with_markers",
486+
description: "Returns a list of all the frames which have markers on them."
487+
+ " If branchIndex is specified, instead returns the frames which have markers in that branch.")]
488+
public LuaTable GetFramesWithMarkers(int? branchIndex = null)
494489
=> Engaged()
495-
? _th.EnumerateToLuaTable(Tastudio.CurrentTasMovie.Branches[index].Markers.Select(CreateMarkerTuple))
490+
? _th.EnumerateToLuaTable(MarkerListForBranch(branchIndex).Select(static m => m.Frame))
496491
: _th.CreateTable();
497492

498493
[LuaMethodExample("tastudio.removemarker( 500 );")]

0 commit comments

Comments
 (0)