diff --git a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs index 0eb02839de..29268c8f19 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs @@ -113,6 +113,8 @@ namespace BizHawk.Emulation.Common public int Min => Range.Start; + public string PairedAxis => Constraint?.PairedAxis; + public readonly Range Range; public AxisSpec(Range range, int mid, bool isReversed = false, AxisConstraint constraint = null) @@ -164,6 +166,15 @@ namespace BizHawk.Emulation.Common public string PairedAxis { get; } } + public sealed class NoOpAxisConstraint : AxisConstraint + { + public string Class { get; } = null; + + public string PairedAxis { get; } + + public NoOpAxisConstraint(string pairedAxis) => PairedAxis = pairedAxis; + } + public sealed class CircularAxisConstraint : AxisConstraint { public string Class { get; } diff --git a/src/BizHawk.Emulation.Common/Extensions.cs b/src/BizHawk.Emulation.Common/Extensions.cs index afca4013f7..46990dde17 100644 --- a/src/BizHawk.Emulation.Common/Extensions.cs +++ b/src/BizHawk.Emulation.Common/Extensions.cs @@ -420,8 +420,12 @@ namespace BizHawk.Emulation.Common /// format string e.g. "P1 Left {0}" (will be used to interpolate "X" and "Y") /// identical reference to ; the object is mutated public static ControllerDefinition AddXYPair(this ControllerDefinition def, string nameFormat, AxisPairOrientation pDir, Range rangeX, int midX, Range rangeY, int midY, AxisConstraint constraint = null) - => def.AddAxis(string.Format(nameFormat, "X"), rangeX, midX, ((byte) pDir & 2) != 0, constraint) - .AddAxis(string.Format(nameFormat, "Y"), rangeY, midY, ((byte) pDir & 1) != 0); + { + var yAxisName = string.Format(nameFormat, "Y"); + var finalConstraint = constraint ?? new NoOpAxisConstraint(yAxisName); + return def.AddAxis(string.Format(nameFormat, "X"), rangeX, midX, ((byte) pDir & 2) != 0, finalConstraint) + .AddAxis(yAxisName, rangeY, midY, ((byte) pDir & 1) != 0); + } /// /// Adds an X/Y pair of axes to the receiver , and returns it.