mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
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:
1 parent
0b8a3f1ee8
commit
bc929c08b2
2 files changed
+32
-1
No files matched your search
@@ -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()))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user