From 318331a21eeeafb7685c0dc4ac67c563ae84b09f Mon Sep 17 00:00:00 2001 From: shen Date: Thu, 29 Oct 2026 11:50:56 +0800 Subject: [PATCH] feat: sync controller button swaps with virtual controls for 1.0.1 --- README.md | 4 +- app/build.gradle.kts | 4 +- .../main/java/org/neslite/app/MainActivity.kt | 94 ++++++++++++++++--- .../org/neslite/app/VirtualGamepadLayout.kt | 12 ++- .../org/neslite/app/VirtualGamepadView.kt | 13 +++ .../neslite/app/input/ControllerProfile.kt | 11 +++ .../app/input/ControllerProfileJson.kt | 2 + .../neslite/app/settings/AppSettingsStore.kt | 8 ++ .../java/org/neslite/app/BuildIdentityTest.kt | 4 +- .../neslite/app/VirtualGamepadLayoutTest.kt | 41 ++++++++ .../app/input/ControllerProfileTest.kt | 48 ++++++++++ .../neslite/app/settings/AppSettingsTest.kt | 2 + docs/build.md | 6 +- docs/controller-x5lite.md | 2 +- docs/releases/1.0.1.md | 22 +++++ docs/usage.md | 7 +- 16 files changed, 254 insertions(+), 26 deletions(-) create mode 100644 docs/releases/1.0.1.md diff --git a/README.md b/README.md index 87492f2..d92a5c5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # NESLite -NESLite 是一个面向 Android 的轻量 NES/FC 模拟器前端。当前版本为 1.0.0,内置固定提交的 +NESLite 是一个面向 Android 的轻量 NES/FC 模拟器前端。当前版本为 1.0.1,内置固定提交的 FCEUmm 和 Nestopia,可设置默认内核,也可长按游戏单独选择,下次打开游戏时生效。两个内核的存档 独立保留。0.9.17 对已确认哈希的“龙珠英雄”自动使用 Dendy 制式,两个内核的桌面启动与菜单检查 通过,详见 [兼容修复记录](docs/reports/long-zhu-ying-xiong-0.9.17.md)。 @@ -8,7 +8,7 @@ FCEUmm 和 Nestopia,可设置默认内核,也可长按游戏单独选择, 见 [显示修复记录](docs/reports/integer-scaling-0.9.18.md)。 源码仓库:[shen/NESLite](http://git.m3frame.com/shen/NESLite)。安装包、源码与校验值见 -[发行版](http://git.m3frame.com/shen/NESLite/releases),首次发布说明见 [1.0.0](docs/releases/1.0.0.md)。 +[发行版](http://git.m3frame.com/shen/NESLite/releases),本次更新说明见 [1.0.1](docs/releases/1.0.1.md),首次发布说明见 [1.0.0](docs/releases/1.0.0.md)。 用户已确认产品可发布;历史测试报告中未归档的专项证据仍保留原状态,不据此宣称所有计划测试均已执行。 主界面固定为横屏游戏布局:中央是 4:3 游戏容器,可切换原始像素整数缩放,左右为虚拟按键,左上角提供游戏列表、导入和 diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f458fc3..2adc4f1 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -21,8 +21,8 @@ android { applicationId = "org.neslite.app" minSdk = 28 targetSdk = 36 - versionCode = 1000000 - versionName = "1.0.0" + versionCode = 1000001 + versionName = "1.0.1" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" ndk { diff --git a/app/src/main/java/org/neslite/app/MainActivity.kt b/app/src/main/java/org/neslite/app/MainActivity.kt index 7df3911..9e0103b 100644 --- a/app/src/main/java/org/neslite/app/MainActivity.kt +++ b/app/src/main/java/org/neslite/app/MainActivity.kt @@ -154,6 +154,9 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener { private val profileResolver = ControllerProfileResolver() private lateinit var profileStore: ControllerProfileStore private val controllerProfiles = mutableMapOf() + private val readyControllerProfileIds = mutableSetOf() + private var appSettingsLoaded = false + private var virtualButtonSwapsOverride: Pair? = null private val controllerIdentities = mutableMapOf() private val controllerProfileRevisions = mutableMapOf() private var selectedControllerId: Int? = null @@ -1213,7 +1216,7 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener { } }) settingsPanel.addView(Button(this).apply { - text = "手动设置手柄按键、摇杆与功能键" + text = "交换 X/Y、A/B 按键与手动映射" setOnClickListener { showControllerSettings(returnToPause = false, returnToSettings = true) } @@ -1313,7 +1316,12 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener { val loaded = appSettingsStore.load() val loadedCores = runCatching { corePreferencesStore.load() } runOnUiThread { - appSettings = loaded + // A controller profile can finish loading before the application settings. + appSettings = virtualButtonSwapsOverride?.let { (swapAB, swapXY) -> + loaded.copy(virtualSwapAB = swapAB, virtualSwapXY = swapXY) + } ?: loaded + appSettingsLoaded = true + if (appSettings != loaded) persistAppSettings() loadedCores.onSuccess { corePreferences = it corePreferencesReady = true @@ -1330,6 +1338,7 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener { private fun applyAppSettings() { muted = appSettings.muted if (::virtualGamepad.isInitialized) { + virtualGamepad.configureButtonSwaps(appSettings.virtualSwapAB, appSettings.virtualSwapXY) virtualGamepad.configureDpad( mode = appSettings.directionMode, scale = appSettings.virtualDpadSize.scale, @@ -1352,6 +1361,21 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener { } } + private fun syncVirtualButtonSwaps() { + val deviceId = selectedControllerId ?: return + // Do not overwrite saved screen controls with a temporary default during reconnect. + if (deviceId !in readyControllerProfileIds) return + val profile = controllerProfiles[deviceId] ?: return + virtualButtonSwapsOverride = profile.swapAB to profile.swapXY + val updated = appSettings.copy(virtualSwapAB = profile.swapAB, virtualSwapXY = profile.swapXY) + val changed = updated != appSettings + appSettings = updated + if (::virtualGamepad.isInitialized) { + virtualGamepad.configureButtonSwaps(profile.swapAB, profile.swapXY) + } + if (changed && appSettingsLoaded) persistAppSettings() + } + private fun persistAppSettings() { val snapshot = appSettings controllerScope.launch { appSettingsStore.save(snapshot) } @@ -1527,6 +1551,7 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener { setOnClickListener { val index = controllers.indexOfFirst { it.deviceId == selectedControllerId } selectedControllerId = controllers[(index + 1).mod(controllers.size)].deviceId + syncVirtualButtonSwaps() draftProfile = selectedControllerId?.let(controllerProfiles::get) pendingBindingAction = null manualMappingIndex = null @@ -1565,8 +1590,23 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener { }) }) } + controllerSettingsPanel.addView(section("交换 X/Y、A/B 按键")) + controllerSettingsPanel.addView(body( + "默认顺序:A → NES A,B → NES B,X → A 连发,Y → B 连发。\n" + + "两组可独立交换;已有自定义映射时,交换对应的普通或连发动作绑定。点击保存后,当前手柄和屏幕按键同步交换;屏幕按键的文字与触控位置一起调整。", + )) controllerSettingsPanel.addView(Button(this).apply { - text = if (profile.swapAB) "A/B 交换:开" else "A/B 交换:关" + text = if (profile.swapXY) "交换 X/Y 按键:开" else "交换 X/Y 按键:关" + isEnabled = pendingBindingAction == null && manualMappingIndex == null + setOnClickListener { + draftProfile = profile.toggleXY() + controllerSettingsMessage = "已交换 A/B 连发按键(默认 X/Y);保存后生效。" + renderControllerSettings() + } + }) + controllerSettingsPanel.addView(Button(this).apply { + text = if (profile.swapAB) "交换 A/B 按键:开" else "交换 A/B 按键:关" + isEnabled = pendingBindingAction == null && manualMappingIndex == null setOnClickListener { draftProfile = profile.toggleAB() controllerSettingsMessage = "已交换 NES A/B;保存后生效。" @@ -1810,9 +1850,8 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener { private fun saveControllerProfile() { val deviceId = selectedControllerId ?: return val profile = draftProfile?.copy(origin = ProfileOrigin.CUSTOM) ?: return - val previousProfile = controllerProfiles[deviceId] - controllerProfileRevisions[deviceId] = (controllerProfileRevisions[deviceId] ?: 0) + 1 - controllerProfiles[deviceId] = profile + val revision = (controllerProfileRevisions[deviceId] ?: 0) + 1 + controllerProfileRevisions[deviceId] = revision pendingBindingAction = null manualMappingIndex = null bindingCaptureWaitForNeutral = false @@ -1820,15 +1859,25 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener { controllerScope.launch { val result = runCatching { profileStore.save(profile) } runOnUiThread { + if (controllerProfileRevisions[deviceId] != revision || + controllerIdentities[deviceId]?.fingerprint() != profile.fingerprint + ) return@runOnUiThread + if (result.isSuccess) { + inputRouter.clearDevice(deviceId).let(::applyRoutedInput) + axisHysteresis.clearDevice(deviceId) + controllerProfiles[deviceId] = profile + readyControllerProfileIds += deviceId + if (selectedControllerId == deviceId) { + syncVirtualButtonSwaps() + if (draftProfile?.copy(origin = ProfileOrigin.CUSTOM) == profile) draftProfile = profile + } + } if (selectedControllerId != deviceId) return@runOnUiThread controllerSettingsMessage = if (result.isSuccess) { - "设置已保存;重连和重启后按设备特征恢复。" + "设置已保存,屏幕按键已同步;重连和重启后恢复。" } else { - if (previousProfile == null) controllerProfiles.remove(deviceId) - else controllerProfiles[deviceId] = previousProfile "保存失败:${result.exceptionOrNull()?.message ?: "未知错误"};修改仍保留在页面,可重试保存。" } - draftProfile = profile renderControllerSettings() } } @@ -1838,9 +1887,8 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener { val deviceId = selectedControllerId ?: return val identity = controllerIdentities[deviceId] ?: return val defaultProfile = profileResolver.resolve(identity) - controllerProfileRevisions[deviceId] = (controllerProfileRevisions[deviceId] ?: 0) + 1 - controllerProfiles[deviceId] = defaultProfile - draftProfile = defaultProfile + val revision = (controllerProfileRevisions[deviceId] ?: 0) + 1 + controllerProfileRevisions[deviceId] = revision pendingBindingAction = null manualMappingIndex = null bindingCaptureWaitForNeutral = false @@ -1848,9 +1896,22 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener { controllerScope.launch { val result = runCatching { profileStore.reset(identity) } runOnUiThread { + if (controllerProfileRevisions[deviceId] != revision || + controllerIdentities[deviceId]?.fingerprint() != identity.fingerprint() + ) return@runOnUiThread + if (result.isSuccess) { + inputRouter.clearDevice(deviceId).let(::applyRoutedInput) + axisHysteresis.clearDevice(deviceId) + controllerProfiles[deviceId] = defaultProfile + readyControllerProfileIds += deviceId + if (selectedControllerId == deviceId) { + syncVirtualButtonSwaps() + draftProfile = defaultProfile + } + } if (selectedControllerId != deviceId) return@runOnUiThread controllerSettingsMessage = if (result.isSuccess) { - "已恢复安全的通用默认配置。" + "已恢复通用默认配置,屏幕按键也已恢复。" } else { "恢复默认失败:${result.exceptionOrNull()?.message ?: "未知错误"}" } @@ -1862,12 +1923,14 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener { private fun syncControllerProfiles() { val connected = controllers.mapTo(mutableSetOf()) { it.deviceId } controllerProfiles.keys.retainAll(connected) + readyControllerProfileIds.retainAll(connected) controllerIdentities.keys.retainAll(connected) controllerProfileRevisions.keys.retainAll(connected) controllers.forEach { controller -> val identity = controller.toIdentity() if (controllerIdentities[controller.deviceId]?.fingerprint() == identity.fingerprint()) return@forEach controllerIdentities[controller.deviceId] = identity + readyControllerProfileIds.remove(controller.deviceId) controllerProfiles[controller.deviceId] = profileResolver.resolve(identity) val revision = (controllerProfileRevisions[controller.deviceId] ?: 0) + 1 controllerProfileRevisions[controller.deviceId] = revision @@ -1881,7 +1944,9 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener { val cleared = inputRouter.clearDevice(controller.deviceId) axisHysteresis.clearDevice(controller.deviceId) controllerProfiles[controller.deviceId] = restored + readyControllerProfileIds += controller.deviceId applyRoutedInput(cleared) + if (selectedControllerId == controller.deviceId) syncVirtualButtonSwaps() if (selectedControllerId == controller.deviceId && draftProfile == null) { renderControllerSettings() } @@ -1894,6 +1959,7 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener { draftProfile = null pendingBindingAction = null } + syncVirtualButtonSwaps() renderControllerSettings() } diff --git a/app/src/main/java/org/neslite/app/VirtualGamepadLayout.kt b/app/src/main/java/org/neslite/app/VirtualGamepadLayout.kt index 7fc928e..fff1cb4 100644 --- a/app/src/main/java/org/neslite/app/VirtualGamepadLayout.kt +++ b/app/src/main/java/org/neslite/app/VirtualGamepadLayout.kt @@ -32,6 +32,8 @@ internal fun computeVirtualGamepadGeometry( dpadScale: Float = 1f, dpadHorizontalOffset: Float = 0f, dpadVerticalOffset: Float = 0f, + swapAB: Boolean = false, + swapXY: Boolean = false, ): VirtualGamepadGeometry { val w = width.coerceAtLeast(1f) val h = height.coerceAtLeast(1f) @@ -96,5 +98,13 @@ internal fun computeVirtualGamepadGeometry( ), pause = VirtualControl(w - rightInset - sideWidth * 0.72f - horizontalShift + shift, h * 0.13f, utilityRadius), reset = VirtualControl(baseResetX + shift, h * 0.13f, utilityRadius), - ) + ).let { geometry -> + // Drawing, pressed feedback and touch hit testing all use these same controls. + geometry.copy( + faceA = if (swapAB) geometry.faceB else geometry.faceA, + faceB = if (swapAB) geometry.faceA else geometry.faceB, + faceX = if (swapXY) geometry.faceY else geometry.faceX, + faceY = if (swapXY) geometry.faceX else geometry.faceY, + ) + } } diff --git a/app/src/main/java/org/neslite/app/VirtualGamepadView.kt b/app/src/main/java/org/neslite/app/VirtualGamepadView.kt index 01ede2a..62c0512 100644 --- a/app/src/main/java/org/neslite/app/VirtualGamepadView.kt +++ b/app/src/main/java/org/neslite/app/VirtualGamepadView.kt @@ -47,6 +47,8 @@ class VirtualGamepadView( private var safeLeft = 0f private var safeRight = 0f private var screenShift = 0f + private var swapAB = false + private var swapXY = false private var directionMode = DirectionMode.EIGHT_WAY private var dpadScale = 1.18f private var dpadHorizontalOffset = 0f @@ -88,6 +90,15 @@ class VirtualGamepadView( invalidate() } + internal fun configureButtonSwaps(swapAB: Boolean, swapXY: Boolean) { + if (this.swapAB == swapAB && this.swapXY == swapXY) return + // Release touches against the old layout before changing their targets. + clearInputs() + this.swapAB = swapAB + this.swapXY = swapXY + invalidate() + } + internal fun configureDpad( mode: DirectionMode, scale: Float, @@ -285,6 +296,8 @@ class VirtualGamepadView( dpadScale = dpadScale, dpadHorizontalOffset = dpadHorizontalOffset, dpadVerticalOffset = dpadVerticalOffset, + swapAB = swapAB, + swapXY = swapXY, ) private companion object { diff --git a/app/src/main/java/org/neslite/app/input/ControllerProfile.kt b/app/src/main/java/org/neslite/app/input/ControllerProfile.kt index f176af8..8d6448f 100644 --- a/app/src/main/java/org/neslite/app/input/ControllerProfile.kt +++ b/app/src/main/java/org/neslite/app/input/ControllerProfile.kt @@ -52,6 +52,7 @@ data class ControllerProfile( val pressThreshold: Float = 0.55f, val releaseThreshold: Float = 0.35f, val swapAB: Boolean = false, + val swapXY: Boolean = false, ) { init { require(pressThreshold in 0.2f..0.95f) @@ -78,6 +79,16 @@ data class ControllerProfile( }, ) + fun toggleXY(): ControllerProfile { + val x = bindings[GameAction.TURBO_A].orEmpty() + val y = bindings[GameAction.TURBO_B].orEmpty() + return copy( + origin = ProfileOrigin.CUSTOM, + bindings = bindings + mapOf(GameAction.TURBO_A to y, GameAction.TURBO_B to x), + swapXY = !swapXY, + ) + } + fun toggleAB(): ControllerProfile { val a = bindings[GameAction.NES_A].orEmpty() val b = bindings[GameAction.NES_B].orEmpty() diff --git a/app/src/main/java/org/neslite/app/input/ControllerProfileJson.kt b/app/src/main/java/org/neslite/app/input/ControllerProfileJson.kt index 85afba7..d282950 100644 --- a/app/src/main/java/org/neslite/app/input/ControllerProfileJson.kt +++ b/app/src/main/java/org/neslite/app/input/ControllerProfileJson.kt @@ -13,6 +13,7 @@ object ControllerProfileJson { .put("pressThreshold", profile.pressThreshold.toDouble()) .put("releaseThreshold", profile.releaseThreshold.toDouble()) .put("swapAB", profile.swapAB) + .put("swapXY", profile.swapXY) .put( "bindings", JSONObject().apply { @@ -50,6 +51,7 @@ object ControllerProfileJson { pressThreshold = root.getDouble("pressThreshold").toFloat(), releaseThreshold = root.getDouble("releaseThreshold").toFloat(), swapAB = root.getBoolean("swapAB"), + swapXY = root.optBoolean("swapXY", false), ) } } diff --git a/app/src/main/java/org/neslite/app/settings/AppSettingsStore.kt b/app/src/main/java/org/neslite/app/settings/AppSettingsStore.kt index 3269c32..06be559 100644 --- a/app/src/main/java/org/neslite/app/settings/AppSettingsStore.kt +++ b/app/src/main/java/org/neslite/app/settings/AppSettingsStore.kt @@ -38,6 +38,8 @@ data class AppSettings( val virtualDpadSize: VirtualDpadSize = VirtualDpadSize.LARGE, val virtualDpadHorizontalOffset: Float = 0f, val virtualDpadVerticalOffset: Float = 0f, + val virtualSwapAB: Boolean = false, + val virtualSwapXY: Boolean = false, val guideCompleted: Boolean = false, ) @@ -63,6 +65,8 @@ class AppSettingsStore(private val context: Context) { virtualDpadSize = VirtualDpadSize.fromStored(values[VIRTUAL_DPAD_SIZE] ?: VirtualDpadSize.LARGE.ordinal), virtualDpadHorizontalOffset = (values[VIRTUAL_DPAD_HORIZONTAL_OFFSET] ?: 0f).coerceIn(-1f, 1f), virtualDpadVerticalOffset = (values[VIRTUAL_DPAD_VERTICAL_OFFSET] ?: 0f).coerceIn(-1f, 1f), + virtualSwapAB = values[VIRTUAL_SWAP_AB] ?: false, + virtualSwapXY = values[VIRTUAL_SWAP_XY] ?: false, guideCompleted = values[GUIDE_COMPLETED] ?: false, ) } @@ -80,6 +84,8 @@ class AppSettingsStore(private val context: Context) { values[VIRTUAL_DPAD_SIZE] = settings.virtualDpadSize.ordinal values[VIRTUAL_DPAD_HORIZONTAL_OFFSET] = settings.virtualDpadHorizontalOffset.coerceIn(-1f, 1f) values[VIRTUAL_DPAD_VERTICAL_OFFSET] = settings.virtualDpadVerticalOffset.coerceIn(-1f, 1f) + values[VIRTUAL_SWAP_AB] = settings.virtualSwapAB + values[VIRTUAL_SWAP_XY] = settings.virtualSwapXY values[GUIDE_COMPLETED] = settings.guideCompleted } } @@ -97,6 +103,8 @@ class AppSettingsStore(private val context: Context) { private val VIRTUAL_DPAD_SIZE = intPreferencesKey("virtual_dpad_size") private val VIRTUAL_DPAD_HORIZONTAL_OFFSET = floatPreferencesKey("virtual_dpad_horizontal_offset") private val VIRTUAL_DPAD_VERTICAL_OFFSET = floatPreferencesKey("virtual_dpad_vertical_offset") + private val VIRTUAL_SWAP_AB = booleanPreferencesKey("virtual_swap_ab") + private val VIRTUAL_SWAP_XY = booleanPreferencesKey("virtual_swap_xy") private val GUIDE_COMPLETED = booleanPreferencesKey("guide_completed") } } diff --git a/app/src/test/java/org/neslite/app/BuildIdentityTest.kt b/app/src/test/java/org/neslite/app/BuildIdentityTest.kt index de88336..eec20a6 100644 --- a/app/src/test/java/org/neslite/app/BuildIdentityTest.kt +++ b/app/src/test/java/org/neslite/app/BuildIdentityTest.kt @@ -7,7 +7,7 @@ class BuildIdentityTest { @Test fun debugBuildUsesTheDocumentedIdentity() { assertEquals("org.neslite.app.debug", BuildConfig.APPLICATION_ID) - assertEquals("1.0.0-debug", BuildConfig.VERSION_NAME) - assertEquals(1000000, BuildConfig.VERSION_CODE) + assertEquals("1.0.1-debug", BuildConfig.VERSION_NAME) + assertEquals(1000001, BuildConfig.VERSION_CODE) } } diff --git a/app/src/test/java/org/neslite/app/VirtualGamepadLayoutTest.kt b/app/src/test/java/org/neslite/app/VirtualGamepadLayoutTest.kt index 118db84..3d4128c 100644 --- a/app/src/test/java/org/neslite/app/VirtualGamepadLayoutTest.kt +++ b/app/src/test/java/org/neslite/app/VirtualGamepadLayoutTest.kt @@ -218,6 +218,47 @@ class VirtualGamepadLayoutTest { assertTrue(flipped.faceB.x + flipped.faceB.radius < 2760f) } + @Test + fun allSwapCombinationsMoveOnlyTheirMatchingLabeledTouchControls() { + val original = computeVirtualGamepadGeometry(2760f, 1256f, 126f) + for (swapAB in listOf(false, true)) { + for (swapXY in listOf(false, true)) { + val swapped = computeVirtualGamepadGeometry( + 2760f, 1256f, 126f, swapAB = swapAB, swapXY = swapXY, + ) + assertEquals(if (swapAB) original.faceB else original.faceA, swapped.faceA) + assertEquals(if (swapAB) original.faceA else original.faceB, swapped.faceB) + assertEquals(if (swapXY) original.faceY else original.faceX, swapped.faceX) + assertEquals(if (swapXY) original.faceX else original.faceY, swapped.faceY) + // Every other control and the game viewport remain unchanged. + assertEquals(original, swapped.copy( + faceA = original.faceA, faceB = original.faceB, + faceX = original.faceX, faceY = original.faceY, + )) + } + } + } + + @Test + fun swappedControlsKeepTheirPositionsAcrossDifferentInsetsAndDpadSettings() { + for (inset in listOf(0f, 48f, 172f, 288f)) { + val original = computeVirtualGamepadGeometry( + 2760f, 1256f, 126f, safeLeft = inset, screenShift = 47f, + dpadScale = 1.35f, dpadHorizontalOffset = -1f, dpadVerticalOffset = 1f, + ) + val swapped = computeVirtualGamepadGeometry( + 2760f, 1256f, 126f, safeLeft = inset, screenShift = 47f, + dpadScale = 1.35f, dpadHorizontalOffset = -1f, dpadVerticalOffset = 1f, + swapAB = true, swapXY = true, + ) + assertEquals(original.faceB, swapped.faceA) + assertEquals(original.faceA, swapped.faceB) + assertEquals(original.faceY, swapped.faceX) + assertEquals(original.faceX, swapped.faceY) + assertEquals(original.horizontalShift, swapped.horizontalShift) + } + } + private fun distance(first: VirtualControl, second: VirtualControl): Float = hypot(first.x - second.x, first.y - second.y) } diff --git a/app/src/test/java/org/neslite/app/input/ControllerProfileTest.kt b/app/src/test/java/org/neslite/app/input/ControllerProfileTest.kt index 23db132..6b47835 100644 --- a/app/src/test/java/org/neslite/app/input/ControllerProfileTest.kt +++ b/app/src/test/java/org/neslite/app/input/ControllerProfileTest.kt @@ -55,6 +55,54 @@ class ControllerProfileTest { assertFalse(JSONObject(ControllerProfileJson.encode(swapped)).has("deviceId")) } + @Test + fun xySwapOnlyExchangesTurboActionsAndIsReversible() { + val original = ControllerProfileResolver().resolve(identity) + val swapped = original.toggleXY() + assertTrue(swapped.swapXY) + assertFalse(swapped.swapAB) + assertEquals(ProfileOrigin.CUSTOM, swapped.origin) + assertEquals(setOf(GameAction.TURBO_B), swapped.actionsFor(InputBinding(BindingKind.KEY, 99))) + assertEquals(setOf(GameAction.TURBO_A), swapped.actionsFor(InputBinding(BindingKind.KEY, 100))) + GameAction.entries.filter { it != GameAction.TURBO_A && it != GameAction.TURBO_B }.forEach { + assertEquals(original.bindings[it], swapped.bindings[it]) + } + assertEquals(original.bindings, swapped.toggleXY().bindings) + assertFalse(swapped.toggleXY().swapXY) + } + + @Test + fun bothSwapsAreIndependentAndPersistTogether() { + val original = ControllerProfileResolver().resolve(identity) + val swapped = original.toggleAB().toggleXY() + assertEquals(swapped, original.toggleXY().toggleAB()) + assertEquals(setOf(GameAction.NES_B), swapped.actionsFor(InputBinding(BindingKind.KEY, 96))) + assertEquals(setOf(GameAction.NES_A), swapped.actionsFor(InputBinding(BindingKind.KEY, 97))) + assertEquals(swapped, ControllerProfileJson.decode(ControllerProfileJson.encode(swapped))) + val xyOnly = swapped.toggleAB() + assertFalse(xyOnly.swapAB) + assertTrue(xyOnly.swapXY) + assertEquals(original.bindings, xyOnly.toggleXY().bindings) + } + + @Test + fun legacyProfileWithoutXyFlagKeepsSavedBindings() { + val original = ControllerProfileResolver().resolve(identity).toggleAB() + val legacy = JSONObject(ControllerProfileJson.encode(original)).apply { remove("swapXY") } + assertEquals(original, ControllerProfileJson.decode(legacy.toString())) + } + + @Test + fun xySwapPreservesCustomAndEmptyBindings() { + val original = ControllerProfileResolver().resolve(identity) + .replaceBinding(GameAction.TURBO_A, InputBinding(BindingKind.KEY, 188)) + .clearBinding(GameAction.TURBO_B) + val swapped = original.toggleXY() + assertTrue(swapped.bindings.getValue(GameAction.TURBO_A).isEmpty()) + assertEquals(setOf(GameAction.TURBO_B), swapped.actionsFor(InputBinding(BindingKind.KEY, 188))) + assertEquals(original, swapped.toggleXY()) + } + @Test fun manualMappingCanReplaceAndClearEachAction() { val original = ControllerProfileResolver().resolve(identity) diff --git a/app/src/test/java/org/neslite/app/settings/AppSettingsTest.kt b/app/src/test/java/org/neslite/app/settings/AppSettingsTest.kt index 8bd92bc..945fa44 100644 --- a/app/src/test/java/org/neslite/app/settings/AppSettingsTest.kt +++ b/app/src/test/java/org/neslite/app/settings/AppSettingsTest.kt @@ -20,6 +20,8 @@ class AppSettingsTest { assertEquals(VirtualDpadSize.LARGE, settings.virtualDpadSize) assertEquals(0f, settings.virtualDpadHorizontalOffset) assertEquals(0f, settings.virtualDpadVerticalOffset) + assertFalse(settings.virtualSwapAB) + assertFalse(settings.virtualSwapXY) assertFalse(settings.guideCompleted) } diff --git a/docs/build.md b/docs/build.md index 160fe00..cdf2786 100644 --- a/docs/build.md +++ b/docs/build.md @@ -1,7 +1,7 @@ # NESLite 构建与打包 项目的 APK 打包入口统一为根目录 `打包.cmd`,项目内的编译产物、缓存、日志和交付文件统一放入 -`build/`。当前应用版本为 1.0.0,入口从 APK 构建元数据读取版本,不另写一套版本号。 +`build/`。当前应用版本为 1.0.1,入口从 APK 构建元数据读取版本,不另写一套版本号。 ## 一键打包 @@ -14,7 +14,7 @@ .\打包.cmd -NoPause ``` -当前交付文件是 `build/releases/NESLite-1.0.0-debug-arm64-v8a.apk`,旁边的 `.sha256` 保存校验值。 +当前交付文件是 `build/releases/NESLite-1.0.1-debug-arm64-v8a.apk`,旁边的 `.sha256` 保存校验值。 入口检查工具链与固定依赖、编译选定 APK、检查原生库和 APK 的 16 KB 对齐,成功后复制产物。 它不会自动启动单元测试、ROM 遍历、设备测试或发布回归;失败会返回非零退出码,旧交付 APK 不冒充本次成功产物。 @@ -24,7 +24,7 @@ .\打包.cmd release -NoPause ``` -该模式使用项目外的正式密钥,生成 `build/releases/NESLite-1.0.0-arm64-v8a.apk`、原生符号、应用和依赖源码 ZIP、发布清单及校验值。 +该模式使用项目外的正式密钥,生成 `build/releases/NESLite-1.0.1-arm64-v8a.apk`、原生符号、应用和依赖源码 ZIP、发布清单及校验值。 正式打包前必须提交源码并配置签名目录;入口读取 Windows 用户加密的密码,完成签名和签名验证。密钥位置与发布步骤见 [publishing.md](publishing.md)。 一键打包不会运行原 `package-rc.ps1` 的全量 Stage/lint/设备测试包构建,也不表示发布门槛通过。 diff --git a/docs/controller-x5lite.md b/docs/controller-x5lite.md index 37bcce6..facdfa0 100644 --- a/docs/controller-x5lite.md +++ b/docs/controller-x5lite.md @@ -5,7 +5,7 @@ ABXY、视图/菜单键及左右肩键。随后在荣耀 Magic8 页面取得了 Android 设备身份和静态轴范围; 实际 KeyEvent、动态轴采样、手柄模式及拔出重连仍待诊断 JSON 回填。 -在 0.9.15-debug 中可从“设置 → 手动设置手柄按键、摇杆与功能键”进入编辑页。可选择“开始逐项手动 +在 0.9.15-debug 中可从“设置 → 交换 X/Y、A/B 按键与手动映射”进入编辑页。可选择“开始逐项手动 设置全部按键”,按页面顺序操作 X5 Lite;也可点击任一动作单独修改或清除。轴方向捕获后先松回中位, 冲突时确认是否替换,最后点击“保存”。配置按下表设备指纹保存,不依赖临时 deviceId。 diff --git a/docs/releases/1.0.1.md b/docs/releases/1.0.1.md new file mode 100644 index 0000000..ffe594f --- /dev/null +++ b/docs/releases/1.0.1.md @@ -0,0 +1,22 @@ +# NESLite 1.0.1 + +本次更新增加手柄与屏幕虚拟按键的同步交换,面向 Android 9 及以上的 arm64 设备。 + +## 本次更新 + +- 设置中提供“交换 X/Y、A/B 按键与手动映射”入口,两组可独立交换。 +- 保存后屏幕虚拟按键同步换位,文字、颜色、按下反馈和触控区域保持一致。 +- 屏幕按键在断开手柄或重启后保留最近的交换状态;恢复默认时一起还原。 +- 兼容旧手柄配置,换位前释放触控输入,保存失败时继续使用原有映射。 + +## 安装 + +安装包为 `NESLite-1.0.1-arm64-v8a.apk`,正式包名为 `org.neslite.app`,版本号为 1000001。 +沿用 1.0.0 正式签名,可直接覆盖安装旧正式版。调试版包名不同,仍需通过存档导入导出迁移进度。 +应用不附带游戏 ROM。 + +## 验证与构建材料 + +功能修改已通过 71 项单元测试和调试构建;手柄实机、触屏操作及覆盖升级仍待设备验证。 +正式打包流程校验签名、arm64 库与 16 KB 静态对齐,并输出源码、原生符号、依赖源码和 SHA-256 清单。 +具体版本、源码提交及安装包校验值见同目录的 `NESLite-1.0.1-release.json`。 diff --git a/docs/usage.md b/docs/usage.md index 6c1e1a8..fb52269 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -13,7 +13,12 @@ 长按游戏名可查看详情、收藏、从列表移除或选择内核。连接外接手柄后仍可按设置选择是否显示 屏幕按键。多点触控支持方向与动作同时按住,滑出、取消、失焦或暂停都会释放输入。 4. 点左上角“设置”图标,在画面与声音、方向与触控、手柄与辅助三个卡片中调整选项,可切换 4:3/整数缩放、最近邻/线性过滤、音量、静音、软件连发和 RB 快进。进入 - “手动设置手柄按键、摇杆与功能键”后,可启动逐项向导,也可单独点击动作修改或清除;按下物理键 + “交换 X/Y、A/B 按键与手动映射”后,可分别开启“交换 X/Y 按键”和“交换 A/B 按键”,点击保存后生效。 + 默认 A/B 对应 NES A/B,X/Y 对应 A/B 连发;两组独立交换,保存后所选手柄与屏幕虚拟按键同步。 + 屏幕上的按钮文字、颜色、按下反馈与触控区域一起换位;断开手柄或重启应用后保留最近的交换状态。 + 切换所选手柄时,屏幕跟随该手柄已保存的交换设置;尚未保存的修改不会影响屏幕按键。 + 已有自定义映射时,交换对应的普通或连发动作绑定;再次切换可还原,恢复默认映射会关闭两项交换。 + 同一页面可启动逐项向导,也可单独点击动作修改或清除;按下物理键 或推动轴完成捕获,检查无误后点“保存”。冲突会要求确认,设置按设备特征在重启和重连后恢复。 “屏幕方向键与手柄摇杆”可切换四方向/八方向,并循环选择标准、大、特大方向键;两个位置滑块可 调整方向键的水平和垂直位置。默认八方向与大号,A、B 支持两根手指同时按住。