mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
fix(input): send files with older Winlator key names through the converter
This commit is contained in:
1 parent
f94d5179c3
commit
2f192fddee
3 files changed
+20
-2
No files matched your search
@@ -29,6 +29,9 @@ internal object InputLayoutFile {
|
||||
)
|
||||
private val CODES: Map<String, Int> = NAMES.entries.associate { (code, name) -> name to code }
|
||||
|
||||
/** Whether [parse] keeps a binding with this name. */
|
||||
internal fun knows(binding: String) = binding in CODES
|
||||
|
||||
fun fileName(layout: SavedInputLayout) = layout.name.replace(Regex("[^A-Za-z0-9 _.-]"), "_").trim().ifEmpty { "droiddeck-layout" } + ".icp"
|
||||
|
||||
fun export(layout: SavedInputLayout, bindings: SavedInputBindings?, width: Int, height: Int): String? {
|
||||
|
||||
@@ -20,7 +20,7 @@ object WinlatorLayouts {
|
||||
fun isIcp(raw: String) = runCatching { JSONObject(raw).let { it.has("elements") && it.optJSONArray("elements") != null && it.has("cursorSpeed") } }.getOrDefault(false)
|
||||
|
||||
/**
|
||||
* Whether a file uses something only this converter keeps: mouse or gamepad bindings, trackpads or key ranges.
|
||||
* Whether a file uses something only this converter keeps: mouse or gamepad bindings, older key names, trackpads or key ranges.
|
||||
* DroidDeck's own exports send only keys, so they keep importing through [InputLayoutFile] with the sizes they were saved with.
|
||||
*/
|
||||
fun needsConversion(raw: String): Boolean = runCatching {
|
||||
@@ -28,7 +28,7 @@ object WinlatorLayouts {
|
||||
(0 until elements.length()).any { i ->
|
||||
val e = elements.optJSONObject(i) ?: return@any false
|
||||
val bindings = e.optJSONArray("bindings")?.let { a -> (0 until a.length()).map { a.optString(it) } }.orEmpty()
|
||||
e.optString("type") in setOf("TRACKPAD", "RANGE_BUTTON") || bindings.any { it.isNotBlank() && it != "NONE" && !it.startsWith("KEY_") }
|
||||
e.optString("type") in setOf("TRACKPAD", "RANGE_BUTTON") || bindings.any { it.isNotBlank() && it != "NONE" && !InputLayoutFile.knows(it) }
|
||||
}
|
||||
}.getOrDefault(false)
|
||||
|
||||
|
||||
Reference in new issue
Block a user