fix(input): save Steam touch layout without existing config (#2580)

* fix(input): save Steam touch layout without existing config

* fix(input): preserve unreadable Steam touch config on save

* test(input): register configset in unreadable touch config fixture
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-13 17:24:25 -05:00
1 parent 0b8a3f1ee8
commit bc929c08b2
2 files changed
+32 -1

No files matched your search

@@ -390,7 +390,8 @@ object SteamTouchConfig {
options: Options? = null,
): File? {
val dir = configDir(context) ?: return null
val source = bindings.entries.fold(config.text ?: return null) { text, (ref, change) ->
val base = config.text ?: if (config.file == null && bindings.isEmpty()) "\"controller_mappings\"\n{\n\t\"controller_type\"\t\t\"controller_mobile_touch\"\n}\n" else return null
val source = bindings.entries.fold(base) { text, (ref, change) ->
SteamTouchBindings.rewrite(text, ref, change) ?: text
}
val key = steamKey(context, appId)
@@ -113,4 +113,34 @@ class SteamTouchConfigFilesTest {
assertEquals(1, entries.findAll(File(dir, "configset_controller_mobile_touch.vdf").readText()).count())
assertEquals(0, entries.findAll(File(dir, "configset_MT-DROIDDECK0001.vdf").readText()).count())
}
@Test fun savesLayoutWhenNoTouchConfigExistsOnDisk() {
val config = SteamTouchConfig.load(context, 413150)
assertEquals(null, config.file)
assertEquals(null, config.text)
val elements = listOf(SteamTouchConfig.Element(SteamTouchConfig.A, true, 0.5f, 0.6f))
val saved = SteamTouchConfig.saveLayouts(context, 413150, config, mapOf(1 to elements))
assertEquals(File(dir, "413150/controller_mobile_touch.vdf"), saved)
assertTrue(saved!!.readText().contains("\"touch_layout\""))
val loaded = SteamTouchConfig.load(context, 413150)
assertEquals(saved, loaded.file)
val a = SteamTouchConfig.elementsFor(loaded, 1, emptyList()).first { it.type == SteamTouchConfig.A }
assertEquals(0.5f, a.x, 0.002f)
assertEquals(0.6f, a.y, 0.002f)
}
@Test fun savingDoesNotOverwriteUnreadableExistingTouchConfig() {
configset("configset_controller_mobile_touch.vdf", "413150" to "\"autosave\"\t\t\"1\"")
val file = File(dir, "413150/controller_mobile_touch.vdf").apply {
parentFile!!.mkdirs()
writeText("\"controller_mappings\"\n{\n\t\"controller_type\"\t\t\"controller_mobile_touch\"\n\t\"touch_layout\"\t\t\"zz\"\n}\n")
}
val original = file.readBytes()
val config = SteamTouchConfig.load(context, 413150)
assertEquals(file, config.file)
assertEquals(null, config.text)
val saved = SteamTouchConfig.saveLayouts(context, 413150, config, emptyMap())
assertEquals(null, saved)
assertTrue(original.contentEquals(file.readBytes()))
}
}