Cleanup various Hawk cores' controller decks
The main point is referencing types directly instead of iterating them by reflection and also calling their ctors by reflection. (disclaimer: [DisplayName] attrs are still necessarily read by reflection)
This commit is contained in:
parent
329a7de8b8
commit
d170972e3c
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using BizHawk.Emulation.Cores.Atari.A7800Hawk;
|
||||
|
||||
|
@ -22,9 +21,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void IntvControllerSettings_Load(object sender, EventArgs e)
|
||||
{
|
||||
var possibleControllers = A7800HawkControllerDeck.ValidControllerTypes.Select(t => t.Key);
|
||||
|
||||
foreach (var val in possibleControllers)
|
||||
foreach (var val in A7800HawkControllerDeck.ControllerCtors.Keys)
|
||||
{
|
||||
Port1ComboBox.Items.Add(val);
|
||||
Port2ComboBox.Items.Add(val);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using BizHawk.Emulation.Cores.ColecoVision;
|
||||
|
||||
|
@ -22,9 +21,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void ColecoControllerSettings_Load(object sender, EventArgs e)
|
||||
{
|
||||
var possibleControllers = ColecoVisionControllerDeck.ValidControllerTypes.Select(t => t.Key);
|
||||
|
||||
foreach (var val in possibleControllers)
|
||||
foreach (var val in ColecoVisionControllerDeck.ControllerCtors.Keys)
|
||||
{
|
||||
Port1ComboBox.Items.Add(val);
|
||||
Port2ComboBox.Items.Add(val);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using BizHawk.Emulation.Cores.Intellivision;
|
||||
|
||||
|
@ -22,9 +21,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void IntvControllerSettings_Load(object sender, EventArgs e)
|
||||
{
|
||||
var possibleControllers = IntellivisionControllerDeck.ValidControllerTypes.Select(t => t.Key);
|
||||
|
||||
foreach (var val in possibleControllers)
|
||||
foreach (var val in IntellivisionControllerDeck.ControllerCtors.Keys)
|
||||
{
|
||||
Port1ComboBox.Items.Add(val);
|
||||
Port2ComboBox.Items.Add(val);
|
||||
|
|
|
@ -3,27 +3,17 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.ReflectionExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
||||
{
|
||||
public class Atari2600ControllerDeck
|
||||
{
|
||||
private static readonly Type[] Implementors =
|
||||
{
|
||||
typeof(UnpluggedController), // Order must match Atari2600ControllerTypes enum values
|
||||
typeof(StandardController),
|
||||
typeof(PaddleController),
|
||||
typeof(BoostGripController),
|
||||
typeof(DrivingController),
|
||||
typeof(KeyboardController)
|
||||
};
|
||||
|
||||
public Atari2600ControllerDeck(Atari2600ControllerTypes controller1, Atari2600ControllerTypes controller2)
|
||||
{
|
||||
Port1 = (IPort)Activator.CreateInstance(Implementors[(int)controller1], 1);
|
||||
Port2 = (IPort)Activator.CreateInstance(Implementors[(int)controller2], 2);
|
||||
Port1 = ControllerCtors[controller1](1);
|
||||
Port2 = ControllerCtors[controller1](2);
|
||||
|
||||
Definition = new ControllerDefinition
|
||||
{
|
||||
|
@ -77,24 +67,17 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
private readonly IPort Port1;
|
||||
private readonly IPort Port2;
|
||||
|
||||
private static Dictionary<string, Type> _controllerTypes;
|
||||
private static IReadOnlyDictionary<Atari2600ControllerTypes, Func<int, IPort>> _controllerCtors;
|
||||
|
||||
public static Dictionary<string, Type> ValidControllerTypes
|
||||
{
|
||||
get
|
||||
public static IReadOnlyDictionary<Atari2600ControllerTypes, Func<int, IPort>> ControllerCtors => _controllerCtors
|
||||
??= new Dictionary<Atari2600ControllerTypes, Func<int, IPort>>
|
||||
{
|
||||
if (_controllerTypes == null)
|
||||
{
|
||||
_controllerTypes = Emulation.Cores.ReflectionCache.Types
|
||||
.Where(t => typeof(IPort).IsAssignableFrom(t))
|
||||
.Where(t => !t.IsAbstract && !t.IsInterface)
|
||||
.ToDictionary(tkey => tkey.DisplayName());
|
||||
}
|
||||
|
||||
return _controllerTypes;
|
||||
}
|
||||
}
|
||||
|
||||
public static string DefaultControllerName => typeof(StandardController).DisplayName();
|
||||
[Atari2600ControllerTypes.Unplugged] = portNum => new UnpluggedController(portNum),
|
||||
[Atari2600ControllerTypes.Joystick] = portNum => new StandardController(portNum),
|
||||
[Atari2600ControllerTypes.Paddle] = portNum => new PaddleController(portNum),
|
||||
[Atari2600ControllerTypes.BoostGrip] = portNum => new BoostGripController(portNum),
|
||||
[Atari2600ControllerTypes.Driving] = portNum => new DrivingController(portNum),
|
||||
[Atari2600ControllerTypes.Keyboard] = portNum => new KeyboardController(portNum)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk
|
|||
get => _port1;
|
||||
set
|
||||
{
|
||||
if (!A7800HawkControllerDeck.ValidControllerTypes.ContainsKey(value))
|
||||
if (!A7800HawkControllerDeck.ControllerCtors.ContainsKey(value))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + value);
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk
|
|||
get => _port2;
|
||||
set
|
||||
{
|
||||
if (!A7800HawkControllerDeck.ValidControllerTypes.ContainsKey(value))
|
||||
if (!A7800HawkControllerDeck.ControllerCtors.ContainsKey(value))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + value);
|
||||
}
|
||||
|
|
|
@ -12,18 +12,12 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk
|
|||
{
|
||||
public A7800HawkControllerDeck(string controller1Name, string controller2Name)
|
||||
{
|
||||
if (!ValidControllerTypes.ContainsKey(controller1Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller1Name);
|
||||
}
|
||||
|
||||
if (!ValidControllerTypes.ContainsKey(controller2Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller2Name);
|
||||
}
|
||||
|
||||
Port1 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller1Name], 1);
|
||||
Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2);
|
||||
Port1 = ControllerCtors.TryGetValue(controller1Name, out var ctor1)
|
||||
? ctor1(1)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller1Name}");
|
||||
Port2 = ControllerCtors.TryGetValue(controller2Name, out var ctor2)
|
||||
? ctor2(2)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller2Name}");
|
||||
|
||||
Definition = new ControllerDefinition
|
||||
{
|
||||
|
@ -113,23 +107,16 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk
|
|||
private readonly IPort Port1;
|
||||
private readonly IPort Port2;
|
||||
|
||||
private static Dictionary<string, Type> _controllerTypes;
|
||||
private static IReadOnlyDictionary<string, Func<int, IPort>> _controllerCtors;
|
||||
|
||||
public static Dictionary<string, Type> ValidControllerTypes
|
||||
{
|
||||
get
|
||||
public static IReadOnlyDictionary<string, Func<int, IPort>> ControllerCtors => _controllerCtors
|
||||
??= new Dictionary<string, Func<int, IPort>>
|
||||
{
|
||||
if (_controllerTypes == null)
|
||||
{
|
||||
_controllerTypes = Emulation.Cores.ReflectionCache.Types
|
||||
.Where(t => typeof(IPort).IsAssignableFrom(t))
|
||||
.Where(t => !t.IsAbstract && !t.IsInterface)
|
||||
.ToDictionary(tkey => tkey.DisplayName());
|
||||
}
|
||||
|
||||
return _controllerTypes;
|
||||
}
|
||||
}
|
||||
[typeof(UnpluggedController).DisplayName()] = portNum => new UnpluggedController(portNum),
|
||||
[typeof(StandardController).DisplayName()] = portNum => new StandardController(portNum),
|
||||
[typeof(ProLineController).DisplayName()] = portNum => new ProLineController(portNum),
|
||||
[typeof(LightGunController).DisplayName()] = portNum => new LightGunController(portNum)
|
||||
};
|
||||
|
||||
public static string DefaultControllerName => typeof(StandardController).DisplayName();
|
||||
}
|
||||
|
|
|
@ -12,18 +12,12 @@ namespace BizHawk.Emulation.Cores.ColecoVision
|
|||
{
|
||||
public ColecoVisionControllerDeck(string controller1Name, string controller2Name)
|
||||
{
|
||||
if (!ValidControllerTypes.ContainsKey(controller1Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller1Name);
|
||||
}
|
||||
|
||||
if (!ValidControllerTypes.ContainsKey(controller2Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller2Name);
|
||||
}
|
||||
|
||||
Port1 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller1Name], 1);
|
||||
Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2);
|
||||
Port1 = ControllerCtors.TryGetValue(controller1Name, out var ctor1)
|
||||
? ctor1(1)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller1Name}");
|
||||
Port2 = ControllerCtors.TryGetValue(controller2Name, out var ctor2)
|
||||
? ctor2(2)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller2Name}");
|
||||
|
||||
Definition = new ControllerDefinition
|
||||
{
|
||||
|
@ -79,23 +73,16 @@ namespace BizHawk.Emulation.Cores.ColecoVision
|
|||
public IPort Port1 { get; }
|
||||
public IPort Port2 { get; }
|
||||
|
||||
private static Dictionary<string, Type> _controllerTypes = null;
|
||||
private static IReadOnlyDictionary<string, Func<int, IPort>> _controllerCtors;
|
||||
|
||||
public static Dictionary<string, Type> ValidControllerTypes
|
||||
{
|
||||
get
|
||||
public static IReadOnlyDictionary<string, Func<int, IPort>> ControllerCtors => _controllerCtors
|
||||
??= new Dictionary<string, Func<int, IPort>>
|
||||
{
|
||||
if (_controllerTypes == null)
|
||||
{
|
||||
_controllerTypes = Emulation.Cores.ReflectionCache.Types
|
||||
.Where(t => typeof(IPort).IsAssignableFrom(t))
|
||||
.Where(t => !t.IsAbstract && !t.IsInterface)
|
||||
.ToDictionary(tkey => tkey.DisplayName());
|
||||
}
|
||||
|
||||
return _controllerTypes;
|
||||
}
|
||||
}
|
||||
[typeof(UnpluggedController).DisplayName()] = portNum => new UnpluggedController(portNum),
|
||||
[typeof(StandardController).DisplayName()] = portNum => new StandardController(portNum),
|
||||
[typeof(ColecoTurboController).DisplayName()] = portNum => new ColecoTurboController(portNum),
|
||||
[typeof(ColecoSuperActionController).DisplayName()] = portNum => new ColecoSuperActionController(portNum)
|
||||
};
|
||||
|
||||
public static string DefaultControllerName => typeof(StandardController).DisplayName();
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
|
|||
get => _port1;
|
||||
set
|
||||
{
|
||||
if (!ColecoVisionControllerDeck.ValidControllerTypes.ContainsKey(value))
|
||||
if (!ColecoVisionControllerDeck.ControllerCtors.ContainsKey(value))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + value);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
|
|||
get => _port2;
|
||||
set
|
||||
{
|
||||
if (!ColecoVisionControllerDeck.ValidControllerTypes.ContainsKey(value))
|
||||
if (!ColecoVisionControllerDeck.ControllerCtors.ContainsKey(value))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + value);
|
||||
}
|
||||
|
|
|
@ -12,18 +12,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
|
|||
{
|
||||
public VectrexHawkControllerDeck(string controller1Name, string controller2Name)
|
||||
{
|
||||
if (!ValidControllerTypes.ContainsKey(controller1Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller1Name);
|
||||
}
|
||||
|
||||
if (!ValidControllerTypes.ContainsKey(controller2Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller2Name);
|
||||
}
|
||||
|
||||
Port1 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller1Name], 1);
|
||||
Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2);
|
||||
Port1 = ControllerCtors.TryGetValue(controller1Name, out var ctor1)
|
||||
? ctor1(1)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller1Name}");
|
||||
Port2 = ControllerCtors.TryGetValue(controller2Name, out var ctor2)
|
||||
? ctor2(2)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller2Name}");
|
||||
|
||||
Definition = new ControllerDefinition
|
||||
{
|
||||
|
@ -68,23 +62,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
|
|||
private readonly IPort Port1;
|
||||
private readonly IPort Port2;
|
||||
|
||||
private static Dictionary<string, Type> _controllerTypes;
|
||||
private static IReadOnlyDictionary<string, Func<int, IPort>> _controllerCtors;
|
||||
|
||||
public static Dictionary<string, Type> ValidControllerTypes
|
||||
{
|
||||
get
|
||||
public static IReadOnlyDictionary<string, Func<int, IPort>> ControllerCtors => _controllerCtors
|
||||
??= new Dictionary<string, Func<int, IPort>>
|
||||
{
|
||||
if (_controllerTypes == null)
|
||||
{
|
||||
_controllerTypes = Emulation.Cores.ReflectionCache.Types
|
||||
.Where(t => typeof(IPort).IsAssignableFrom(t))
|
||||
.Where(t => !t.IsAbstract && !t.IsInterface)
|
||||
.ToDictionary(tkey => tkey.DisplayName());
|
||||
}
|
||||
|
||||
return _controllerTypes;
|
||||
}
|
||||
}
|
||||
[typeof(StandardControls).DisplayName()] = portNum => new StandardControls(portNum),
|
||||
[typeof(AnalogControls).DisplayName()] = portNum => new AnalogControls(portNum)
|
||||
};
|
||||
|
||||
public static string DefaultControllerName => typeof(StandardControls).DisplayName();
|
||||
}
|
||||
|
|
|
@ -12,18 +12,12 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
{
|
||||
public IntellivisionControllerDeck(string controller1Name, string controller2Name)
|
||||
{
|
||||
if (!ValidControllerTypes.ContainsKey(controller1Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller1Name);
|
||||
}
|
||||
|
||||
if (!ValidControllerTypes.ContainsKey(controller2Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller2Name);
|
||||
}
|
||||
|
||||
Port1 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller1Name], 1);
|
||||
Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2);
|
||||
Port1 = ControllerCtors.TryGetValue(controller1Name, out var ctor1)
|
||||
? ctor1(1)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller1Name}");
|
||||
Port2 = ControllerCtors.TryGetValue(controller2Name, out var ctor2)
|
||||
? ctor2(2)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller2Name}");
|
||||
|
||||
Definition = new ControllerDefinition
|
||||
{
|
||||
|
@ -68,23 +62,15 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
private readonly IPort Port1;
|
||||
private readonly IPort Port2;
|
||||
|
||||
private static Dictionary<string, Type> _controllerTypes;
|
||||
private static IReadOnlyDictionary<string, Func<int, IPort>> _controllerCtors;
|
||||
|
||||
public static Dictionary<string, Type> ValidControllerTypes
|
||||
{
|
||||
get
|
||||
public static IReadOnlyDictionary<string, Func<int, IPort>> ControllerCtors => _controllerCtors
|
||||
??= new Dictionary<string, Func<int, IPort>>
|
||||
{
|
||||
if (_controllerTypes == null)
|
||||
{
|
||||
_controllerTypes = Emulation.Cores.ReflectionCache.Types
|
||||
.Where(t => typeof(IPort).IsAssignableFrom(t))
|
||||
.Where(t => !t.IsAbstract && !t.IsInterface)
|
||||
.ToDictionary(tkey => tkey.DisplayName());
|
||||
}
|
||||
|
||||
return _controllerTypes;
|
||||
}
|
||||
}
|
||||
[typeof(UnpluggedController).DisplayName()] = portNum => new UnpluggedController(portNum),
|
||||
[typeof(StandardController).DisplayName()] = portNum => new StandardController(portNum),
|
||||
[typeof(FakeAnalogController).DisplayName()] = portNum => new FakeAnalogController(portNum)
|
||||
};
|
||||
|
||||
public static string DefaultControllerName => typeof(FakeAnalogController).DisplayName();
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
get => _port1;
|
||||
set
|
||||
{
|
||||
if (!IntellivisionControllerDeck.ValidControllerTypes.ContainsKey(value))
|
||||
if (!IntellivisionControllerDeck.ControllerCtors.ContainsKey(value))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + value);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
get => _port2;
|
||||
set
|
||||
{
|
||||
if (!IntellivisionControllerDeck.ValidControllerTypes.ContainsKey(value))
|
||||
if (!IntellivisionControllerDeck.ControllerCtors.ContainsKey(value))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + value);
|
||||
}
|
||||
|
|
|
@ -12,18 +12,12 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
|
|||
{
|
||||
public O2HawkControllerDeck(string controller1Name, string controller2Name, bool is_G7400)
|
||||
{
|
||||
if (!ValidControllerTypes.ContainsKey(controller1Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller1Name);
|
||||
}
|
||||
|
||||
if (!ValidControllerTypes.ContainsKey(controller2Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller2Name);
|
||||
}
|
||||
|
||||
Port1 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller1Name], 1);
|
||||
Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2);
|
||||
Port1 = ControllerCtors.TryGetValue(controller1Name, out var ctor1)
|
||||
? ctor1(1)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller1Name}");
|
||||
Port2 = ControllerCtors.TryGetValue(controller2Name, out var ctor2)
|
||||
? ctor2(2)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller2Name}");
|
||||
|
||||
if (is_G7400)
|
||||
{
|
||||
|
@ -94,23 +88,13 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
|
|||
|
||||
private readonly IPort Port1, Port2;
|
||||
|
||||
private static Dictionary<string, Type> _controllerTypes;
|
||||
private static IReadOnlyDictionary<string, Func<int, IPort>> _controllerCtors;
|
||||
|
||||
public static Dictionary<string, Type> ValidControllerTypes
|
||||
{
|
||||
get
|
||||
public static IReadOnlyDictionary<string, Func<int, IPort>> ControllerCtors => _controllerCtors
|
||||
??= new Dictionary<string, Func<int, IPort>>
|
||||
{
|
||||
if (_controllerTypes == null)
|
||||
{
|
||||
_controllerTypes = Emulation.Cores.ReflectionCache.Types
|
||||
.Where(t => typeof(IPort).IsAssignableFrom(t))
|
||||
.Where(t => !t.IsAbstract && !t.IsInterface)
|
||||
.ToDictionary(tkey => tkey.DisplayName());
|
||||
}
|
||||
|
||||
return _controllerTypes;
|
||||
}
|
||||
}
|
||||
[typeof(StandardControls).DisplayName()] = portNum => new StandardControls(portNum)
|
||||
};
|
||||
|
||||
public static string DefaultControllerName => typeof(StandardControls).DisplayName();
|
||||
}
|
||||
|
|
|
@ -12,12 +12,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
{
|
||||
public GBHawkControllerDeck(string controller1Name)
|
||||
{
|
||||
if (!ValidControllerTypes.ContainsKey(controller1Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller1Name);
|
||||
}
|
||||
|
||||
Port1 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller1Name], 1);
|
||||
Port1 = ControllerCtors.TryGetValue(controller1Name, out var ctor1)
|
||||
? ctor1(1)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller1Name}");
|
||||
|
||||
Definition = new ControllerDefinition
|
||||
{
|
||||
|
@ -55,23 +52,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
|
||||
private readonly IPort Port1;
|
||||
|
||||
private static Dictionary<string, Type> _controllerTypes;
|
||||
private static IReadOnlyDictionary<string, Func<int, IPort>> _controllerCtors;
|
||||
|
||||
public static Dictionary<string, Type> ValidControllerTypes
|
||||
{
|
||||
get
|
||||
public static IReadOnlyDictionary<string, Func<int, IPort>> ControllerCtors => _controllerCtors
|
||||
??= new Dictionary<string, Func<int, IPort>>
|
||||
{
|
||||
if (_controllerTypes == null)
|
||||
{
|
||||
_controllerTypes = Emulation.Cores.ReflectionCache.Types
|
||||
.Where(t => typeof(IPort).IsAssignableFrom(t))
|
||||
.Where(t => !t.IsAbstract && !t.IsInterface)
|
||||
.ToDictionary(tkey => tkey.DisplayName());
|
||||
}
|
||||
|
||||
return _controllerTypes;
|
||||
}
|
||||
}
|
||||
[typeof(StandardControls).DisplayName()] = portNum => new StandardControls(portNum),
|
||||
[typeof(StandardTilt).DisplayName()] = portNum => new StandardTilt(portNum)
|
||||
};
|
||||
|
||||
public static string DefaultControllerName => typeof(StandardControls).DisplayName();
|
||||
}
|
||||
|
|
|
@ -12,18 +12,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink
|
|||
{
|
||||
public GBHawkLinkControllerDeck(string controller1Name, string controller2Name)
|
||||
{
|
||||
if (!ValidControllerTypes.ContainsKey(controller1Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller1Name);
|
||||
}
|
||||
|
||||
if (!ValidControllerTypes.ContainsKey(controller2Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller2Name);
|
||||
}
|
||||
|
||||
Port1 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller1Name], 1);
|
||||
Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2);
|
||||
Port1 = ControllerCtors.TryGetValue(controller1Name, out var ctor1)
|
||||
? ctor1(1)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller1Name}");
|
||||
Port2 = ControllerCtors.TryGetValue(controller2Name, out var ctor2)
|
||||
? ctor2(2)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller2Name}");
|
||||
|
||||
Definition = new ControllerDefinition
|
||||
{
|
||||
|
@ -61,23 +55,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink
|
|||
private readonly IPort Port1;
|
||||
private readonly IPort Port2;
|
||||
|
||||
private static Dictionary<string, Type> _controllerTypes;
|
||||
private static IReadOnlyDictionary<string, Func<int, IPort>> _controllerCtors;
|
||||
|
||||
public static Dictionary<string, Type> ValidControllerTypes
|
||||
{
|
||||
get
|
||||
public static IReadOnlyDictionary<string, Func<int, IPort>> ControllerCtors => _controllerCtors
|
||||
??= new Dictionary<string, Func<int, IPort>>
|
||||
{
|
||||
if (_controllerTypes == null)
|
||||
{
|
||||
_controllerTypes = Emulation.Cores.ReflectionCache.Types
|
||||
.Where(t => typeof(IPort).IsAssignableFrom(t))
|
||||
.Where(t => !t.IsAbstract && !t.IsInterface)
|
||||
.ToDictionary(tkey => tkey.DisplayName());
|
||||
}
|
||||
|
||||
return _controllerTypes;
|
||||
}
|
||||
}
|
||||
[typeof(StandardControls).DisplayName()] = portNum => new StandardControls(portNum)
|
||||
};
|
||||
|
||||
public static string DefaultControllerName => typeof(StandardControls).DisplayName();
|
||||
}
|
||||
|
|
|
@ -12,24 +12,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
|
|||
{
|
||||
public GBHawkLink3xControllerDeck(string controller1Name, string controller2Name, string controller3Name)
|
||||
{
|
||||
if (!ValidControllerTypes.ContainsKey(controller1Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller1Name);
|
||||
}
|
||||
|
||||
if (!ValidControllerTypes.ContainsKey(controller2Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller2Name);
|
||||
}
|
||||
|
||||
if (!ValidControllerTypes.ContainsKey(controller3Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller3Name);
|
||||
}
|
||||
|
||||
Port1 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller1Name], 1);
|
||||
Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2);
|
||||
Port3 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller3Name], 3);
|
||||
Port1 = ControllerCtors.TryGetValue(controller1Name, out var ctor1)
|
||||
? ctor1(1)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller1Name}");
|
||||
Port2 = ControllerCtors.TryGetValue(controller2Name, out var ctor2)
|
||||
? ctor2(2)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller2Name}");
|
||||
Port3 = ControllerCtors.TryGetValue(controller3Name, out var ctor3)
|
||||
? ctor3(3)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller3Name}");
|
||||
|
||||
Definition = new ControllerDefinition
|
||||
{
|
||||
|
@ -80,23 +71,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
|
|||
private readonly IPort Port2;
|
||||
private readonly IPort Port3;
|
||||
|
||||
private static Dictionary<string, Type> _controllerTypes;
|
||||
private static IReadOnlyDictionary<string, Func<int, IPort>> _controllerCtors;
|
||||
|
||||
public static Dictionary<string, Type> ValidControllerTypes
|
||||
{
|
||||
get
|
||||
public static IReadOnlyDictionary<string, Func<int, IPort>> ControllerCtors => _controllerCtors
|
||||
??= new Dictionary<string, Func<int, IPort>>
|
||||
{
|
||||
if (_controllerTypes == null)
|
||||
{
|
||||
_controllerTypes = Emulation.Cores.ReflectionCache.Types
|
||||
.Where(t => typeof(IPort).IsAssignableFrom(t))
|
||||
.Where(t => !t.IsAbstract && !t.IsInterface)
|
||||
.ToDictionary(tkey => tkey.DisplayName());
|
||||
}
|
||||
|
||||
return _controllerTypes;
|
||||
}
|
||||
}
|
||||
[typeof(StandardControls).DisplayName()] = portNum => new StandardControls(portNum)
|
||||
};
|
||||
|
||||
public static string DefaultControllerName => typeof(StandardControls).DisplayName();
|
||||
}
|
||||
|
|
|
@ -12,30 +12,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x
|
|||
{
|
||||
public GBHawkLink4xControllerDeck(string controller1Name, string controller2Name, string controller3Name, string controller4Name)
|
||||
{
|
||||
if (!ValidControllerTypes.ContainsKey(controller1Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller1Name);
|
||||
}
|
||||
|
||||
if (!ValidControllerTypes.ContainsKey(controller2Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller2Name);
|
||||
}
|
||||
|
||||
if (!ValidControllerTypes.ContainsKey(controller3Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller3Name);
|
||||
}
|
||||
|
||||
if (!ValidControllerTypes.ContainsKey(controller4Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller4Name);
|
||||
}
|
||||
|
||||
Port1 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller1Name], 1);
|
||||
Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2);
|
||||
Port3 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller3Name], 3);
|
||||
Port4 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller3Name], 4);
|
||||
Port1 = ControllerCtors.TryGetValue(controller1Name, out var ctor1)
|
||||
? ctor1(1)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller1Name}");
|
||||
Port2 = ControllerCtors.TryGetValue(controller2Name, out var ctor2)
|
||||
? ctor2(2)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller2Name}");
|
||||
Port3 = ControllerCtors.TryGetValue(controller3Name, out var ctor3)
|
||||
? ctor3(3)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller3Name}");
|
||||
Port4 = ControllerCtors.TryGetValue(controller4Name, out var ctor4)
|
||||
? ctor4(4)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller4Name}");
|
||||
|
||||
Definition = new ControllerDefinition
|
||||
{
|
||||
|
@ -98,23 +86,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x
|
|||
private readonly IPort Port3;
|
||||
private readonly IPort Port4;
|
||||
|
||||
private static Dictionary<string, Type> _controllerTypes;
|
||||
private static IReadOnlyDictionary<string, Func<int, IPort>> _controllerCtors;
|
||||
|
||||
public static Dictionary<string, Type> ValidControllerTypes
|
||||
{
|
||||
get
|
||||
public static IReadOnlyDictionary<string, Func<int, IPort>> ControllerCtors => _controllerCtors
|
||||
??= new Dictionary<string, Func<int, IPort>>
|
||||
{
|
||||
if (_controllerTypes == null)
|
||||
{
|
||||
_controllerTypes = Emulation.Cores.ReflectionCache.Types
|
||||
.Where(t => typeof(IPort).IsAssignableFrom(t))
|
||||
.Where(t => !t.IsAbstract && !t.IsInterface)
|
||||
.ToDictionary(tkey => tkey.DisplayName());
|
||||
}
|
||||
|
||||
return _controllerTypes;
|
||||
}
|
||||
}
|
||||
[typeof(StandardControls).DisplayName()] = portNum => new StandardControls(portNum)
|
||||
};
|
||||
|
||||
public static string DefaultControllerName => typeof(StandardControls).DisplayName();
|
||||
}
|
||||
|
|
|
@ -12,18 +12,12 @@ namespace BizHawk.Emulation.Cores.Sega.GGHawkLink
|
|||
{
|
||||
public GGHawkLinkControllerDeck(string controller1Name, string controller2Name)
|
||||
{
|
||||
if (!ValidControllerTypes.ContainsKey(controller1Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller1Name);
|
||||
}
|
||||
|
||||
if (!ValidControllerTypes.ContainsKey(controller2Name))
|
||||
{
|
||||
throw new InvalidOperationException("Invalid controller type: " + controller2Name);
|
||||
}
|
||||
|
||||
Port1 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller1Name], 1);
|
||||
Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2);
|
||||
Port1 = ControllerCtors.TryGetValue(controller1Name, out var ctor1)
|
||||
? ctor1(1)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller1Name}");
|
||||
Port2 = ControllerCtors.TryGetValue(controller2Name, out var ctor2)
|
||||
? ctor2(2)
|
||||
: throw new InvalidOperationException($"Invalid controller type: {controller2Name}");
|
||||
|
||||
Definition = new ControllerDefinition
|
||||
{
|
||||
|
@ -61,23 +55,13 @@ namespace BizHawk.Emulation.Cores.Sega.GGHawkLink
|
|||
private readonly IPort Port1;
|
||||
private readonly IPort Port2;
|
||||
|
||||
private static Dictionary<string, Type> _controllerTypes;
|
||||
private static IReadOnlyDictionary<string, Func<int, IPort>> _controllerCtors;
|
||||
|
||||
public static Dictionary<string, Type> ValidControllerTypes
|
||||
{
|
||||
get
|
||||
public static IReadOnlyDictionary<string, Func<int, IPort>> ControllerCtors => _controllerCtors
|
||||
??= new Dictionary<string, Func<int, IPort>>
|
||||
{
|
||||
if (_controllerTypes == null)
|
||||
{
|
||||
_controllerTypes = Emulation.Cores.ReflectionCache.Types
|
||||
.Where(t => typeof(IPort).IsAssignableFrom(t))
|
||||
.Where(t => !t.IsAbstract && !t.IsInterface)
|
||||
.ToDictionary(tkey => tkey.DisplayName());
|
||||
}
|
||||
|
||||
return _controllerTypes;
|
||||
}
|
||||
}
|
||||
[typeof(StandardControls).DisplayName()] = portNum => new StandardControls(portNum)
|
||||
};
|
||||
|
||||
public static string DefaultControllerName => typeof(StandardControls).DisplayName();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue