fix(input): saved D-pad keeps direction overrides, held directions wait for neutral and Reset regenerates an emptied gamepad

This commit is contained in:
Kurt Himebauch committed 2026-11-18 21:00:31 -05:00
1 parent 952f363b45
commit bf75dfb9c0
7 files changed
+39 -5

No files matched your search

@@ -317,4 +317,4 @@ internal fun InputAction.validFor(element: InputSurfaceElement): Boolean = when
/** A saved element, or, in a gamepad that keeps no kit positions, the kit control that [id] names. */
internal fun SavedInputLayout.element(id: String): InputSurfaceElement? =
elements.firstOrNull { it.id == id } ?: KitLayout.element(id)?.takeIf { OnScreenLayout.generated(this) }
elements.firstOrNull { it.id == id } ?: KitLayout.element(id)?.takeIf { OnScreenLayout.generated(this) || KitLayout.bindsTo(id, elements) }
@@ -60,8 +60,8 @@ class InputSurfaceSource(private val pad: PadBridge, private val role: InputRole
if (latched) 1f else 0f
} else value
if (arms.isNotEmpty() && route?.action is InputAction.Native) {
route.update(x, y, touching)
val values = listOf(y < -.5f, x > .5f, y > .5f, x < -.5f).map { if (it) 1f else 0f }
val ready = route.update(x, y, touching) != null
val values = listOf(y < -.5f, x > .5f, y > .5f, x < -.5f).map { if (it && ready) 1f else 0f }
val toPad = arms.mapIndexed { i, arm -> arm.update(values[i])?.takeIf { it.isPad }?.let { it to values[i] } }.filterNotNull()
if (toPad.isNotEmpty() || nativePad) writePad(this, null) { state -> state.clear(); for ((t, v) in toPad) state.add(t, v) }
nativePad = toPad.isNotEmpty()
@@ -27,6 +27,13 @@ object KitLayout {
else -> null
}
/** The direction buttons the kit's D-pad stands in for; their saved overrides stay with the D-pad. */
val dpadDirectionIds = listOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT).map { "legacy:${it.id}" }
/** Whether a binding for [id] belongs to a layout made of [elements]. */
fun bindsTo(id: String, elements: List<InputSurfaceElement>) =
elements.any { it.id == id } || id in dpadDirectionIds && elements.any { it.id == DPAD_ID }
/** Every kit control that has a click, across all virtual controllers. */
val clickIds = listOf(InputControl.LS, InputControl.RS, InputControl.LEFT_PAD, InputControl.RIGHT_PAD).map { "legacy:${it.id}" }
private const val REF_W = 1600f