From f4d98293d82c9138ee1e3b025671048799ec15ce Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Wed, 28 May 2025 00:14:10 +1000 Subject: [PATCH] Return frame numbers, merge branch and non-, rename, and update docs Co-Authored-By: c7fab <26490633+c7fab@users.noreply.github.com> --- .../tools/Lua/Libraries/TAStudioLuaLibrary.cs | 55 +++++++++---------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs index c21f884b3e..4a73799b61 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs @@ -459,40 +459,35 @@ namespace BizHawk.Client.EmuHawk return ""; } - private LuaTable CreateMarkerTuple(TasMovieMarker marker) - { - var table = _th.CreateTable(); - table["Frame"] = marker.Frame; - table["Text"] = marker.Message; - return table; - } + /// assumes a TAStudio project is loaded + private TasMovieMarkerList MarkerListForBranch(int? branchIndex) + => branchIndex is int i + ? Tastudio.CurrentTasMovie.Branches[i].Markers + : Tastudio.CurrentTasMovie.Markers; - [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) + [LuaMethodExample(""" + local marker_label = tastudio.getmarker(tastudio.find_marker_on_or_before(100)); + """)] + [LuaMethod( + name: "find_marker_on_or_before", + description: "Returns the frame number of the marker closest to the given frame (including that frame, but not after it)." + + " This may be the power-on marker at 0." + + " If branchIndex is specified, searches the markers in that branch instead.")] + public int FindMarkerOnOrBefore(int frame, int? branchIndex = null) => Engaged() - ? CreateMarkerTuple(Tastudio.CurrentTasMovie.Markers.PreviousOrCurrent(frame)) - : _th.CreateTable(); + ? MarkerListForBranch(branchIndex).PreviousOrCurrent(frame).Frame + : default; - [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) + [LuaMethodExample(""" + local marker_label = tastudio.getmarker(tastudio.get_frames_with_markers()[2]); + """)] + [LuaMethod( + name: "get_frames_with_markers", + description: "Returns a list of all the frames which have markers on them." + + " If branchIndex is specified, instead returns the frames which have markers in that branch.")] + public LuaTable GetFramesWithMarkers(int? branchIndex = null) => Engaged() - ? CreateMarkerTuple(Tastudio.CurrentTasMovie.Branches[index].Markers.PreviousOrCurrent(frame)) - : _th.CreateTable(); - - [LuaMethodExample("local markertext = tastudio.getmarkers()[1].Text")] - [LuaMethod("getmarkers", "returns a table of all markers with fields Frame and Text")] - public LuaTable GetMarkers() - => Engaged() - ? _th.EnumerateToLuaTable(Tastudio.CurrentTasMovie.Markers.Select(CreateMarkerTuple)) - : _th.CreateTable(); - - [LuaMethodExample("local branchmarkerframe = tastudio.getmarkers(0)[1].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) - => Engaged() - ? _th.EnumerateToLuaTable(Tastudio.CurrentTasMovie.Branches[index].Markers.Select(CreateMarkerTuple)) + ? _th.EnumerateToLuaTable(MarkerListForBranch(branchIndex).Select(static m => m.Frame)) : _th.CreateTable(); [LuaMethodExample("tastudio.removemarker( 500 );")]