Pass global InputManager to JoypadApi via ctor
This commit is contained in:
parent
8ad3ea9cc6
commit
85d4d5ed4d
|
@ -24,7 +24,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private static readonly Type[] _ctorParamTypesB = { typeof(Action<string>), typeof(IMainFormForApi) };
|
private static readonly Type[] _ctorParamTypesB = { typeof(Action<string>), typeof(IMainFormForApi) };
|
||||||
|
|
||||||
private static readonly Type[] _ctorParamTypesC = { typeof(Action<string>), typeof(IMovieSession) };
|
private static readonly Type[] _ctorParamTypesC = { typeof(Action<string>), typeof(InputManager), typeof(IMovieSession) };
|
||||||
|
|
||||||
private static readonly Type[] _ctorParamTypesD = { typeof(Action<string>), typeof(IMainFormForApi), typeof(DisplayManager), typeof(InputManager), typeof(Config), typeof(IEmulator), typeof(IGameInfo) };
|
private static readonly Type[] _ctorParamTypesD = { typeof(Action<string>), typeof(IMainFormForApi), typeof(DisplayManager), typeof(InputManager), typeof(Config), typeof(IEmulator), typeof(IGameInfo) };
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
t => _apiTypes[t],
|
t => _apiTypes[t],
|
||||||
t => (IExternalApi) (
|
t => (IExternalApi) (
|
||||||
t.GetConstructor(_ctorParamTypesD)?.Invoke(new object[] { logCallback, mainForm, displayManager, inputManager, config, emulator, game })
|
t.GetConstructor(_ctorParamTypesD)?.Invoke(new object[] { logCallback, mainForm, displayManager, inputManager, config, emulator, game })
|
||||||
?? t.GetConstructor(_ctorParamTypesC)?.Invoke(new object[] { logCallback, movieSession })
|
?? t.GetConstructor(_ctorParamTypesC)?.Invoke(new object[] { logCallback, inputManager, movieSession })
|
||||||
?? t.GetConstructor(_ctorParamTypesB)?.Invoke(new object[] { logCallback, mainForm })
|
?? t.GetConstructor(_ctorParamTypesB)?.Invoke(new object[] { logCallback, mainForm })
|
||||||
?? t.GetConstructor(_ctorParamTypesA)?.Invoke(new object[] { logCallback })
|
?? t.GetConstructor(_ctorParamTypesA)?.Invoke(new object[] { logCallback })
|
||||||
?? t.GetConstructor(_ctorParamTypesTools)?.Invoke(new object[] { toolManager })
|
?? t.GetConstructor(_ctorParamTypesTools)?.Invoke(new object[] { toolManager })
|
||||||
|
|
|
@ -7,24 +7,27 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
public sealed class JoypadApi : IJoypadApi
|
public sealed class JoypadApi : IJoypadApi
|
||||||
{
|
{
|
||||||
|
private readonly InputManager _inputManager;
|
||||||
|
|
||||||
private readonly IMovieSession _movieSession;
|
private readonly IMovieSession _movieSession;
|
||||||
|
|
||||||
private readonly Action<string> LogCallback;
|
private readonly Action<string> LogCallback;
|
||||||
|
|
||||||
public JoypadApi(Action<string> logCallback, IMovieSession movieSession)
|
public JoypadApi(Action<string> logCallback, InputManager inputManager, IMovieSession movieSession)
|
||||||
{
|
{
|
||||||
LogCallback = logCallback;
|
LogCallback = logCallback;
|
||||||
|
_inputManager = inputManager;
|
||||||
_movieSession = movieSession;
|
_movieSession = movieSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDictionary<string, object> Get(int? controller = null)
|
public IDictionary<string, object> Get(int? controller = null)
|
||||||
{
|
{
|
||||||
return GlobalWin.InputManager.AutofireStickyXorAdapter.ToDictionary(controller);
|
return _inputManager.AutofireStickyXorAdapter.ToDictionary(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDictionary<string, object> GetImmediate(int? controller = null)
|
public IDictionary<string, object> GetImmediate(int? controller = null)
|
||||||
{
|
{
|
||||||
return GlobalWin.InputManager.ActiveController.ToDictionary(controller);
|
return _inputManager.ActiveController.ToDictionary(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetFromMnemonicStr(string inputLogEntry)
|
public void SetFromMnemonicStr(string inputLogEntry)
|
||||||
|
@ -39,15 +42,15 @@ namespace BizHawk.Client.EmuHawk
|
||||||
LogCallback($"invalid mnemonic string: {inputLogEntry}");
|
LogCallback($"invalid mnemonic string: {inputLogEntry}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
foreach (var button in controller.Definition.BoolButtons) GlobalWin.InputManager.ButtonOverrideAdapter.SetButton(button, controller.IsPressed(button));
|
foreach (var button in controller.Definition.BoolButtons) _inputManager.ButtonOverrideAdapter.SetButton(button, controller.IsPressed(button));
|
||||||
foreach (var axis in controller.Definition.Axes.Keys) GlobalWin.InputManager.ButtonOverrideAdapter.SetAxis(axis, controller.AxisValue(axis));
|
foreach (var axis in controller.Definition.Axes.Keys) _inputManager.ButtonOverrideAdapter.SetAxis(axis, controller.AxisValue(axis));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Set(IDictionary<string, bool> buttons, int? controller = null)
|
public void Set(IDictionary<string, bool> buttons, int? controller = null)
|
||||||
{
|
{
|
||||||
// If a controller is specified, we need to iterate over unique button names. If not, we iterate over
|
// If a controller is specified, we need to iterate over unique button names. If not, we iterate over
|
||||||
// ALL button names with P{controller} prefixes
|
// ALL button names with P{controller} prefixes
|
||||||
foreach (var button in GlobalWin.InputManager.ActiveController.ToBoolButtonNameList(controller))
|
foreach (var button in _inputManager.ActiveController.ToBoolButtonNameList(controller))
|
||||||
{
|
{
|
||||||
Set(button, buttons.TryGetValue(button, out var state) ? state : (bool?) null, controller);
|
Set(button, buttons.TryGetValue(button, out var state) ? state : (bool?) null, controller);
|
||||||
}
|
}
|
||||||
|
@ -58,9 +61,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var buttonToSet = controller == null ? button : $"P{controller} {button}";
|
var buttonToSet = controller == null ? button : $"P{controller} {button}";
|
||||||
if (state == null) GlobalWin.InputManager.ButtonOverrideAdapter.UnSet(buttonToSet);
|
if (state == null) _inputManager.ButtonOverrideAdapter.UnSet(buttonToSet);
|
||||||
else GlobalWin.InputManager.ButtonOverrideAdapter.SetButton(buttonToSet, state.Value);
|
else _inputManager.ButtonOverrideAdapter.SetButton(buttonToSet, state.Value);
|
||||||
GlobalWin.InputManager.ActiveController.Overrides(GlobalWin.InputManager.ButtonOverrideAdapter);
|
_inputManager.ActiveController.Overrides(_inputManager.ButtonOverrideAdapter);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
@ -77,7 +80,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GlobalWin.InputManager.StickyXorAdapter.SetAxis(controller == null ? control : $"P{controller} {control}", value);
|
_inputManager.StickyXorAdapter.SetAxis(controller == null ? control : $"P{controller} {control}", value);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private readonly Action<string> LogCallback;
|
private readonly Action<string> LogCallback;
|
||||||
|
|
||||||
public MovieApi(Action<string> logCallback, IMovieSession movieSession)
|
public MovieApi(Action<string> logCallback, InputManager inputManager, IMovieSession movieSession)
|
||||||
{
|
{
|
||||||
LogCallback = logCallback;
|
LogCallback = logCallback;
|
||||||
_movieSession = movieSession;
|
_movieSession = movieSession;
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
private readonly IMovieSession _movieSession;
|
private readonly IMovieSession _movieSession;
|
||||||
|
|
||||||
public UserDataApi(Action<string> logCallback, IMovieSession movieSession)
|
public UserDataApi(Action<string> logCallback, InputManager inputManager, IMovieSession movieSession)
|
||||||
{
|
{
|
||||||
_movieSession = movieSession;
|
_movieSession = movieSession;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue