Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow matching xinput santroller devices on their santroller device type and rhythm type #4

Merged
merged 4 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@ public class SantrollerXInputFiveLaneDrumkit : XInputFiveLaneDrumkit
/// </summary>
internal new static void Initialize()
{
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
// 4-lane kits and 5-lane kits share the same subtype, they need to be differentiated in another way
// 5-lane kits always hold the left-stick click input, 4-lane kits use that for the second kick but
// realistically that isn't likely to be held when powering on
XInputLayoutFinder.RegisterLayout<SantrollerXInputFiveLaneDrumkit>(XInputController.DeviceSubType.DrumKit,
(state) => (state.buttons & (ushort)XInputGamepad.Button.LeftThumb) != 0,
SantrollerLayoutFinder.GetXInputMatcher((int)XInputController.DeviceSubType.DrumKit)
);
#endif
SantrollerLayoutFinder.RegisterXInputLayout<SantrollerXInputFiveLaneDrumkit>(SantrollerDeviceType.Drums, SantrollerRhythmType.GuitarHero);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class SantrollerXInputFourLaneDrumkit : XInputFourLaneDrumkit
/// </summary>
internal new static void Initialize()
{
SantrollerLayoutFinder.RegisterXInputLayout<SantrollerXInputFourLaneDrumkit>(XInputController.DeviceSubType.DrumKit);
SantrollerLayoutFinder.RegisterXInputLayout<SantrollerXInputFourLaneDrumkit>(SantrollerDeviceType.Drums, SantrollerRhythmType.RockBand);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ internal static void RegisterXInputLayout<TDevice>(int subType)
#endif
}

/// <summary>
/// Registers <typeparamref name="TDevice"/> to the input system as an XInput Santroller device using the specified device type and rhythm type.
/// </summary>
internal static void RegisterXInputLayout<TDevice>(SantrollerDeviceType deviceType, SantrollerRhythmType rhythmType)
where TDevice : InputDevice
{
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
InputSystem.RegisterLayout<TDevice>(matches: GetXInputMatcher(deviceType, rhythmType));
#endif
}

/// <summary>
/// Gets a matcher that matches XInput Santroller devices with the given subtype.
/// </summary>
Expand All @@ -150,5 +161,18 @@ internal static InputDeviceMatcher GetXInputMatcher(int subType)
.WithCapability("gamepad/leftStickX", (int)VendorID)
.WithCapability("gamepad/leftStickY", (int)ProductID);
}

/// <summary>
/// Gets a matcher that matches XInput Santroller devices with the given device type and rhythm type.
/// </summary>
internal static InputDeviceMatcher GetXInputMatcher(SantrollerDeviceType deviceType, SantrollerRhythmType rhythmType)
{
int revision = (((int)deviceType) << 8) | (((int)rhythmType) << 4);
return new InputDeviceMatcher()
.WithInterface(XInputLayoutFinder.InterfaceName)
.WithCapability("gamepad/leftStickX", (int)VendorID)
.WithCapability("gamepad/leftStickY", (int)ProductID)
.WithCapability("gamepad/rightStickX", revision);
}
}
}