EmuLuaLibrary.Tastudio - organize methods some
This commit is contained in:
parent
6972046509
commit
a3428128ef
|
@ -43,12 +43,19 @@ namespace BizHawk.Client.EmuHawk
|
|||
DeleteFrames,
|
||||
};
|
||||
|
||||
public enum InputChangeTypes
|
||||
private enum InputChangeTypes
|
||||
{
|
||||
Bool,
|
||||
Float,
|
||||
};
|
||||
|
||||
public class TastudioBranchInfo
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public int Frame { get; set; }
|
||||
public string Text { get; set; }
|
||||
}
|
||||
|
||||
private readonly List<PendingChanges> _changeList = new List<PendingChanges>(); //TODO: Initialize it to empty list on a script reload, and have each script have it's own list
|
||||
|
||||
[LuaMethodExample("if ( tastudio.engaged( ) ) then\r\n\tconsole.log( \"returns whether or not tastudio is currently engaged ( active )\" );\r\nend;")]
|
||||
|
@ -82,70 +89,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
Tastudio.ToggleReadOnly();
|
||||
}
|
||||
|
||||
[LuaMethodExample("tastudio.setbranchtext( \"Some text\", 1 );")]
|
||||
[LuaMethod("setbranchtext", "adds the given message to the existing branch, or to the branch that will be created next if branch index is not specified")]
|
||||
public void SetBranchText(string text, int? index = null)
|
||||
{
|
||||
if (index != null)
|
||||
{
|
||||
Tastudio.CurrentTasMovie.GetBranch(index.Value).UserText = text;
|
||||
}
|
||||
else
|
||||
{
|
||||
Tastudio.CurrentTasMovie.NewBranchText = text;
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("local sttasget = tastudio.getmarker( 500 );")]
|
||||
[LuaMethod("getmarker", "returns the marker text at the given frame, or an empty string if there is no marker for the given frame")]
|
||||
public string GetMarker(int frame)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
var marker = Tastudio.CurrentTasMovie.Markers.Get(frame);
|
||||
if (marker != null)
|
||||
{
|
||||
return marker.Message;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
[LuaMethodExample("tastudio.removemarker( 500 );")]
|
||||
[LuaMethod("removemarker", "if there is a marker for the given frame, it will be removed")]
|
||||
public void RemoveMarker(int frame)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
var marker = Tastudio.CurrentTasMovie.Markers.Get(frame);
|
||||
if (marker != null)
|
||||
{
|
||||
Tastudio.CurrentTasMovie.Markers.Remove(marker);
|
||||
Tastudio.UpdateValues();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("tastudio.setmarker( 500, \"Some message\" );")]
|
||||
[LuaMethod("setmarker", "Adds or sets a marker at the given frame, with an optional message")]
|
||||
public void SetMarker(int frame, string message = null)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
var marker = Tastudio.CurrentTasMovie.Markers.Get(frame);
|
||||
if (marker != null)
|
||||
{
|
||||
marker.Message = message;
|
||||
}
|
||||
else
|
||||
{
|
||||
Tastudio.CurrentTasMovie.Markers.Add(frame, message);
|
||||
Tastudio.UpdateValues();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("local botasisl = tastudio.islag( 500 );")]
|
||||
[LuaMethod("islag", "Returns whether or not the given frame was a lag frame, null if unknown")]
|
||||
public bool? IsLag(int frame)
|
||||
|
@ -215,114 +158,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("tastudio.onqueryitembg( function( currentindex, itemname )\r\n\tconsole.log( \"called during the background draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)\" );\r\nend );")]
|
||||
[LuaMethod("onqueryitembg", "called during the background draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)")]
|
||||
public void OnQueryItemBg(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
Tastudio.QueryItemBgColorCallback = (index, name) =>
|
||||
{
|
||||
var result = luaf.Call(index, name);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
var color = ToColor(result[0]);
|
||||
return color;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("tastudio.onqueryitemtext( function( currentindex, itemname )\r\n\tconsole.log( \"called during the text draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)\" );\r\nend );")]
|
||||
[LuaMethod("onqueryitemtext", "called during the text draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)")]
|
||||
public void OnQueryItemText(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
Tastudio.QueryItemTextCallback = (index, name) =>
|
||||
{
|
||||
var result = luaf.Call(index, name);
|
||||
return result?[0]?.ToString();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("tastudio.onqueryitemicon( function( currentindex, itemname )\r\n\tconsole.log( \"called during the icon draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)\" );\r\nend );")]
|
||||
[LuaMethod("onqueryitemicon", "called during the icon draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)")]
|
||||
public void OnQueryItemIcon(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
Tastudio.QueryItemIconCallback = (index, name) =>
|
||||
{
|
||||
var result = luaf.Call(index, name);
|
||||
if (result?[0] != null)
|
||||
{
|
||||
string path = result[0].ToString();
|
||||
Icon icon = new Icon(path);
|
||||
return icon.ToBitmap();
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("tastudio.ongreenzoneinvalidated( function( currentindex, itemname )\r\n\tconsole.log( \"called whenever the greenzone is invalidated and returns the first frame that was invalidated\" );\r\nend );")]
|
||||
[LuaMethod("ongreenzoneinvalidated", "called whenever the greenzone is invalidated and returns the first frame that was invalidated")]
|
||||
public void OnGreenzoneInvalidated(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
Tastudio.GreenzoneInvalidatedCallback = index =>
|
||||
{
|
||||
luaf.Call(index);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("tastudio.ongreenzoneinvalidated( function( currentindex, itemname )\r\n\tconsole.log( \"called whenever the greenzone is invalidated and returns the first frame that was invalidated\" );\r\nend );")]
|
||||
[LuaMethod("onbranchload", "called whenever a branch is loaded. luaf must be a function that takes the integer branch index as a parameter")]
|
||||
public void OnBranchLoad(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
Tastudio.BranchLoadedCallback = index =>
|
||||
{
|
||||
luaf.Call(index);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("")]
|
||||
[LuaMethod("onbranchsave", "called whenever a branch is created or updated. luaf must be a function that takes the integer branch index as a parameter")]
|
||||
public void OnBranchSave(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
Tastudio.BranchSavedCallback = index =>
|
||||
{
|
||||
luaf.Call(index);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("")]
|
||||
[LuaMethod("onbranchremove", "called whenever a branch is removed. luaf must be a function that takes the integer branch index as a parameter")]
|
||||
public void OnBranchRemove(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
Tastudio.BranchRemovedCallback = index =>
|
||||
{
|
||||
luaf.Call(index);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("local nltasget = tastudio.getselection( );")]
|
||||
[LuaMethod("getselection", "gets the currently selected frames")]
|
||||
public LuaTable GetSelection()
|
||||
|
@ -342,78 +177,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
return table;
|
||||
}
|
||||
|
||||
public class TastudioBranchInfo
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public int Frame { get; set; }
|
||||
public string Text { get; set; }
|
||||
}
|
||||
|
||||
[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")]
|
||||
public LuaTable GetBranches()
|
||||
{
|
||||
var table = Lua.NewTable();
|
||||
|
||||
if (Engaged())
|
||||
{
|
||||
var branches = Tastudio.CurrentTasMovie.Branches
|
||||
.Select(b => new
|
||||
{
|
||||
Id = b.UniqueIdentifier.ToString(),
|
||||
b.Frame,
|
||||
Text = b.UserText
|
||||
})
|
||||
.ToList();
|
||||
|
||||
for (int i = 0; i < branches.Count; i++)
|
||||
{
|
||||
table[i] = branches[i];
|
||||
}
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
[LuaMethodExample("local nltasget = tastudio.getbranchinput( \"97021544-2454-4483-824f-47f75e7fcb6a\", 500 );")]
|
||||
[LuaMethod("getbranchinput", "Gets the controller state of the given frame with the given branch identifier")]
|
||||
public LuaTable GetBranchInput(string branchId, int frame)
|
||||
{
|
||||
var table = Lua.NewTable();
|
||||
|
||||
if (Engaged())
|
||||
{
|
||||
if (Tastudio.CurrentTasMovie.Branches.Any(b => b.UniqueIdentifier.ToString() == branchId))
|
||||
{
|
||||
var branch = Tastudio.CurrentTasMovie.Branches.First(b => b.UniqueIdentifier.ToString() == branchId);
|
||||
if (frame < branch.InputLog.Count)
|
||||
{
|
||||
var input = branch.InputLog[frame];
|
||||
|
||||
var adapter = new Bk2ControllerAdapter
|
||||
{
|
||||
Definition = Global.MovieSession.MovieControllerAdapter.Definition
|
||||
};
|
||||
|
||||
adapter.SetControllersAsMnemonic(input);
|
||||
|
||||
foreach (var button in adapter.Definition.BoolButtons)
|
||||
{
|
||||
table[button] = adapter.IsPressed(button);
|
||||
}
|
||||
|
||||
foreach (var button in adapter.Definition.FloatControls)
|
||||
{
|
||||
table[button] = adapter.GetFloat(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
[LuaMethodExample("")]
|
||||
[LuaMethod("submitinputchange", "")]
|
||||
public void SubmitInputChange(int frame, string button, bool value)
|
||||
|
@ -584,5 +347,253 @@ namespace BizHawk.Client.EmuHawk
|
|||
Tastudio.AddColumn(name, text, width, ColumnType.Text);
|
||||
}
|
||||
}
|
||||
|
||||
#region Branches
|
||||
|
||||
[LuaMethodExample("tastudio.setbranchtext( \"Some text\", 1 );")]
|
||||
[LuaMethod("setbranchtext", "adds the given message to the existing branch, or to the branch that will be created next if branch index is not specified")]
|
||||
public void SetBranchText(string text, int? index = null)
|
||||
{
|
||||
if (index != null)
|
||||
{
|
||||
Tastudio.CurrentTasMovie.GetBranch(index.Value).UserText = text;
|
||||
}
|
||||
else
|
||||
{
|
||||
Tastudio.CurrentTasMovie.NewBranchText = text;
|
||||
}
|
||||
}
|
||||
|
||||
[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")]
|
||||
public LuaTable GetBranches()
|
||||
{
|
||||
var table = Lua.NewTable();
|
||||
|
||||
if (Engaged())
|
||||
{
|
||||
var branches = Tastudio.CurrentTasMovie.Branches
|
||||
.Select(b => new
|
||||
{
|
||||
Id = b.UniqueIdentifier.ToString(),
|
||||
b.Frame,
|
||||
Text = b.UserText
|
||||
})
|
||||
.ToList();
|
||||
|
||||
for (int i = 0; i < branches.Count; i++)
|
||||
{
|
||||
table[i] = branches[i];
|
||||
}
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
[LuaMethodExample("local nltasget = tastudio.getbranchinput( \"97021544-2454-4483-824f-47f75e7fcb6a\", 500 );")]
|
||||
[LuaMethod("getbranchinput", "Gets the controller state of the given frame with the given branch identifier")]
|
||||
public LuaTable GetBranchInput(string branchId, int frame)
|
||||
{
|
||||
var table = Lua.NewTable();
|
||||
|
||||
if (Engaged())
|
||||
{
|
||||
if (Tastudio.CurrentTasMovie.Branches.Any(b => b.UniqueIdentifier.ToString() == branchId))
|
||||
{
|
||||
var branch = Tastudio.CurrentTasMovie.Branches.First(b => b.UniqueIdentifier.ToString() == branchId);
|
||||
if (frame < branch.InputLog.Count)
|
||||
{
|
||||
var input = branch.InputLog[frame];
|
||||
|
||||
var adapter = new Bk2ControllerAdapter
|
||||
{
|
||||
Definition = Global.MovieSession.MovieControllerAdapter.Definition
|
||||
};
|
||||
|
||||
adapter.SetControllersAsMnemonic(input);
|
||||
|
||||
foreach (var button in adapter.Definition.BoolButtons)
|
||||
{
|
||||
table[button] = adapter.IsPressed(button);
|
||||
}
|
||||
|
||||
foreach (var button in adapter.Definition.FloatControls)
|
||||
{
|
||||
table[button] = adapter.GetFloat(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Markers
|
||||
|
||||
[LuaMethodExample("local sttasget = tastudio.getmarker( 500 );")]
|
||||
[LuaMethod("getmarker", "returns the marker text at the given frame, or an empty string if there is no marker for the given frame")]
|
||||
public string GetMarker(int frame)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
var marker = Tastudio.CurrentTasMovie.Markers.Get(frame);
|
||||
if (marker != null)
|
||||
{
|
||||
return marker.Message;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
[LuaMethodExample("tastudio.removemarker( 500 );")]
|
||||
[LuaMethod("removemarker", "if there is a marker for the given frame, it will be removed")]
|
||||
public void RemoveMarker(int frame)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
var marker = Tastudio.CurrentTasMovie.Markers.Get(frame);
|
||||
if (marker != null)
|
||||
{
|
||||
Tastudio.CurrentTasMovie.Markers.Remove(marker);
|
||||
Tastudio.UpdateValues();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("tastudio.setmarker( 500, \"Some message\" );")]
|
||||
[LuaMethod("setmarker", "Adds or sets a marker at the given frame, with an optional message")]
|
||||
public void SetMarker(int frame, string message = null)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
var marker = Tastudio.CurrentTasMovie.Markers.Get(frame);
|
||||
if (marker != null)
|
||||
{
|
||||
marker.Message = message;
|
||||
}
|
||||
else
|
||||
{
|
||||
Tastudio.CurrentTasMovie.Markers.Add(frame, message);
|
||||
Tastudio.UpdateValues();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
[LuaMethodExample("tastudio.onqueryitembg( function( currentindex, itemname )\r\n\tconsole.log( \"called during the background draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)\" );\r\nend );")]
|
||||
[LuaMethod("onqueryitembg", "called during the background draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)")]
|
||||
public void OnQueryItemBg(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
Tastudio.QueryItemBgColorCallback = (index, name) =>
|
||||
{
|
||||
var result = luaf.Call(index, name);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
var color = ToColor(result[0]);
|
||||
return color;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("tastudio.onqueryitemtext( function( currentindex, itemname )\r\n\tconsole.log( \"called during the text draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)\" );\r\nend );")]
|
||||
[LuaMethod("onqueryitemtext", "called during the text draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)")]
|
||||
public void OnQueryItemText(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
Tastudio.QueryItemTextCallback = (index, name) =>
|
||||
{
|
||||
var result = luaf.Call(index, name);
|
||||
return result?[0]?.ToString();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("tastudio.onqueryitemicon( function( currentindex, itemname )\r\n\tconsole.log( \"called during the icon draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)\" );\r\nend );")]
|
||||
[LuaMethod("onqueryitemicon", "called during the icon draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)")]
|
||||
public void OnQueryItemIcon(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
Tastudio.QueryItemIconCallback = (index, name) =>
|
||||
{
|
||||
var result = luaf.Call(index, name);
|
||||
if (result?[0] != null)
|
||||
{
|
||||
string path = result[0].ToString();
|
||||
Icon icon = new Icon(path);
|
||||
return icon.ToBitmap();
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("tastudio.ongreenzoneinvalidated( function( currentindex, itemname )\r\n\tconsole.log( \"called whenever the greenzone is invalidated and returns the first frame that was invalidated\" );\r\nend );")]
|
||||
[LuaMethod("ongreenzoneinvalidated", "called whenever the greenzone is invalidated and returns the first frame that was invalidated")]
|
||||
public void OnGreenzoneInvalidated(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
Tastudio.GreenzoneInvalidatedCallback = index =>
|
||||
{
|
||||
luaf.Call(index);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("tastudio.ongreenzoneinvalidated( function( currentindex, itemname )\r\n\tconsole.log( \"called whenever the greenzone is invalidated and returns the first frame that was invalidated\" );\r\nend );")]
|
||||
[LuaMethod("onbranchload", "called whenever a branch is loaded. luaf must be a function that takes the integer branch index as a parameter")]
|
||||
public void OnBranchLoad(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
Tastudio.BranchLoadedCallback = index =>
|
||||
{
|
||||
luaf.Call(index);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("")]
|
||||
[LuaMethod("onbranchsave", "called whenever a branch is created or updated. luaf must be a function that takes the integer branch index as a parameter")]
|
||||
public void OnBranchSave(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
Tastudio.BranchSavedCallback = index =>
|
||||
{
|
||||
luaf.Call(index);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("")]
|
||||
[LuaMethod("onbranchremove", "called whenever a branch is removed. luaf must be a function that takes the integer branch index as a parameter")]
|
||||
public void OnBranchRemove(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
Tastudio.BranchRemovedCallback = index =>
|
||||
{
|
||||
luaf.Call(index);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue