majorly refactor Bk2Controller more
This commit is contained in:
parent
2f750e8469
commit
aa80c3a0d6
|
@ -65,7 +65,7 @@ namespace BizHawk.Client.Common
|
|||
MovieInputSourceAdapter.Source = MultitrackRewiringAdapter;
|
||||
ControllerOutput.Source = MovieOutputHardpoint;
|
||||
|
||||
Global.MovieSession.MovieControllerAdapter.Definition = MovieInputSourceAdapter.Definition;
|
||||
Global.MovieSession.SetMovieController(MovieInputSourceAdapter.Definition);
|
||||
|
||||
// connect the movie session before MovieOutputHardpoint if it is doing anything
|
||||
// otherwise connect the MovieInputSourceAdapter to it, effectively bypassing the movie session
|
||||
|
|
|
@ -47,6 +47,11 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
public Action ModeChangedCallback { get; set; }
|
||||
|
||||
public void SetMovieController(ControllerDefinition definition)
|
||||
{
|
||||
MovieControllerAdapter = new Bk2Controller(definition);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simply shortens the verbosity necessary otherwise
|
||||
/// </summary>
|
||||
|
@ -59,9 +64,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public IMovieController MovieControllerInstance()
|
||||
{
|
||||
var adapter = Movie.LogGeneratorInstance().MovieControllerAdapter;
|
||||
adapter.Definition = MovieControllerAdapter.Definition;
|
||||
return adapter;
|
||||
return Movie.LogGeneratorInstance().MovieControllerAdapter;
|
||||
}
|
||||
|
||||
// Convenience property that gets the controller state from the movie for the most recent frame
|
||||
|
|
|
@ -13,41 +13,34 @@ namespace BizHawk.Client.Common
|
|||
private readonly WorkingDictionary<string, bool> _myBoolButtons = new WorkingDictionary<string, bool>();
|
||||
private readonly WorkingDictionary<string, float> _myAxisControls = new WorkingDictionary<string, float>();
|
||||
|
||||
private Bk2ControllerDefinition _type = new Bk2ControllerDefinition();
|
||||
private List<ControlMap> _controlsOrdered = new List<ControlMap>();
|
||||
private readonly Bk2ControllerDefinition _type;
|
||||
private readonly List<ControlMap> _controlsOrdered;
|
||||
|
||||
public Bk2Controller()
|
||||
{
|
||||
}
|
||||
|
||||
public Bk2Controller(string key)
|
||||
public Bk2Controller(string key, ControllerDefinition definition) : this(definition)
|
||||
{
|
||||
_logKey = key;
|
||||
SetLogOverride();
|
||||
}
|
||||
|
||||
#region IController Implementation
|
||||
|
||||
public ControllerDefinition Definition
|
||||
public Bk2Controller(ControllerDefinition definition)
|
||||
{
|
||||
get => _type;
|
||||
set
|
||||
{
|
||||
_type = new Bk2ControllerDefinition(value);
|
||||
_type = new Bk2ControllerDefinition(definition);
|
||||
SetLogOverride();
|
||||
|
||||
var def = Global.Emulator.ControllerDefinition;
|
||||
_controlsOrdered = Definition.ControlsOrdered
|
||||
.SelectMany(c => c)
|
||||
.Select(c => new ControlMap
|
||||
{
|
||||
Name = c,
|
||||
IsBool = def.BoolButtons.Contains(c),
|
||||
IsAxis = def.AxisControls.Contains(c)
|
||||
IsBool = _type.BoolButtons.Contains(c),
|
||||
IsAxis = _type.AxisControls.Contains(c)
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
#region IController Implementation
|
||||
|
||||
public ControllerDefinition Definition => _type;
|
||||
|
||||
public bool IsPressed(string button) => _myBoolButtons[button];
|
||||
public float AxisValue(string name) => _myAxisControls[name];
|
||||
|
|
|
@ -9,14 +9,14 @@ namespace BizHawk.Client.Common
|
|||
public class Bk2LogEntryGenerator : ILogEntryGenerator
|
||||
{
|
||||
private readonly string _logKey;
|
||||
private IController _source;
|
||||
private IController _source = NullController.Instance;
|
||||
|
||||
public Bk2LogEntryGenerator(string logKey)
|
||||
{
|
||||
_logKey = logKey;
|
||||
}
|
||||
|
||||
public IMovieController MovieControllerAdapter => new Bk2Controller(_logKey);
|
||||
public IMovieController MovieControllerAdapter => new Bk2Controller(_logKey, _source.Definition);
|
||||
|
||||
public void SetSource(IController source) => _source = source;
|
||||
|
||||
|
@ -56,11 +56,11 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (_source.Definition.BoolButtons.Contains(button))
|
||||
{
|
||||
dict.Add(button, Bk2MnemonicConstants.Lookup(button, Global.Emulator.SystemId).ToString());
|
||||
dict.Add(button, Bk2MnemonicLookup.Lookup(button, Global.Emulator.SystemId).ToString());
|
||||
}
|
||||
else if (_source.Definition.AxisControls.Contains(button))
|
||||
{
|
||||
dict.Add(button, Bk2MnemonicConstants.LookupAxis(button, Global.Emulator.SystemId));
|
||||
dict.Add(button, Bk2MnemonicLookup.LookupAxis(button, Global.Emulator.SystemId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
else
|
||||
{
|
||||
sb.Append(_source.IsPressed(button) ? Bk2MnemonicConstants.Lookup(button, Global.Emulator.SystemId) : forInputDisplay ? ' ' : '.');
|
||||
sb.Append(_source.IsPressed(button) ? Bk2MnemonicLookup.Lookup(button, Global.Emulator.SystemId) : forInputDisplay ? ' ' : '.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,10 +125,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (frame < FrameCount && frame >= 0)
|
||||
{
|
||||
_adapter ??= new Bk2Controller
|
||||
{
|
||||
Definition = Global.MovieSession.MovieControllerAdapter.Definition
|
||||
};
|
||||
_adapter ??= new Bk2Controller(Global.MovieSession.MovieControllerAdapter.Definition);
|
||||
|
||||
int getFrame;
|
||||
|
||||
|
|
|
@ -4,8 +4,6 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public interface IMovieController : IController
|
||||
{
|
||||
new ControllerDefinition Definition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Latches to the given <see cref="IController" />
|
||||
/// </summary>
|
||||
|
|
|
@ -14,6 +14,8 @@ namespace BizHawk.Client.Common
|
|||
IController PreviousFrame { get; }
|
||||
IController CurrentInput { get; }
|
||||
|
||||
void SetMovieController(ControllerDefinition definition);
|
||||
|
||||
bool ReadOnly { get; set; }
|
||||
bool MovieIsQueued { get; }
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ namespace BizHawk.Client.Common
|
|||
if (adapter.Definition.BoolButtons.Contains(buttonName))
|
||||
{
|
||||
return adapter.IsPressed(buttonName)
|
||||
? Bk2MnemonicConstants.Lookup(buttonName, Global.Emulator.SystemId).ToString()
|
||||
? Bk2MnemonicLookup.Lookup(buttonName, Global.Emulator.SystemId).ToString()
|
||||
: "";
|
||||
}
|
||||
|
||||
|
|
|
@ -375,11 +375,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var branch = Tastudio.CurrentTasMovie.Branches.FirstOrDefault(b => b.UniqueIdentifier.ToString() == branchId);
|
||||
if (branch != null && frame < branch.InputLog.Count)
|
||||
{
|
||||
var adapter = new Bk2Controller
|
||||
{
|
||||
Definition = Global.MovieSession.MovieControllerAdapter.Definition
|
||||
};
|
||||
|
||||
var adapter = new Bk2Controller(Global.MovieSession.MovieControllerAdapter.Definition);
|
||||
adapter.SetFromMnemonic(branch.InputLog[frame]);
|
||||
|
||||
foreach (var button in adapter.Definition.BoolButtons)
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
_tools = tools;
|
||||
var lg = movie.LogGeneratorInstance();
|
||||
lg.SetSource(Global.MovieSession.MovieControllerAdapter);
|
||||
_targetController = new Bk2Controller { Definition = _emulator.ControllerDefinition };
|
||||
_targetController = new Bk2Controller(_emulator.ControllerDefinition);
|
||||
_targetController.LatchFrom(_targetController); // Reference and create all buttons
|
||||
|
||||
if (key == "")
|
||||
|
@ -54,7 +54,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
_controller = new Bk2Controller { Definition = d };
|
||||
_controller = new Bk2Controller(d);
|
||||
var logGenerator = new Bk2LogEntryGenerator("");
|
||||
logGenerator.SetSource(_controller);
|
||||
logGenerator.GenerateLogEntry(); // Reference and create all buttons.
|
||||
|
@ -108,7 +108,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
var newController = new Bk2Controller { Definition = d };
|
||||
var newController = new Bk2Controller(d);
|
||||
var logGenerator = new Bk2LogEntryGenerator("");
|
||||
|
||||
logGenerator.SetSource(newController);
|
||||
|
@ -257,10 +257,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
Name = Path.GetFileNameWithoutExtension(fileName);
|
||||
|
||||
// Adapters
|
||||
_targetController = new Bk2Controller { Definition = _emulator.ControllerDefinition };
|
||||
_targetController = new Bk2Controller(_emulator.ControllerDefinition);
|
||||
_targetController.LatchFrom(_targetController); // Reference and create all buttons
|
||||
string[] keys = _inputKey.Split('|');
|
||||
var d = new ControllerDefinition();
|
||||
var d = new ControllerDefinition(_emulator.ControllerDefinition);
|
||||
foreach (var k in keys)
|
||||
{
|
||||
if (_emulator.ControllerDefinition.BoolButtons.Contains(k))
|
||||
|
@ -273,7 +273,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
_controller = new Bk2Controller { Definition = d };
|
||||
_controller = new Bk2Controller(d);
|
||||
}
|
||||
|
||||
#region Custom Latch
|
||||
|
|
Loading…
Reference in New Issue