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