mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
fix(input): refuse layout files over 64 controls on the original importer too
This commit is contained in:
1 parent
3c4d349a47
commit
668e02fa17
2 files changed
+11
-1
No files matched your search
@@ -105,11 +105,12 @@ internal object InputLayoutFile {
|
||||
else -> 4f * snap * scale
|
||||
}
|
||||
fun coordinate(name: String) = element.optDouble(name, .5).toFloat().takeIf { it.isFinite() }?.coerceIn(0f, 1f) ?: .5f
|
||||
// A layout holds 64 controls; a file with more is refused rather than cut short.
|
||||
if (keys.size == 64) return null
|
||||
keys += LegacyScreenKey(codes, coordinate("x"), coordinate("y"), (sizePx / density).roundToInt().coerceIn(24, 140).toFloat(),
|
||||
text = element.optString("text").trim().take(24),
|
||||
opacity = element.optDouble("opacity", 1.0).toFloat().takeIf { it.isFinite() }?.coerceIn(.2f, 1f) ?: 1f,
|
||||
shape = shape, toggle = element.optBoolean("toggleSwitch"))
|
||||
if (keys.size == 64) break
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
@@ -159,6 +159,15 @@ class WinlatorLayoutsTest {
|
||||
assertEquals(52, layout.elements.size)
|
||||
}
|
||||
|
||||
@Test fun aFileWithoutCursorSpeedOver64ControlsIsRefusedByTheOtherImporter() {
|
||||
val buttons = (0 until 65).joinToString(",") { """{"type":"BUTTON","shape":"CIRCLE","bindings":["KEY_A"],"scale":0.5,"x":0.5,"y":0.5}""" }
|
||||
val raw = """{"name":"Many","elements":[$buttons]}"""
|
||||
assertFalse(WinlatorLayouts.isIcp(raw))
|
||||
assertNull(InputLayoutFile.import(context, raw, "Many", InputLayoutScreen.MAIN, InputSurfaceStyle(), 1920, 1080, 2f))
|
||||
val sixtyFour = """{"name":"Fits","elements":[${(0 until 64).joinToString(",") { """{"type":"BUTTON","bindings":["KEY_A"],"x":0.5,"y":0.5}""" }}]}"""
|
||||
assertEquals(64, InputLayoutFile.import(context, sixtyFour, "Fits", InputLayoutScreen.MAIN, InputSurfaceStyle(), 1920, 1080, 2f)!!.first.elements.size)
|
||||
}
|
||||
|
||||
@Test fun aKeyboardTrackpadKeepsItsKeys() {
|
||||
val raw = """{"cursorSpeed":1,"elements":[{"type":"TRACKPAD","shape":"CIRCLE","bindings":["KEY_W","KEY_D","KEY_S","KEY_A"],"scale":1,"x":0.5,"y":0.5}]}"""
|
||||
val (layout, bindings) = WinlatorLayouts.import(raw, "x", InputLayoutScreen.MAIN, 1920, 1080)!!
|
||||
|
||||
Reference in new issue
Block a user