Use constraints for grouping, add new class for unconstrained pairs
e.g. for Intellivision `_controllerDeck.Definition.Axes["P1 Disc X"].PairedAxis` gives "P1 Disc Y"
This commit is contained in:
parent
1e67fc1d4b
commit
a0c8f722d2
|
@ -113,6 +113,8 @@ namespace BizHawk.Emulation.Common
|
|||
|
||||
public int Min => Range.Start;
|
||||
|
||||
public string PairedAxis => Constraint?.PairedAxis;
|
||||
|
||||
public readonly Range<int> Range;
|
||||
|
||||
public AxisSpec(Range<int> 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; }
|
||||
|
|
|
@ -420,8 +420,12 @@ namespace BizHawk.Emulation.Common
|
|||
/// <param name="nameFormat">format string e.g. <c>"P1 Left {0}"</c> (will be used to interpolate <c>"X"</c> and <c>"Y"</c>)</param>
|
||||
/// <returns>identical reference to <paramref name="def"/>; the object is mutated</returns>
|
||||
public static ControllerDefinition AddXYPair(this ControllerDefinition def, string nameFormat, AxisPairOrientation pDir, Range<int> rangeX, int midX, Range<int> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an X/Y pair of axes to the receiver <see cref="ControllerDefinition"/>, and returns it.
|
||||
|
|
Loading…
Reference in New Issue