Lua - implement tastudio.getbranches() and tastudio.getbranchinput(), fixes #843
This commit is contained in:
parent
34d3073346
commit
3f8aa0e018
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
@ -289,5 +290,74 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TastudioBranchInfo
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public int Frame { get; set; }
|
||||
public string Text { get; set; }
|
||||
}
|
||||
|
||||
[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(),
|
||||
Frame = b.Frame,
|
||||
Text = b.UserText
|
||||
})
|
||||
.ToList();
|
||||
|
||||
for (int i = 0; i < branches.Count; i++)
|
||||
{
|
||||
table[i] = branches[i];
|
||||
}
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
[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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue