Modern Apps git

← Modern-Apps.git

games-unblockjam: ktlint rollout — format module and fix residue

Commit
8a9d4973fe12423c4c539b7cba83e167f3ce6153
Author
Vayun Mathur <[email protected]>
When
2026-12-01 19:05 UTC (4 days ago)
Parents
b8566aa
Ran ./format games/unblockjam over the whole module: 799
violations in 44 files at census (main 460, test 323, androidTest
8, screenshotTest 8) are down to zero, verified by ktlintCheck
on every source set.

Manual fixes for the non-autocorrectable residue:
- Renamed the mutable LevelPack.PACKS registry to packs
  (property-naming) at its declaration and every call site in
  main and test sources.
- Merged the doubled KDoc in GameUiContract, also correcting its
  stale claim that the contract lives in `util`: it lives in
  `platform` alongside the ViewModel.

detekt fixes surfaced once the module compiled formatted:
- RushHourSolver.Board.of carried a 26-complexity validation
  sequence with 12 returns and a 4-way complex condition.
  Extracted mainAndSizeValid, blocksFitBoard and
  hasOverlappingBlocks as named companion helpers, each with a
  single responsibility; board construction is unchanged.
- UnblockJamViewModelOverlapTest: extracted the shipped-level
  clash search from the test body into findStaleClash /
  staleClashAt helpers that return the clash directly instead of
  break/continue bookkeeping, which also removes the
  multi-jump loop the detekt LoopWithTooManyJumpStatements rule
  flagged.

No ktlint rule was disabled, no detekt or detector config was
touched, and no baseline was added.

Verified: ./gradlew :games:unblockjam:detekt :games:unblockjam:lint
:games:unblockjam:ktlintCheck :games:unblockjam:compileDevKotlin
green; :games:unblockjam:testDevUnitTest green. ./check
games/unblockjam still fails only on the repo-wide structure
ratchets and verifyLibraryBoundaries (communicate-dev and other
modules, pre-existing and outside this module's scope); every
unblockjam task in that run is green.

Diff

games/unblockjam/src/androidTest/java/com/vayunmathur/games/unblockjam/ui/FullE2eTest.kt
diff --git a/games/unblockjam/src/androidTest/java/com/vayunmathur/games/unblockjam/ui/FullE2eTest.kt b/games/unblockjam/src/androidTest/java/com/vayunmathur/games/unblockjam/ui/FullE2eTest.ktindex 755a5c5f69..2360d38e55 100644--- a/games/unblockjam/src/androidTest/java/com/vayunmathur/games/unblockjam/ui/FullE2eTest.kt+++ b/games/unblockjam/src/androidTest/java/com/vayunmathur/games/unblockjam/ui/FullE2eTest.kt@@ -8,12 +8,12 @@ import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.By import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.Until-import java.io.IOException import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull import org.junit.Assert.assertNull import org.junit.Test import org.junit.runner.RunWith+import java.io.IOException  /**  * Full e2e test: launches the app, grants every requested permission, and@@ -29,7 +29,6 @@ import org.junit.runner.RunWith  */ @RunWith(AndroidJUnit4::class) class FullE2eTest {-     @Test     fun launch_grantsPermissions_showsPackList() {         val instrumentation = InstrumentationRegistry.getInstrumentation()@@ -64,11 +63,12 @@ class FullE2eTest {         packageManager: PackageManager,         packageName: String,     ) {-        val info = try {-            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)-        } catch (e: PackageManager.NameNotFoundException) {-            throw AssertionError("package $packageName not installed", e)-        }+        val info =+            try {+                packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+            } catch (e: PackageManager.NameNotFoundException) {+                throw AssertionError("package $packageName not installed", e)+            }         for (permission in info.requestedPermissions.orEmpty()) {             try {                 uiAutomation.executeShellCommand("pm grant $packageName $permission").close()@@ -101,9 +101,10 @@ class FullE2eTest {          * have no pm-grantable permission, but the shell can flip their appops.          * Ignored where the appop does not exist; the gate assertion reports it.          */-        private val SPECIAL_ACCESS_COMMANDS = arrayOf(-            "appops set %s SCHEDULE_EXACT_ALARM allow",-            "appops set %s USE_FULL_SCREEN_INTENT allow",-        )+        private val SPECIAL_ACCESS_COMMANDS =+            arrayOf(+                "appops set %s SCHEDULE_EXACT_ALARM allow",+                "appops set %s USE_FULL_SCREEN_INTENT allow",+            )     } }
games/unblockjam/src/androidTest/java/com/vayunmathur/games/unblockjam/ui/GamePlayTest.kt
diff --git a/games/unblockjam/src/androidTest/java/com/vayunmathur/games/unblockjam/ui/GamePlayTest.kt b/games/unblockjam/src/androidTest/java/com/vayunmathur/games/unblockjam/ui/GamePlayTest.ktindex d8765131a4..cc2a01db26 100644--- a/games/unblockjam/src/androidTest/java/com/vayunmathur/games/unblockjam/ui/GamePlayTest.kt+++ b/games/unblockjam/src/androidTest/java/com/vayunmathur/games/unblockjam/ui/GamePlayTest.kt@@ -8,12 +8,12 @@ import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.By import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.Until-import java.io.IOException import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull import org.junit.Assert.assertNull import org.junit.Test import org.junit.runner.RunWith+import java.io.IOException  /**  * Journey test: launches unblockjam, opens the first pack and puzzle, taps@@ -30,7 +30,6 @@ import org.junit.runner.RunWith  */ @RunWith(AndroidJUnit4::class) class GamePlayTest {-     @Test     fun play_openFirstPuzzle_tapUndo_boardStays() {         val instrumentation = InstrumentationRegistry.getInstrumentation()@@ -87,11 +86,12 @@ class GamePlayTest {         packageManager: PackageManager,         packageName: String,     ) {-        val info = try {-            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)-        } catch (e: PackageManager.NameNotFoundException) {-            throw AssertionError("package $packageName not installed", e)-        }+        val info =+            try {+                packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+            } catch (e: PackageManager.NameNotFoundException) {+                throw AssertionError("package $packageName not installed", e)+            }         for (permission in info.requestedPermissions.orEmpty()) {             try {                 uiAutomation.executeShellCommand("pm grant $packageName $permission").close()@@ -129,9 +129,10 @@ class GamePlayTest {          * have no pm-grantable permission, but the shell can flip their appops.          * Ignored where the appop does not exist; the gate assertion reports it.          */-        private val SPECIAL_ACCESS_COMMANDS = arrayOf(-            "appops set %s SCHEDULE_EXACT_ALARM allow",-            "appops set %s USE_FULL_SCREEN_INTENT allow",-        )+        private val SPECIAL_ACCESS_COMMANDS =+            arrayOf(+                "appops set %s SCHEDULE_EXACT_ALARM allow",+                "appops set %s USE_FULL_SCREEN_INTENT allow",+            )     } }
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Navigation.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Navigation.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Navigation.ktindex e6ea55ea7e..9e922294f2 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Navigation.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Navigation.kt@@ -43,10 +43,10 @@ import com.vayunmathur.games.unblockjam.platform.UnblockJamViewModel import com.vayunmathur.games.unblockjam.ui.UnblockJamTheme import com.vayunmathur.games.unblockjam.ui.components.GameBoard import com.vayunmathur.library.ui.AchievementNotification+import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.CardDefaults-import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.ConfirmDialog import com.vayunmathur.library.ui.DailyReminderSettingsSection import com.vayunmathur.library.ui.DetailScaffold@@ -56,16 +56,16 @@ import com.vayunmathur.library.ui.GameCenterScreen import com.vayunmathur.library.ui.IconCheck import com.vayunmathur.library.ui.IconStar import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Surface-import com.vayunmathur.library.ui.rememberPermissionRequest+import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.game.DailyChallengeCard import com.vayunmathur.library.ui.game.GameTopBarActions import com.vayunmathur.library.ui.game.LevelPickerBox import com.vayunmathur.library.ui.game.MovesBox+import com.vayunmathur.library.ui.rememberPermissionRequest+import com.vayunmathur.library.util.FullscreenPage import com.vayunmathur.library.util.GameHubComposeHook import com.vayunmathur.library.util.LevelStats-import com.vayunmathur.library.util.FullscreenPage import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.util.OpenSettingsIfRequested@@ -91,13 +91,13 @@ fun Navigation(viewModel: UnblockJamViewModel) {                 )             }             entry<Route.LevelSelector> {-                val pack = LevelPack.PACKS[it.packIndex]+                val pack = LevelPack.packs[it.packIndex]                 UnblockJamTheme(pack = pack) {                     LevelPage(backStack, viewModel, it.packIndex)                 }             }             entry<Route.Game>(metadata = FullscreenPage()) {-                val pack = LevelPack.PACKS[it.packIndex]+                val pack = LevelPack.packs[it.packIndex]                 UnblockJamTheme(pack = pack) {                     GamePage(backStack, viewModel, it.packIndex, it.levelIndex)                 }@@ -111,7 +111,7 @@ fun Navigation(viewModel: UnblockJamViewModel) {             entry<Route.GameCenter> {                 GameCenterScreen(                     manager = viewModel.achievementsManager,-                    onBack = { backStack.pop() }+                    onBack = { backStack.pop() },                 )             }             entry<Route.Settings> {@@ -131,6 +131,7 @@ fun Navigation(viewModel: UnblockJamViewModel) {         }     } }+ /** Binds [UnblockJamViewModel] to the stateless [PackScreen]. */ @Composable fun PackPage(@@ -144,13 +145,14 @@ fun PackPage(     val dailyStreak by viewModel.dailyStreak.collectAsState()      PackScreen(-        packNames = LevelPack.PACKS.map { it.name },-        daily = DailyProgress(-            day = dailyDay,-            completed = dailyCompleted,-            total = DailyLevelGenerator.LEVELS_PER_DAY,-            streak = dailyStreak,-        ),+        packNames = LevelPack.packs.map { it.name },+        daily =+            DailyProgress(+                day = dailyDay,+                completed = dailyCompleted,+                total = DailyLevelGenerator.LEVELS_PER_DAY,+                streak = dailyStreak,+            ),         onOpenPack = { backStack.add(Route.LevelSelector(it)) },         onOpenDaily = { backStack.add(Route.DailySelector) },         onOpenGameCenter = onOpenGameCenter,@@ -160,37 +162,45 @@ fun PackPage(  /** Binds [UnblockJamViewModel] to the stateless [SettingsScreen]. */ @Composable-fun SettingsPage(viewModel: UnblockJamViewModel, onBack: () -> Unit) {+fun SettingsPage(+    viewModel: UnblockJamViewModel,+    onBack: () -> Unit,+) {     val reminderEnabled by viewModel.reminderEnabled.collectAsState()     val reminderMinutes by viewModel.reminderMinutesOfDay.collectAsState()      // POST_NOTIFICATIONS is a String constant inlined at compile time, so referencing     // it below API 33 is safe; it is only requested on API 33+ (see setReminderEnabled).-    val notificationPermission = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {-        Manifest.permission.POST_NOTIFICATIONS-    } else {-        ""-    }+    val notificationPermission =+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {+            Manifest.permission.POST_NOTIFICATIONS+        } else {+            ""+        }     val requestNotifications = rememberPermissionRequest(notificationPermission)      SettingsScreen(-        state = SettingsUiState(-            reminderEnabled = reminderEnabled,-            reminderHour = (reminderMinutes / 60).toInt(),-            reminderMinute = (reminderMinutes % 60).toInt(),-        ),-        actions = object : SettingsActions {-            override fun setReminderEnabled(enabled: Boolean) {-                // Asked for lazily, on opt-in only, so the screen never blocks on a prompt.-                if (enabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {-                    requestNotifications()+        state =+            SettingsUiState(+                reminderEnabled = reminderEnabled,+                reminderHour = (reminderMinutes / 60).toInt(),+                reminderMinute = (reminderMinutes % 60).toInt(),+            ),+        actions =+            object : SettingsActions {+                override fun setReminderEnabled(enabled: Boolean) {+                    // Asked for lazily, on opt-in only, so the screen never blocks on a prompt.+                    if (enabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {+                        requestNotifications()+                    }+                    viewModel.setReminderEnabled(enabled)                 }-                viewModel.setReminderEnabled(enabled)-            } -            override fun setReminderTime(hour: Int, minute: Int) =-                viewModel.setReminderTime(hour, minute)-        },+                override fun setReminderTime(+                    hour: Int,+                    minute: Int,+                ) = viewModel.setReminderTime(hour, minute)+            },         onBack = onBack,     ) }@@ -198,7 +208,11 @@ fun SettingsPage(viewModel: UnblockJamViewModel, onBack: () -> Unit) { /** The settings screen, ViewModel-free so a preview can render it. */ @OptIn(ExperimentalMaterial3Api::class) @Composable-fun SettingsScreen(state: SettingsUiState, actions: SettingsActions, onBack: () -> Unit) {+fun SettingsScreen(+    state: SettingsUiState,+    actions: SettingsActions,+    onBack: () -> Unit,+) {     DetailScaffold(         title = stringResource(UiR.string.settings),         onNavigateBack = onBack,@@ -249,9 +263,12 @@ fun PackScreen(                 }             }             itemsIndexed(packNames) { index, name ->-                Card(Modifier.clickable{-                    onOpenPack(index)-                }, colors = CardDefaults.cardColors(MaterialTheme.colorScheme.surface)) {+                Card(+                    Modifier.clickable {+                        onOpenPack(index)+                    },+                    colors = CardDefaults.cardColors(MaterialTheme.colorScheme.surface),+                ) {                     Box(Modifier.fillMaxWidth().padding(8.dp)) {                         Text(name, Modifier.align(Alignment.Center), style = MaterialTheme.typography.displayMedium)                     }@@ -263,7 +280,10 @@ fun PackScreen(  /** Binds [UnblockJamViewModel] to today's daily pack, reusing the pack level grid. */ @Composable-fun DailyLevelPage(backStack: NavBackStack<Route>, viewModel: UnblockJamViewModel) {+fun DailyLevelPage(+    backStack: NavBackStack<Route>,+    viewModel: UnblockJamViewModel,+) {     val dailyPack by viewModel.dailyPack.collectAsState()     val dailyStats by viewModel.dailyStats.collectAsState() @@ -279,18 +299,22 @@ fun DailyLevelPage(backStack: NavBackStack<Route>, viewModel: UnblockJamViewMode         pack = pack,         levelStats = dailyStats,         title = stringResource(UiR.string.daily_challenge),-        onOpenLevel = { backStack.add(Route.DailyGame(it)) }+        onOpenLevel = { backStack.add(Route.DailyGame(it)) },     ) }  /** Binds [UnblockJamViewModel] to the stateless [LevelScreen]. */ @Composable-fun LevelPage(backStack: NavBackStack<Route>, viewModel: UnblockJamViewModel, packIndex: Int) {+fun LevelPage(+    backStack: NavBackStack<Route>,+    viewModel: UnblockJamViewModel,+    packIndex: Int,+) {     val levelStats by viewModel.levelStats.collectAsState()     LevelScreen(-        pack = LevelPack.PACKS[packIndex],+        pack = LevelPack.packs[packIndex],         levelStats = levelStats,-        onOpenLevel = { backStack.add(Route.Game(packIndex, it)) }+        onOpenLevel = { backStack.add(Route.Game(packIndex, it)) },     ) } @@ -305,7 +329,7 @@ fun LevelScreen(     pack: LevelPack,     levelStats: Map<String, LevelStats>,     onOpenLevel: (Int) -> Unit,-    title: String = stringResource(R.string.level_selector)+    title: String = stringResource(R.string.level_selector), ) {     AppScaffold(title = title) { paddingValues ->         LazyVerticalGrid(@@ -318,14 +342,14 @@ fun LevelScreen(             itemsIndexed(pack.levels) { index, levelData ->                 Card(                     Modifier.fillMaxWidth().clickable { onOpenLevel(index) },-                    colors = CardDefaults.cardColors(MaterialTheme.colorScheme.surface)+                    colors = CardDefaults.cardColors(MaterialTheme.colorScheme.surface),                 ) {                     Box(Modifier.fillMaxSize().padding(8.dp)) {                         Text("${index + 1}", Modifier.align(Alignment.Center))                         val levelStat = levelStats[levelData.id]                         Box(                             Modifier.size(20.dp).align(Alignment.CenterEnd),-                            Alignment.Center+                            Alignment.Center,                         ) {                             when {                                 levelStat == null -> return@Box@@ -342,14 +366,19 @@ fun LevelScreen(  /** Binds [UnblockJamViewModel] to the stateless [GameScreen]. */ @Composable-fun GamePage(backStack: NavBackStack<Route>, viewModel: UnblockJamViewModel, packIndex: Int, levelIndex: Int) {+fun GamePage(+    backStack: NavBackStack<Route>,+    viewModel: UnblockJamViewModel,+    packIndex: Int,+    levelIndex: Int,+) {     val uiState by viewModel.uiState.collectAsState()     val packStats by viewModel.levelStats.collectAsState()     val dailyStats by viewModel.dailyStats.collectAsState()     val dailyPack by viewModel.dailyPack.collectAsState()      val isDaily = packIndex == UnblockJamViewModel.DAILY_PACK_INDEX-    val levels = if (isDaily) dailyPack?.levels else LevelPack.PACKS[packIndex].levels+    val levels = if (isDaily) dailyPack?.levels else LevelPack.packs[packIndex].levels     val levelStats = if (isDaily) dailyStats else packStats      // Restoring straight onto a daily level can outrun pack generation.@@ -365,39 +394,42 @@ fun GamePage(backStack: NavBackStack<Route>, viewModel: UnblockJamViewModel, pac         return     } -    val isReady = uiState.packIndex == packIndex &&+    val isReady =+        uiState.packIndex == packIndex &&             uiState.levelIndex == levelIndex &&             uiState.currentLevelData != null     val currentLevelData = if (isReady) uiState.currentLevelData!! else startingLevelData     val currentLevelStats = levelStats[startingLevelData.id]      // Everything except level navigation is the ViewModel's; that one is the back stack's.-    val actions = remember(viewModel, backStack, packIndex, levels.lastIndex) {-        object : GameActions by viewModel {-            override fun onLevelChange(newIndex: Int) {-                val clamped = newIndex.coerceIn(0, levels.lastIndex)-                backStack.setLast(-                    if (isDaily) Route.DailyGame(clamped) else Route.Game(packIndex, clamped)-                )-            }+    val actions =+        remember(viewModel, backStack, packIndex, levels.lastIndex) {+            object : GameActions by viewModel {+                override fun onLevelChange(newIndex: Int) {+                    val clamped = newIndex.coerceIn(0, levels.lastIndex)+                    backStack.setLast(+                        if (isDaily) Route.DailyGame(clamped) else Route.Game(packIndex, clamped),+                    )+                } -            override fun onBackToPacks() = backStack.popToPacks()+                override fun onBackToPacks() = backStack.popToPacks()+            }         }-    }      GameScreen(-        state = GameUiState(-            levelData = currentLevelData,-            levelIndex = levelIndex,-            maxLevelIndex = levels.lastIndex,-            moves = if (isReady) viewModel.getCurrentMoves() else 0,-            bestScore = currentLevelStats?.bestScore,-            isCompleted = currentLevelStats != null,-            isLevelWon = isReady && uiState.isLevelWon,-            canUndo = isReady && uiState.history.isNotEmpty()-        ),+        state =+            GameUiState(+                levelData = currentLevelData,+                levelIndex = levelIndex,+                maxLevelIndex = levels.lastIndex,+                moves = if (isReady) viewModel.getCurrentMoves() else 0,+                bestScore = currentLevelStats?.bestScore,+                isCompleted = currentLevelStats != null,+                isLevelWon = isReady && uiState.isLevelWon,+                canUndo = isReady && uiState.history.isNotEmpty(),+            ),         actions = actions,-        onBack = { backStack.pop() }+        onBack = { backStack.pop() },     ) } @@ -407,17 +439,22 @@ fun GamePage(backStack: NavBackStack<Route>, viewModel: UnblockJamViewModel, pac  */ @OptIn(ExperimentalMaterial3Api::class) @Composable-fun GameScreen(state: GameUiState, actions: GameActions, onBack: () -> Unit) {+fun GameScreen(+    state: GameUiState,+    actions: GameActions,+    onBack: () -> Unit,+) {     // Restart throws away every move on the puzzle, so it asks first, as Pipes does. The buttons     // get actions whose onRestart opens the dialog; only confirming reaches the real one.     var confirmRestart by remember { mutableStateOf(false) }-    val screenActions = remember(actions) {-        object : GameActions by actions {-            override fun onRestart() {-                confirmRestart = true+    val screenActions =+        remember(actions) {+            object : GameActions by actions {+                override fun onRestart() {+                    confirmRestart = true+                }             }         }-    }     if (confirmRestart) {         ConfirmDialog(             title = stringResource(R.string.restart_confirm_title),@@ -435,13 +472,14 @@ fun GameScreen(state: GameUiState, actions: GameActions, onBack: () -> Unit) {     ) { innerPadding ->         Surface(             modifier = Modifier.fillMaxSize(),-            color = MaterialTheme.colorScheme.background+            color = MaterialTheme.colorScheme.background,         ) {             BoxWithConstraints(-                modifier = Modifier-                    .fillMaxSize()-                    .padding(innerPadding)-                    .padding(16.dp)+                modifier =+                    Modifier+                        .fillMaxSize()+                        .padding(innerPadding)+                        .padding(16.dp),             ) {                 if (maxWidth > maxHeight) {                     LandscapeGameLayout(state, screenActions)@@ -454,7 +492,10 @@ fun GameScreen(state: GameUiState, actions: GameActions, onBack: () -> Unit) { }  @Composable-private fun GameInfoBoxes(state: GameUiState, actions: GameActions) {+private fun GameInfoBoxes(+    state: GameUiState,+    actions: GameActions,+) {     LevelPickerBox(         levelIndex = state.levelIndex,         maxLevelIndex = state.maxLevelIndex,@@ -466,24 +507,27 @@ private fun GameInfoBoxes(state: GameUiState, actions: GameActions) {     MovesBox(         moves = state.moves,         bestScore = state.bestScore,-        optimalMoves = state.levelData.optimalMoves+        optimalMoves = state.levelData.optimalMoves,     ) }  @Composable-private fun GameActionButtons(state: GameUiState, actions: GameActions) {+private fun GameActionButtons(+    state: GameUiState,+    actions: GameActions,+) {     // While playing show Undo/Restart; once solved they're replaced by the     // "next level" button in the same row.     if (!state.isLevelWon) {         Button(             onClick = { actions.onUndo() },-            enabled = state.canUndo+            enabled = state.canUndo,         ) {             Text(stringResource(UiR.string.undo))         }         Button(             onClick = { actions.onRestart() },-            enabled = state.canUndo+            enabled = state.canUndo,         ) {             Text(stringResource(UiR.string.restart))         }@@ -501,15 +545,18 @@ private fun GameActionButtons(state: GameUiState, actions: GameActions) { }  @Composable-private fun LandscapeGameLayout(state: GameUiState, actions: GameActions) {+private fun LandscapeGameLayout(+    state: GameUiState,+    actions: GameActions,+) {     Row(         modifier = Modifier.fillMaxSize(),         horizontalArrangement = Arrangement.spacedBy(16.dp),-        verticalAlignment = Alignment.CenterVertically+        verticalAlignment = Alignment.CenterVertically,     ) {         Box(             modifier = Modifier.weight(1f).fillMaxHeight(),-            contentAlignment = Alignment.Center+            contentAlignment = Alignment.Center,         ) {             GameBoard(                 levelData = state.levelData,@@ -521,7 +568,7 @@ private fun LandscapeGameLayout(state: GameUiState, actions: GameActions) {         }         Column(             horizontalAlignment = Alignment.CenterHorizontally,-            verticalArrangement = Arrangement.spacedBy(16.dp)+            verticalArrangement = Arrangement.spacedBy(16.dp),         ) {             GameInfoBoxes(state, actions)             Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {@@ -532,22 +579,25 @@ private fun LandscapeGameLayout(state: GameUiState, actions: GameActions) { }  @Composable-private fun PortraitGameLayout(state: GameUiState, actions: GameActions) {+private fun PortraitGameLayout(+    state: GameUiState,+    actions: GameActions,+) {     Column(         modifier = Modifier.fillMaxSize(),         horizontalAlignment = Alignment.CenterHorizontally,-        verticalArrangement = Arrangement.spacedBy(16.dp)+        verticalArrangement = Arrangement.spacedBy(16.dp),     ) {         Row(             modifier = Modifier.fillMaxWidth(),             horizontalArrangement = Arrangement.SpaceAround,-            verticalAlignment = Alignment.CenterVertically+            verticalAlignment = Alignment.CenterVertically,         ) {             GameInfoBoxes(state, actions)         }         Box(             modifier = Modifier.weight(1f).fillMaxWidth(),-            contentAlignment = Alignment.Center+            contentAlignment = Alignment.Center,         ) {             GameBoard(                 levelData = state.levelData,@@ -559,7 +609,7 @@ private fun PortraitGameLayout(state: GameUiState, actions: GameActions) {         }         Row(             modifier = Modifier.fillMaxWidth(),-            horizontalArrangement = Arrangement.SpaceEvenly+            horizontalArrangement = Arrangement.SpaceEvenly,         ) {             GameActionButtons(state, actions)         }
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Route.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Route.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Route.ktindex cded476779..ccd551fff0 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Route.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Route.kt@@ -9,21 +9,34 @@ sealed interface Route : NavKey {     /** Pack list destination. */     @Serializable     data object PackSelector : Route+     /** Level grid for one pack. */     @Serializable-    data class LevelSelector(val packIndex: Int) : Route+    data class LevelSelector(+        val packIndex: Int,+    ) : Route+     /** Board for one level in a pack. */     @Serializable-    data class Game(val packIndex: Int, val levelIndex: Int) : Route+    data class Game(+        val packIndex: Int,+        val levelIndex: Int,+    ) : Route+     /** Daily challenge level list destination. */     @Serializable     data object DailySelector : Route+     /** Board for one daily challenge level. */     @Serializable-    data class DailyGame(val levelIndex: Int) : Route+    data class DailyGame(+        val levelIndex: Int,+    ) : Route+     /** Games Hub and achievements destination. */     @Serializable     data object GameCenter : Route+     /** Daily reminder settings destination. */     @Serializable     data object Settings : Route
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/CompletedLevelsRepository.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/CompletedLevelsRepository.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/CompletedLevelsRepository.ktindex cf6c5b47b6..d32760a844 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/CompletedLevelsRepository.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/CompletedLevelsRepository.kt@@ -4,10 +4,14 @@ import android.content.Context import com.vayunmathur.library.util.LevelStatsRepository  /** Persistent level statistics and move/undo counters for Unblock Jam. */-class CompletedLevelsRepository(context: Context) : LevelStatsRepository(context) {+class CompletedLevelsRepository(+    context: Context,+) : LevelStatsRepository(context) {     fun incrementTotalMoves() = incrementCounter("total_moves")+     fun getTotalMoves(): Int = getCounter("total_moves")      fun incrementUndoCount() = incrementCounter("undo_count")+     fun getUndoCount(): Int = getCounter("undo_count") }
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/DailyLevelGenerator.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/DailyLevelGenerator.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/DailyLevelGenerator.ktindex f86fbbb9ab..47816db2fe 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/DailyLevelGenerator.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/DailyLevelGenerator.kt@@ -15,25 +15,28 @@ import kotlin.random.Random  * Exploring a state space per candidate is not cheap — run this off the main thread.  */ object DailyLevelGenerator {-     const val LEVELS_PER_DAY = 5      private const val BOARD_SIZE = 6     private const val MAIN_LENGTH = 2      /** Preferred optimal-move band per level in the day, giving a difficulty ramp. */-    private val DIFFICULTY_BANDS = listOf(-        3..5,-        6..8,-        9..11,-        12..13,-        14..60,-    )+    private val DIFFICULTY_BANDS =+        listOf(+            3..5,+            6..8,+            9..11,+            12..13,+            14..60,+        )      /** How many blocks besides the main one to place, per level in the day. */     private val BLOCK_COUNTS = listOf(7, 9, 11, 11, 11) -    fun levelId(day: Long, index: Int) = "daily_${day}_$index"+    fun levelId(+        day: Long,+        index: Int,+    ) = "daily_${day}_$index"      /** Null only if every layout for a level was unsolvable, which should not happen in practice. */     fun packFor(day: Long): LevelPack? {@@ -42,12 +45,13 @@ object DailyLevelGenerator {             val band = DIFFICULTY_BANDS[index]             // Keep the ramp rising even when the previous level overshot its band.             val floor = maxOf(band.first, (levels.lastOrNull()?.optimalMoves ?: 0) + 1)-            val level = levelFor(-                baseSeed = SEED_OFFSET + day * 100 + index,-                blockCount = BLOCK_COUNTS[index],-                band = floor..maxOf(band.last, floor),-                id = levelId(day, index)-            ) ?: return null+            val level =+                levelFor(+                    baseSeed = SEED_OFFSET + day * 100 + index,+                    blockCount = BLOCK_COUNTS[index],+                    band = floor..maxOf(band.last, floor),+                    id = levelId(day, index),+                ) ?: return null             levels.add(level)         }         return LevelPack(name = "daily_$day", levels = levels)@@ -58,15 +62,21 @@ object DailyLevelGenerator {      * hardest puzzle seen across all attempts, so a day always gets its pack even when the band      * turns out to be unreachable for the sets that came up.      */-    private fun levelFor(baseSeed: Long, blockCount: Int, band: IntRange, id: String): LevelData? {+    private fun levelFor(+        baseSeed: Long,+        blockCount: Int,+        band: IntRange,+        id: String,+    ): LevelData? {         var fallback: LevelData? = null         for (attempt in 0 until MAX_ATTEMPTS) {-            val best = hardestUpTo(-                random = Random(baseSeed + attempt * SEED_BUMP),-                blockCount = blockCount,-                cap = band.last,-                id = id-            ) ?: continue+            val best =+                hardestUpTo(+                    random = Random(baseSeed + attempt * SEED_BUMP),+                    blockCount = blockCount,+                    cap = band.last,+                    id = id,+                ) ?: continue             if (best.optimalMoves in band) return best             if (best.optimalMoves > (fallback?.optimalMoves ?: 1)) fallback = best         }@@ -77,7 +87,12 @@ object DailyLevelGenerator {      * Lays out one random set of pieces and returns the hardest arrangement of them needing at      * most [cap] moves, or null if the set cannot be solved at all.      */-    private fun hardestUpTo(random: Random, blockCount: Int, cap: Int, id: String): LevelData? {+    private fun hardestUpTo(+        random: Random,+        blockCount: Int,+        cap: Int,+        id: String,+    ): LevelData? {         val layout = randomLayout(random, blockCount, id) ?: return null         val exploration = RushHourSolver.explore(layout, MAX_STATES) ?: return null @@ -97,15 +112,20 @@ object DailyLevelGenerator {     }      /** A random legal placement of the main block plus [blockCount] others. */-    private fun randomLayout(random: Random, blockCount: Int, id: String): LevelData? {+    private fun randomLayout(+        random: Random,+        blockCount: Int,+        id: String,+    ): LevelData? {         val exitRow = random.nextInt(BOARD_SIZE)-        val blocks = mutableListOf(-            Block(-                position = Coord(random.nextInt(BOARD_SIZE - MAIN_LENGTH), exitRow),-                dimension = Dimension(MAIN_LENGTH, 1),-                fixed = false+        val blocks =+            mutableListOf(+                Block(+                    position = Coord(random.nextInt(BOARD_SIZE - MAIN_LENGTH), exitRow),+                    dimension = Dimension(MAIN_LENGTH, 1),+                    fixed = false,+                ),             )-        )          var placed = 0         var tries = 0@@ -120,26 +140,35 @@ object DailyLevelGenerator {             dimension = Dimension(BOARD_SIZE, BOARD_SIZE),             exit = Coord(BOARD_SIZE, exitRow),             blocks = blocks,-            optimalMoves = 0+            optimalMoves = 0,         )     } -    private fun overlapsAny(block: Block, others: List<Block>): Boolean = others.any { other ->-        block.position.x < other.position.x + other.dimension.width &&-            block.position.x + block.dimension.width > other.position.x &&-            block.position.y < other.position.y + other.dimension.height &&-            block.position.y + block.dimension.height > other.position.y-    }+    private fun overlapsAny(+        block: Block,+        others: List<Block>,+    ): Boolean =+        others.any { other ->+            block.position.x < other.position.x + other.dimension.width &&+                block.position.x + block.dimension.width > other.position.x &&+                block.position.y < other.position.y + other.dimension.height &&+                block.position.y + block.dimension.height > other.position.y+        }      /** One placement attempt: false when the candidate overlaps or sits on the exit row. */-    private fun tryPlaceBlock(random: Random, blocks: MutableList<Block>, exitRow: Int): Boolean {+    private fun tryPlaceBlock(+        random: Random,+        blocks: MutableList<Block>,+        exitRow: Int,+    ): Boolean {         val horizontal = random.nextBoolean()         val size = if (random.nextInt(LONG_BLOCK_ODDS) == 0) LONG_BLOCK_SIZE else SHORT_BLOCK_SIZE         val dim = if (horizontal) Dimension(size, 1) else Dimension(1, size)-        val position = Coord(-            random.nextInt(BOARD_SIZE - dim.width + 1),-            random.nextInt(BOARD_SIZE - dim.height + 1)-        )+        val position =+            Coord(+                random.nextInt(BOARD_SIZE - dim.width + 1),+                random.nextInt(BOARD_SIZE - dim.height + 1),+            )         val block = Block(position, dim, fixed = false)         if (overlapsAny(block, blocks)) return false         // A horizontal block on the exit row can never be got out of the way, so the board
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/InProgressBoards.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/InProgressBoards.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/InProgressBoards.ktindex 4a2b4738aa..bbe7ce43e5 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/InProgressBoards.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/InProgressBoards.kt@@ -13,7 +13,9 @@ import kotlinx.serialization.json.Json  * step; the level itself always comes from the shipped (or generated) data. A save that no longer  * fits its level - a pack update moved a wall, say - is ignored rather than trusted.  */-class InProgressBoards(context: Context) {+class InProgressBoards(+    context: Context,+) {     private val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)      /** The saved board and undo history for [level], or null if there is none or it does not fit. */@@ -26,7 +28,10 @@ class InProgressBoards(context: Context) {     }      /** Remembers [current] and its undo [history] for the level they belong to. */-    fun save(current: LevelData, history: List<LevelData>) {+    fun save(+        current: LevelData,+        history: List<LevelData>,+    ) {         val saved = SavedBoard(current = current.toStep(), history = history.map { it.toStep() })         prefs.edit { putString(current.id, Json.encodeToString(saved)) }     }@@ -49,10 +54,16 @@ class InProgressBoards(context: Context) { }  /** A restored board: [current] as it was left, and the undo steps that led to it, oldest first. */-data class SavedProgress(val current: LevelData, val history: List<LevelData>)+data class SavedProgress(+    val current: LevelData,+    val history: List<LevelData>,+)  @Serializable-private data class SavedBoard(val current: SavedStep, val history: List<SavedStep>)+private data class SavedBoard(+    val current: SavedStep,+    val history: List<SavedStep>,+)  /**  * One board: block positions as `[x, y]` in level order, and which block moved last - the@@ -60,10 +71,12 @@ private data class SavedBoard(val current: SavedStep, val history: List<SavedSte  * restored without it would count the next drag of that block as a new move.  */ @Serializable-private data class SavedStep(val blocks: List<List<Int>>, val lastMoved: Int? = null)+private data class SavedStep(+    val blocks: List<List<Int>>,+    val lastMoved: Int? = null,+) -private fun LevelData.toStep() =-    SavedStep(blocks.map { listOf(it.position.x, it.position.y) }, lastMovedBlockIndex)+private fun LevelData.toStep() = SavedStep(blocks.map { listOf(it.position.x, it.position.y) }, lastMovedBlockIndex)  /**  * [level] with its blocks moved to this step's positions, or null if they do not describe a legal board@@ -71,25 +84,36 @@ private fun LevelData.toStep() =  */ private fun SavedStep.applyTo(level: LevelData): LevelData? {     if (blocks.size != level.blocks.size || blocks.any { it.size != 2 }) return null-    val moved = level.blocks.mapIndexed { i, block ->-        val (x, y) = blocks[i]-        val offAxis = if (block.dimension.width > block.dimension.height) y != block.position.y-        else x != block.position.x-        val fixedMoved = block.fixed && Coord(x, y) != block.position-        if (offAxis || fixedMoved) return null-        block.copy(position = Coord(x, y))-    }-    val legal = moved.indices.all { i ->-        val block = moved[i]-        val inside = block.position.x >= 0 && block.position.y >= 0 &&-            block.position.x + block.dimension.width <= level.dimension.width &&-            block.position.y + block.dimension.height <= level.dimension.height-        inside && moved.indices.none { j -> j != i && overlaps(block, moved[j]) }-    }+    val moved =+        level.blocks.mapIndexed { i, block ->+            val (x, y) = blocks[i]+            val offAxis =+                if (block.dimension.width > block.dimension.height) {+                    y != block.position.y+                } else {+                    x != block.position.x+                }+            val fixedMoved = block.fixed && Coord(x, y) != block.position+            if (offAxis || fixedMoved) return null+            block.copy(position = Coord(x, y))+        }+    val legal =+        moved.indices.all { i ->+            val block = moved[i]+            val inside =+                block.position.x >= 0 &&+                    block.position.y >= 0 &&+                    block.position.x + block.dimension.width <= level.dimension.width &&+                    block.position.y + block.dimension.height <= level.dimension.height+            inside && moved.indices.none { j -> j != i && overlaps(block, moved[j]) }+        }     return if (legal) level.copy(blocks = moved, lastMovedBlockIndex = lastMoved) else null } -private fun overlaps(a: Block, b: Block): Boolean =+private fun overlaps(+    a: Block,+    b: Block,+): Boolean =     a.position.x < b.position.x + b.dimension.width &&         a.position.x + a.dimension.width > b.position.x &&         a.position.y < b.position.y + b.dimension.height &&
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/LevelData.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/LevelData.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/LevelData.ktindex 55e5666d99..4ff192afcb 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/LevelData.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/data/LevelData.kt@@ -2,8 +2,8 @@ package com.vayunmathur.games.unblockjam.data import android.content.Context import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObject-import kotlinx.serialization.json.int import kotlinx.serialization.json.boolean+import kotlinx.serialization.json.int import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive@@ -11,39 +11,40 @@ import kotlinx.serialization.json.jsonPrimitive /** A cell coordinate on the board. */ data class Coord(     val x: Int,-    val y: Int+    val y: Int, )  /** Board size in cells. */ data class Dimension(     val width: Int,-    val height: Int+    val height: Int, )  /** A sliding block: its top-left position, size, and whether it is fixed. */ data class Block(     val position: Coord, // top left     val dimension: Dimension,-    val fixed: Boolean+    val fixed: Boolean, )  /** A named set of levels with an optional colour scheme. */ data class LevelPack(     val name: String,     val levels: List<LevelData>,-    val colorScheme: PackColorScheme? = null+    val colorScheme: PackColorScheme? = null, ) {     /** Shipped pack files and the loaded pack registry. */     companion object {-        private val PACK_FILES = listOf(-            "original_pack.json",-            "walls_1_pack.json",-            "walls_2_pack.json",-            "walls_3_pack.json",-            "size_7_pack.json",-            "size_8_pack.json",-            "size_9_pack.json"-        )+        private val PACK_FILES =+            listOf(+                "original_pack.json",+                "walls_1_pack.json",+                "walls_2_pack.json",+                "walls_3_pack.json",+                "size_7_pack.json",+                "size_8_pack.json",+                "size_9_pack.json",+            )          /** The wall packs share one combined completion achievement. */         val WALL_PACK_INDICES: List<Int> =@@ -53,13 +54,19 @@ data class LevelPack(         val SIZE_PACK_INDICES: List<Int> =             PACK_FILES.indices.filter { PACK_FILES[it].startsWith("size_") } -        var PACKS: List<LevelPack> = listOf()+        var packs: List<LevelPack> = listOf()             private set          fun init(context: Context) {-            PACKS = PACK_FILES.map { filename ->-                packFromJson(context.assets.open(filename).bufferedReader().readText())-            }+            packs =+                PACK_FILES.map { filename ->+                    packFromJson(+                        context.assets+                            .open(filename)+                            .bufferedReader()+                            .readText(),+                    )+                }         }     } }@@ -71,7 +78,7 @@ data class LevelData(     val exit: Coord,     val blocks: List<Block>,     val optimalMoves: Int,-    val lastMovedBlockIndex: Int? = null+    val lastMovedBlockIndex: Int? = null, )  /** Per-pack board colours as ARGB values. */@@ -88,64 +95,79 @@ data class PackColorScheme(     val onTertiary: Long = 0xFFFFFFFF,     val onBackground: Long = 0xFFFFFFFF,     val onSurface: Long = 0xFFFFFFFF,-    val error: Long = 0xFFFF0000+    val error: Long = 0xFFFF0000, )  internal fun packFromJson(json: String): LevelPack {     val jsonObject = Json.parseToJsonElement(json).jsonObject-    val colors = jsonObject["colors"]?.jsonObject?.let {-        fun parseColor(key: String, default: Long): Long =-            it[key]?.jsonPrimitive?.content-                ?.removePrefix("0x")?.removePrefix("#")-                ?.toLongOrNull(16) ?: default-        PackColorScheme(-            primary = parseColor("primary", 0xFF3D3021),-            secondary = parseColor("secondary", 0xFF4A3B2A),-            tertiary = parseColor("tertiary", 0xFF8B7E6A),-            background = parseColor("background", 0xFF4A3B2A),-            surface = parseColor("surface", 0xFF3D3021),-            primaryContainer = parseColor("primaryContainer", 0xFFFFA500),-            secondaryContainer = parseColor("secondaryContainer", 0xFF6F5E55),-            onPrimary = parseColor("onPrimary", 0xFFFFFFFF),-            onSecondary = parseColor("onSecondary", 0xFFFFFFFF),-            onTertiary = parseColor("onTertiary", 0xFFFFFFFF),-            onBackground = parseColor("onBackground", 0xFFFFFFFF),-            onSurface = parseColor("onSurface", 0xFFFFFFFF),-            error = parseColor("error", 0xFFFF0000)-        )-    }-    return LevelPack(jsonObject["name"]!!.jsonPrimitive.content, jsonObject["levels"]!!.jsonArray.map {-        fromJson(it.jsonObject)-    }, colors)+    val colors =+        jsonObject["colors"]?.jsonObject?.let {+            fun parseColor(+                key: String,+                default: Long,+            ): Long =+                it[key]+                    ?.jsonPrimitive+                    ?.content+                    ?.removePrefix("0x")+                    ?.removePrefix("#")+                    ?.toLongOrNull(16) ?: default+            PackColorScheme(+                primary = parseColor("primary", 0xFF3D3021),+                secondary = parseColor("secondary", 0xFF4A3B2A),+                tertiary = parseColor("tertiary", 0xFF8B7E6A),+                background = parseColor("background", 0xFF4A3B2A),+                surface = parseColor("surface", 0xFF3D3021),+                primaryContainer = parseColor("primaryContainer", 0xFFFFA500),+                secondaryContainer = parseColor("secondaryContainer", 0xFF6F5E55),+                onPrimary = parseColor("onPrimary", 0xFFFFFFFF),+                onSecondary = parseColor("onSecondary", 0xFFFFFFFF),+                onTertiary = parseColor("onTertiary", 0xFFFFFFFF),+                onBackground = parseColor("onBackground", 0xFFFFFFFF),+                onSurface = parseColor("onSurface", 0xFFFFFFFF),+                error = parseColor("error", 0xFFFF0000),+            )+        }+    return LevelPack(+        jsonObject["name"]!!.jsonPrimitive.content,+        jsonObject["levels"]!!.jsonArray.map {+            fromJson(it.jsonObject)+        },+        colors,+    ) }  private fun fromJson(json: JsonObject): LevelData {     val id = json["id"]!!.jsonPrimitive.content-    val dimension = Dimension(-        json["w"]!!.jsonPrimitive.int,-        json["h"]!!.jsonPrimitive.int-    )-    val exitObj = json["e"]!!.jsonObject-    val exit = Coord(-        exitObj["x"]!!.jsonPrimitive.int,-        dimension.height - exitObj["y"]!!.jsonPrimitive.int - 1-    )-    val blocks = json["b"]!!.jsonArray.map {-        val block = it.jsonObject-        val blockDim = Dimension(-            block["w"]!!.jsonPrimitive.int,-            block["h"]!!.jsonPrimitive.int+    val dimension =+        Dimension(+            json["w"]!!.jsonPrimitive.int,+            json["h"]!!.jsonPrimitive.int,         )-        val y = block["y"]?.jsonPrimitive?.int ?: 0-        Block(-            Coord(-                block["x"]?.jsonPrimitive?.int ?: 0,-                dimension.height - y - blockDim.height-            ),-            blockDim,-            block["fixed"]?.jsonPrimitive?.boolean ?: false+    val exitObj = json["e"]!!.jsonObject+    val exit =+        Coord(+            exitObj["x"]!!.jsonPrimitive.int,+            dimension.height - exitObj["y"]!!.jsonPrimitive.int - 1,         )-    }+    val blocks =+        json["b"]!!.jsonArray.map {+            val block = it.jsonObject+            val blockDim =+                Dimension(+                    block["w"]!!.jsonPrimitive.int,+                    block["h"]!!.jsonPrimitive.int,+                )+            val y = block["y"]?.jsonPrimitive?.int ?: 0+            Block(+                Coord(+                    block["x"]?.jsonPrimitive?.int ?: 0,+                    dimension.height - y - blockDim.height,+                ),+                blockDim,+                block["fixed"]?.jsonPrimitive?.boolean ?: false,+            )+        }     val optimalMoves = json["c"]!!.jsonPrimitive.int     return LevelData(id, dimension, exit, blocks, optimalMoves) }
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/domain/RushHourSolver.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/domain/RushHourSolver.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/domain/RushHourSolver.ktindex 4639d58bd3..72becebd14 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/domain/RushHourSolver.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/domain/RushHourSolver.kt@@ -12,7 +12,6 @@ import com.vayunmathur.games.unblockjam.data.LevelData  * changes, so a run of drags on one block collapses into a single move.  */ object RushHourSolver {-     /**      * Every configuration reachable from a level's starting layout, with each one's distance from      * a position the main block can drive out of.@@ -32,18 +31,24 @@ object RushHourSolver {         fun movesToWin(stateIndex: Int): Int = distanceToGoal[stateIndex] + 1          /** Rebuilds a playable level whose starting layout is [stateIndex]. */-        fun levelAt(stateIndex: Int, level: LevelData): LevelData =-            level.copy(blocks = board.blocksFor(states[stateIndex], level.blocks))+        fun levelAt(+            stateIndex: Int,+            level: LevelData,+        ): LevelData = level.copy(blocks = board.blocksFor(states[stateIndex], level.blocks))     }      /** Null when the board is malformed, or when the search hits [maxStates]. */-    fun explore(level: LevelData, maxStates: Int = 200_000): Exploration? {+    fun explore(+        level: LevelData,+        maxStates: Int = 200_000,+    ): Exploration? {         val board = Board.of(level) ?: return null         val start = board.startState(level)          val indexByState = HashMap<Long, Int>()         var states = LongArray(64)         var count = 0+         fun add(state: Long): Boolean {             if (indexByState.putIfAbsent(state, count) != null) return false             if (count == states.size) states = states.copyOf(count * 2)@@ -86,7 +91,10 @@ object RushHourSolver {     }      /** Fewest moves that free the main block, or null if the board cannot be solved. */-    fun optimalMoves(level: LevelData, maxStates: Int = 200_000): Int? {+    fun optimalMoves(+        level: LevelData,+        maxStates: Int = 200_000,+    ): Int? {         val exploration = explore(level, maxStates) ?: return null         if (exploration.distanceToGoal[exploration.startIndex] == UNREACHABLE) return null         return exploration.movesToWin(exploration.startIndex)@@ -109,23 +117,38 @@ object RushHourSolver {     ) {         private val occupied = BooleanArray(width * height) -        private fun index(x: Int, y: Int) = y * width + x+        private fun index(+            x: Int,+            y: Int,+        ) = y * width + x -        private fun positionOf(state: Long, i: Int) =-            ((state ushr (i * BITS_PER_BLOCK)) and POSITION_MASK).toInt()+        private fun positionOf(+            state: Long,+            i: Int,+        ) = ((state ushr (i * BITS_PER_BLOCK)) and POSITION_MASK).toInt() -        private fun withPosition(state: Long, i: Int, position: Int): Long {+        private fun withPosition(+            state: Long,+            i: Int,+            position: Int,+        ): Long {             val shift = i * BITS_PER_BLOCK             return (state and (POSITION_MASK shl shift).inv()) or (position.toLong() shl shift)         } -        private fun fill(state: Long, value: Boolean) {+        private fun fill(+            state: Long,+            value: Boolean,+        ) {             for (i in 0 until n) {                 val primary = positionOf(state, i)                 for (step in 0 until length[i]) {                     for (c in 0 until crossLength[i]) {-                        if (horizontal[i]) occupied[index(primary + step, cross[i] + c)] = value-                        else occupied[index(cross[i] + c, primary + step)] = value+                        if (horizontal[i]) {+                            occupied[index(primary + step, cross[i] + c)] = value+                        } else {+                            occupied[index(cross[i] + c, primary + step)] = value+                        }                     }                 }             }@@ -137,15 +160,19 @@ object RushHourSolver {             // The main block may span several rows: every row it occupies must be clear to             // the edge, not just the top one, or it would drive through a block sitting on             // one of its lower rows.-            val clear = (positionOf(state, 0) + length[0] until width).all { x ->-                (cross[0] until cross[0] + crossLength[0]).none { occupied[index(x, it)] }-            }+            val clear =+                (positionOf(state, 0) + length[0] until width).all { x ->+                    (cross[0] until cross[0] + crossLength[0]).none { occupied[index(x, it)] }+                }             fill(state, false)             return clear         }          /** Writes every one-move successor into [out], returning how many there are. */-        fun successors(state: Long, out: LongArray): Int {+        fun successors(+            state: Long,+            out: LongArray,+        ): Int {             fill(state, true)             var found = 0             for (i in 0 until n) {@@ -156,7 +183,12 @@ object RushHourSolver {             return found         } -        private fun slideMoves(state: Long, i: Int, out: LongArray, found: Int): Int {+        private fun slideMoves(+            state: Long,+            i: Int,+            out: LongArray,+            found: Int,+        ): Int {             var count = 0             for (direction in intArrayOf(-1, 1)) {                 count += slideDirection(state, i, direction, out, found + count)@@ -164,7 +196,13 @@ object RushHourSolver {             return count         } -        private fun slideDirection(state: Long, i: Int, direction: Int, out: LongArray, found: Int): Int {+        private fun slideDirection(+            state: Long,+            i: Int,+            direction: Int,+            out: LongArray,+            found: Int,+        ): Int {             var count = 0             var pos = positionOf(state, i)             while (true) {@@ -177,11 +215,18 @@ object RushHourSolver {             return count         } -        private fun isBlocked(i: Int, entering: Int): Boolean {+        private fun isBlocked(+            i: Int,+            entering: Int,+        ): Boolean {             if (entering < 0 || entering >= limit[i]) return true             for (c in 0 until crossLength[i]) {-                val isOccupied = if (horizontal[i]) occupied[index(entering, cross[i] + c)]-                else occupied[index(cross[i] + c, entering)]+                val isOccupied =+                    if (horizontal[i]) {+                        occupied[index(entering, cross[i] + c)]+                    } else {+                        occupied[index(cross[i] + c, entering)]+                    }                 if (isOccupied) return true             }             return false@@ -191,81 +236,115 @@ object RushHourSolver {             var state = 0L             for (i in 0 until n) {                 val block = level.blocks[i]-                state = withPosition(-                    state, i, if (horizontal[i]) block.position.x else block.position.y-                )+                state =+                    withPosition(+                        state,+                        i,+                        if (horizontal[i]) block.position.x else block.position.y,+                    )             }             return state         } -        fun blocksFor(state: Long, template: List<Block>): List<Block> = template.mapIndexed { i, block ->-            val primary = positionOf(state, i)-            val position =-                if (horizontal[i]) Coord(primary, cross[i]) else Coord(cross[i], primary)-            block.copy(position = position)-        }+        fun blocksFor(+            state: Long,+            template: List<Block>,+        ): List<Block> =+            template.mapIndexed { i, block ->+                val primary = positionOf(state, i)+                val position =+                    if (horizontal[i]) Coord(primary, cross[i]) else Coord(cross[i], primary)+                block.copy(position = position)+            }          companion object {-            fun of(level: LevelData): Board? {+            /** Main-block shape, block count and board extent within the bit-packing bounds. */+            private fun mainAndSizeValid(level: LevelData): Boolean {                 val blocks = level.blocks-                if (blocks.isEmpty()) return null+                if (blocks.isEmpty()) return false                 val main = blocks[0]                 // The main block always slides out along the exit row; anything else is not a                 // Rush Hour board.-                if (main.dimension.width <= main.dimension.height) return null-                if (main.position.y != level.exit.y) return null+                if (main.dimension.width <= main.dimension.height) return false+                if (main.position.y != level.exit.y) return false                 // Bit-packing bound. The shipped pack tops out at 15 blocks on a 6x6.-                if (blocks.size > MAX_BLOCKS) return null-                if (level.dimension.width !in 1..MAX_EXTENT) return null-                if (level.dimension.height !in 1..MAX_EXTENT) return null-                // The board arrays below are indexed by cell, assuming every block is a-                // positive-sized rectangle lying wholly on the board; a block hanging off-                // an edge either crashes that indexing or silently wraps into the next-                // row. Overlapping blocks are not a legal board either.-                for (block in blocks) {+                if (blocks.size > MAX_BLOCKS) return false+                if (level.dimension.width !in 1..MAX_EXTENT ||+                    level.dimension.height !in 1..MAX_EXTENT+                ) {+                    return false+                }+                return true+            }++            /**+             * Every block is a positive-sized rectangle lying wholly on the board; a block+             * hanging off an edge would crash the cell indexing below or silently wrap into+             * the next row.+             */+            private fun blocksFitBoard(level: LevelData): Boolean {+                for (block in level.blocks) {                     val w = block.dimension.width                     val h = block.dimension.height-                    if (w < 1 || h < 1 || w > level.dimension.width || h > level.dimension.height) {-                        return null-                    }-                    if (block.position.x < 0 || block.position.y < 0) return null-                    if (block.position.x > level.dimension.width - w) return null-                    if (block.position.y > level.dimension.height - h) return null+                    if (w < 1 || h < 1) return false+                    if (w > level.dimension.width || h > level.dimension.height) return false+                    if (block.position.x < 0 || block.position.y < 0) return false+                    if (block.position.x > level.dimension.width - w) return false+                    if (block.position.y > level.dimension.height - h) return false                 }+                return true+            }++            /** Overlapping blocks are not a legal board. */+            private fun hasOverlappingBlocks(blocks: List<Block>): Boolean {                 for (i in blocks.indices) {                     for (j in i + 1 until blocks.size) {                         val a = blocks[i]                         val b = blocks[j]-                        val overlap = a.position.x < b.position.x + b.dimension.width &&-                            a.position.x + a.dimension.width > b.position.x &&-                            a.position.y < b.position.y + b.dimension.height &&-                            a.position.y + a.dimension.height > b.position.y-                        if (overlap) return null+                        val overlap =+                            a.position.x < b.position.x + b.dimension.width &&+                                a.position.x + a.dimension.width > b.position.x &&+                                a.position.y < b.position.y + b.dimension.height &&+                                a.position.y + a.dimension.height > b.position.y+                        if (overlap) return true                     }                 }+                return false+            }++            fun of(level: LevelData): Board? {+                if (!mainAndSizeValid(level)) return null+                if (!blocksFitBoard(level)) return null+                if (hasOverlappingBlocks(level.blocks)) return null+                val blocks = level.blocks                  val n = blocks.size-                val horizontal = BooleanArray(n) {-                    blocks[it].dimension.width > blocks[it].dimension.height-                }+                val horizontal =+                    BooleanArray(n) {+                        blocks[it].dimension.width > blocks[it].dimension.height+                    }                 return Board(                     n = n,                     width = level.dimension.width,                     height = level.dimension.height,                     horizontal = horizontal,                     fixed = BooleanArray(n) { blocks[it].fixed },-                    length = IntArray(n) {-                        if (horizontal[it]) blocks[it].dimension.width else blocks[it].dimension.height-                    },-                    cross = IntArray(n) {-                        if (horizontal[it]) blocks[it].position.y else blocks[it].position.x-                    },-                    crossLength = IntArray(n) {-                        if (horizontal[it]) blocks[it].dimension.height else blocks[it].dimension.width-                    },-                    limit = IntArray(n) {-                        if (horizontal[it]) level.dimension.width else level.dimension.height-                    },+                    length =+                        IntArray(n) {+                            if (horizontal[it]) blocks[it].dimension.width else blocks[it].dimension.height+                        },+                    cross =+                        IntArray(n) {+                            if (horizontal[it]) blocks[it].position.y else blocks[it].position.x+                        },+                    crossLength =+                        IntArray(n) {+                            if (horizontal[it]) blocks[it].dimension.height else blocks[it].dimension.width+                        },+                    limit =+                        IntArray(n) {+                            if (horizontal[it]) level.dimension.width else level.dimension.height+                        },                 )             }         }
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockDragGestures.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockDragGestures.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockDragGestures.ktindex 874610677f..e6b5784a2b 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockDragGestures.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockDragGestures.kt@@ -3,11 +3,11 @@ import androidx.compose.foundation.gestures.detectDragGestures import androidx.compose.ui.Modifier import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.unit.DpSize-import kotlin.math.roundToInt import com.vayunmathur.games.unblockjam.data.Block import com.vayunmathur.games.unblockjam.data.Coord import com.vayunmathur.games.unblockjam.data.Dimension import com.vayunmathur.games.unblockjam.data.LevelData+import kotlin.math.roundToInt  private data class AxisParams(     val pos: Int,@@ -17,7 +17,11 @@ private data class AxisParams(     val perpSize: Int, ) -private fun axisParams(block: Block, levelData: LevelData, isHorizontal: Boolean): AxisParams =+private fun axisParams(+    block: Block,+    levelData: LevelData,+    isHorizontal: Boolean,+): AxisParams =     if (isHorizontal) {         AxisParams(             block.position.x,@@ -36,10 +40,15 @@ private fun axisParams(block: Block, levelData: LevelData, isHorizontal: Boolean         )     } -private fun isOccupied(otherBlocks: List<Block>, x: Int, y: Int): Boolean = otherBlocks.any {-    x in it.position.x until it.position.x + it.dimension.width &&-        y in it.position.y until it.position.y + it.dimension.height-}+private fun isOccupied(+    otherBlocks: List<Block>,+    x: Int,+    y: Int,+): Boolean =+    otherBlocks.any {+        x in it.position.x until it.position.x + it.dimension.width &&+            y in it.position.y until it.position.y + it.dimension.height+    }  private fun isClearAt(     otherBlocks: List<Block>,@@ -47,11 +56,17 @@ private fun isClearAt(     perpPos: Int,     perpSize: Int,     primary: Int,-): Boolean = (perpPos until perpPos + perpSize).all { p ->-    if (isHorizontal) !isOccupied(otherBlocks, primary, p) else !isOccupied(otherBlocks, p, primary)-}+): Boolean =+    (perpPos until perpPos + perpSize).all { p ->+        if (isHorizontal) !isOccupied(otherBlocks, primary, p) else !isOccupied(otherBlocks, p, primary)+    } -private fun scanLimit(axis: AxisParams, isClear: (Int) -> Boolean, start: Int, dir: Int): Int {+private fun scanLimit(+    axis: AxisParams,+    isClear: (Int) -> Boolean,+    start: Int,+    dir: Int,+): Int {     var edge = start     while (true) {         val inBounds = if (dir < 0) edge > 0 else edge + axis.size < axis.boardLimit@@ -76,11 +91,12 @@ private fun exitExtension(     // The main block may span several rows: every row it occupies must be clear to the     // edge, not just the top one, or the drag range would extend through a block sitting     // on one of its lower rows.-    val pathClear = (max + axis.size until levelData.dimension.width).all { x ->-        (axis.perpPos until axis.perpPos + axis.perpSize).all { y ->-            !isOccupied(otherBlocks, x, y)+    val pathClear =+        (max + axis.size until levelData.dimension.width).all { x ->+            (axis.perpPos until axis.perpPos + axis.perpSize).all { y ->+                !isOccupied(otherBlocks, x, y)+            }         }-    }     return if (pathClear) levelData.exit.x else max } @@ -89,22 +105,23 @@ private fun findMovementRange(     otherBlocks: List<Block>,     levelData: LevelData,     isMainBlock: Boolean,-    isHorizontal: Boolean+    isHorizontal: Boolean, ): IntRange {     val axis = axisParams(block, levelData, isHorizontal)     val isClear = { primary: Int ->         isClearAt(otherBlocks, isHorizontal, axis.perpPos, axis.perpSize, primary)     }     val min = scanLimit(axis, isClear, axis.pos, -1)-    val max = exitExtension(-        block,-        otherBlocks,-        levelData,-        isHorizontal,-        isMainBlock,-        axis,-        scanLimit(axis, isClear, axis.pos, 1),-    )+    val max =+        exitExtension(+            block,+            otherBlocks,+            levelData,+            isHorizontal,+            isMainBlock,+            axis,+            scanLimit(axis, isClear, axis.pos, 1),+        )     return min..max } @@ -129,7 +146,10 @@ interface BlockPosition {     val y: Float      /** Puts the block under the finger. */-    fun dragTo(x: Float, y: Float)+    fun dragTo(+        x: Float,+        y: Float,+    )      /**      * Lets go: the block glides from wherever the finger left it to wherever the level now puts@@ -139,7 +159,10 @@ interface BlockPosition {     fun release() } -private fun settleAfterDrag(params: DragParams, position: BlockPosition) {+private fun settleAfterDrag(+    params: DragParams,+    position: BlockPosition,+) {     val (newX, newY) = snappedPosition(params, position)     val newBlock = params.block.copy(position = Coord(newX, newY))     when {@@ -149,30 +172,49 @@ private fun settleAfterDrag(params: DragParams, position: BlockPosition) {     position.release() } -private fun snappedPosition(params: DragParams, position: BlockPosition): Pair<Int, Int> =+private fun snappedPosition(+    params: DragParams,+    position: BlockPosition,+): Pair<Int, Int> =     if (params.isHorizontal) {         position.x.roundToInt() to params.block.position.y     } else {         params.block.position.x to position.y.roundToInt()     } -private fun isWinningMove(params: DragParams, newX: Int): Boolean =+private fun isWinningMove(+    params: DragParams,+    newX: Int,+): Boolean =     params.isMainBlock &&         params.block.position.y == params.levelData.exit.y &&         newX >= params.levelData.exit.x -private fun isValidRelocation(params: DragParams, newBlock: Block): Boolean =+private fun isValidRelocation(+    params: DragParams,+    newBlock: Block,+): Boolean =     newBlock.position != params.block.position &&         isMoveValid(newBlock, params.levelData.blocks - params.block, params.levelData.dimension) -private fun applyRelocation(params: DragParams, newBlock: Block) {+private fun applyRelocation(+    params: DragParams,+    newBlock: Block,+) {     val newBlocks = params.levelData.blocks.toMutableList()     newBlocks[params.index] = newBlock     params.onLevelChanged(params.levelData.copy(blocks = newBlocks, lastMovedBlockIndex = params.index)) }  /** Moves the block by a drag of ([dx], [dy]) cells along its axis, within [min]..[max]. */-private fun handleDragDelta(params: DragParams, min: Float, max: Float, position: BlockPosition, dx: Float, dy: Float) {+private fun handleDragDelta(+    params: DragParams,+    min: Float,+    max: Float,+    position: BlockPosition,+    dx: Float,+    dy: Float,+) {     if (!params.isHorizontal) {         position.dragTo(position.x, (position.y + dy).coerceIn(min, max))         return@@ -238,10 +280,14 @@ fun Modifier.blockDragGestures(                 onDrag = { change, dragAmount ->                     change.consume()                     handleDragDelta(-                        params, minOffset, maxOffset, position,-                        dragAmount.x / cellWidthPx, dragAmount.y / cellHeightPx,+                        params,+                        minOffset,+                        maxOffset,+                        position,+                        dragAmount.x / cellWidthPx,+                        dragAmount.y / cellHeightPx,                     )-                }+                },             )         } finally {             if (dragging) position.release()@@ -249,15 +295,19 @@ fun Modifier.blockDragGestures(     } } -fun isMoveValid(movedBlock: Block, otherBlocks: List<Block>, dimension: Dimension): Boolean {+fun isMoveValid(+    movedBlock: Block,+    otherBlocks: List<Block>,+    dimension: Dimension,+): Boolean {     if (movedBlock.position.x < 0 || movedBlock.position.y < 0) return false     if (movedBlock.position.x + movedBlock.dimension.width > dimension.width) return false     if (movedBlock.position.y + movedBlock.dimension.height > dimension.height) return false      return otherBlocks.none { other ->         movedBlock.position.x < other.position.x + other.dimension.width &&-        movedBlock.position.x + movedBlock.dimension.width > other.position.x &&-        movedBlock.position.y < other.position.y + other.dimension.height &&-        movedBlock.position.y + movedBlock.dimension.height > other.position.y+            movedBlock.position.x + movedBlock.dimension.width > other.position.x &&+            movedBlock.position.y < other.position.y + other.dimension.height &&+            movedBlock.position.y + movedBlock.dimension.height > other.position.y     } }
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockStep.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockStep.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockStep.ktindex 6f01df3950..bd893f817a 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockStep.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockStep.kt@@ -7,7 +7,9 @@ import com.vayunmathur.games.unblockjam.data.LevelData /** What sliding a block one cell does: moves it, wins the level, or nothing. */ sealed interface StepResult {     /** The block moved; [level] is the board after the move, with the block as the last moved. */-    data class Moved(val level: LevelData) : StepResult+    data class Moved(+        val level: LevelData,+    ) : StepResult      /** The target block slid out through the exit. */     data object Won : StepResult@@ -24,15 +26,23 @@ fun Block.isHorizontal(): Boolean = dimension.width > dimension.height  * or an arrow key makes, under the same rules as a drag: only along the block's own axis, never  * through another block or off the board, and the target block wins once it slides into the exit.  */-fun stepBlock(levelData: LevelData, index: Int, dx: Int, dy: Int): StepResult {+fun stepBlock(+    levelData: LevelData,+    index: Int,+    dx: Int,+    dy: Int,+): StepResult {     val block = levelData.blocks.getOrNull(index) ?: return StepResult.Blocked     val alongAxis = if (block.isHorizontal()) dy == 0 && dx != 0 else dx == 0 && dy != 0     if (block.fixed || !alongAxis) return StepResult.Blocked      val moved = block.copy(position = Coord(block.position.x + dx, block.position.y + dy))     val isTarget = index == 0-    val intoExit = isTarget && dx > 0 && block.position.y == levelData.exit.y &&-        block.position.x + block.dimension.width >= levelData.exit.x+    val intoExit =+        isTarget &&+            dx > 0 &&+            block.position.y == levelData.exit.y &&+            block.position.x + block.dimension.width >= levelData.exit.x     if (intoExit) return StepResult.Won      if (!isMoveValid(moved, levelData.blocks - block, levelData.dimension)) return StepResult.Blocked
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/GameUiContract.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/GameUiContract.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/GameUiContract.ktindex 596ead2edc..69693fcd04 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/GameUiContract.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/GameUiContract.kt@@ -7,11 +7,9 @@ import com.vayunmathur.games.unblockjam.data.LevelData  *  * The screen takes a state value plus an actions interface rather than the ViewModel itself,  * so it can be rendered by a `@Preview` — which is what the store listing images are- * generated from. It lives in `util` alongside the ViewModel so the dependency runs one way:+ * generated from. It lives in `platform` alongside the ViewModel so the dependency runs one way:  * the screen depends on this contract, and the ViewModel implements it.- */--/**+ *  * Everything the game screen draws. [levelData] is the board as it currently stands, which  * is the loaded level's starting layout until the player moves something.  */@@ -41,8 +39,11 @@ data class DailyProgress(  */ interface GameActions {     fun onBlockMoved(newLevelData: LevelData) {}+     fun onLevelWon() {}+     fun onUndo() {}+     fun onRestart() {}      /**@@ -73,7 +74,11 @@ data class SettingsUiState( /** Settings callbacks. Same no-op-default arrangement as [GameActions]. */ interface SettingsActions {     fun setReminderEnabled(enabled: Boolean) {}-    fun setReminderTime(hour: Int, minute: Int) {}++    fun setReminderTime(+        hour: Int,+        minute: Int,+    ) {}      /** Factories for [SettingsActions]. */     companion object {
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/UnblockJamAchievementsManager.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/UnblockJamAchievementsManager.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/UnblockJamAchievementsManager.ktindex e23cbed538..7876587ad1 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/UnblockJamAchievementsManager.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/UnblockJamAchievementsManager.kt@@ -13,9 +13,8 @@ import kotlinx.coroutines.launch class UnblockJamAchievementsManager(     context: Context,     json: String,-    private val repository: CompletedLevelsRepository+    private val repository: CompletedLevelsRepository, ) : AchievementsManager(context, json) {-     private val dailyStore = DailyChallengeStore(context, "unblockjam_daily")      override fun checkExistingAchievements() {@@ -44,8 +43,11 @@ class UnblockJamAchievementsManager(      // One stats map covers every shipped pack, so its raw size would let one pack's progress     // unlock another pack's achievement.-    private fun completedIn(completed: Set<String>, packs: List<Int>): Int =+    private fun completedIn(+        completed: Set<String>,+        packs: List<Int>,+    ): Int =         packs.sumOf { index ->-            LevelPack.PACKS[index].levels.count { completed.contains(it.id) }+            LevelPack.packs[index].levels.count { completed.contains(it.id) }         } }
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/UnblockJamViewModel.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/UnblockJamViewModel.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/UnblockJamViewModel.ktindex 2e335331c9..10c0b1c29d 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/UnblockJamViewModel.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/UnblockJamViewModel.kt@@ -8,12 +8,12 @@ import com.vayunmathur.games.unblockjam.data.DailyLevelGenerator import com.vayunmathur.games.unblockjam.data.InProgressBoards import com.vayunmathur.games.unblockjam.data.LevelData import com.vayunmathur.games.unblockjam.data.LevelPack-import com.vayunmathur.library.util.LevelStats import com.vayunmathur.library.util.DailyChallengeStore import com.vayunmathur.library.util.DailyStreakReporter+import com.vayunmathur.library.util.LevelStats+import com.vayunmathur.library.util.LevelStatsRepository import com.vayunmathur.library.work.DailyPuzzleReminder import com.vayunmathur.library.work.DailyReminderSettings-import com.vayunmathur.library.util.LevelStatsRepository import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted@@ -52,18 +52,24 @@ data class UnblockJamUiState(  * dialog visibility, and the slide-out animation for the main block when  * a level is won.  */-class UnblockJamViewModel(application: Application) : AndroidViewModel(application), GameActions {-+class UnblockJamViewModel(+    application: Application,+) : AndroidViewModel(application),+    GameActions {     val repository: CompletedLevelsRepository = CompletedLevelsRepository(application)      /** Boards left part-way, restored when their level is opened again. */     private val inProgress = InProgressBoards(application) -    val achievementsManager: UnblockJamAchievementsManager = run {-        val json = application.assets.open("achievements.json")-            .bufferedReader().use { it.readText() }-        UnblockJamAchievementsManager(application, json, repository)-    }+    val achievementsManager: UnblockJamAchievementsManager =+        run {+            val json =+                application.assets+                    .open("achievements.json")+                    .bufferedReader()+                    .use { it.readText() }+            UnblockJamAchievementsManager(application, json, repository)+        }      private val _uiState = MutableStateFlow(UnblockJamUiState())     val uiState: StateFlow<UnblockJamUiState> = _uiState.asStateFlow()@@ -85,11 +91,13 @@ class UnblockJamViewModel(application: Application) : AndroidViewModel(applicati      private val reminderSettings = DailyReminderSettings(application, DAILY_KEY_PREFIX) -    val reminderEnabled: StateFlow<Boolean> = reminderSettings.enabled-        .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false)+    val reminderEnabled: StateFlow<Boolean> =+        reminderSettings.enabled+            .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false) -    val reminderMinutesOfDay: StateFlow<Long> = reminderSettings.minutesOfDay-        .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), DailyPuzzleReminder.DEFAULT_MINUTES_OF_DAY)+    val reminderMinutesOfDay: StateFlow<Long> =+        reminderSettings.minutesOfDay+            .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), DailyPuzzleReminder.DEFAULT_MINUTES_OF_DAY)      fun setReminderEnabled(enabled: Boolean) {         viewModelScope.launch {@@ -98,7 +106,10 @@ class UnblockJamViewModel(application: Application) : AndroidViewModel(applicati         }     } -    fun setReminderTime(hour: Int, minute: Int) {+    fun setReminderTime(+        hour: Int,+        minute: Int,+    ) {         viewModelScope.launch {             val minutes = (hour * 60 + minute).toLong()             reminderSettings.setMinutesOfDay(minutes)@@ -106,7 +117,10 @@ class UnblockJamViewModel(application: Application) : AndroidViewModel(applicati         }     } -    private fun rescheduleReminder(enabled: Boolean, minutesOfDay: Long) {+    private fun rescheduleReminder(+        enabled: Boolean,+        minutesOfDay: Long,+    ) {         DailyPuzzleReminder.update(             context = getApplication(),             keyPrefix = DAILY_KEY_PREFIX,@@ -126,8 +140,9 @@ class UnblockJamViewModel(application: Application) : AndroidViewModel(applicati     private val _dailyStats = MutableStateFlow(dailyRepository.getLevelStats())     val dailyStats: StateFlow<Map<String, LevelStats>> = _dailyStats.asStateFlow() -    val dailyStreak: StateFlow<Long> = dailyStore.currentStreak-        .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), 0L)+    val dailyStreak: StateFlow<Long> =+        dailyStore.currentStreak+            .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), 0L)      /** How many of today's daily levels are solved. Derived from the IDs, so it needs no pack. */     val dailyCompleted: StateFlow<Int> =@@ -167,11 +182,12 @@ class UnblockJamViewModel(application: Application) : AndroidViewModel(applicati             .mapTo(mutableSetOf()) { DailyLevelGenerator.levelId(day, it) }      /** Resolves a pack index to its levels, covering both the shipped packs and the daily pack. */-    private fun levelsFor(packIndex: Int): List<LevelData>? = when (packIndex) {-        DAILY_PACK_INDEX -> _dailyPack.value?.levels-        in LevelPack.PACKS.indices -> LevelPack.PACKS[packIndex].levels-        else -> null-    }+    private fun levelsFor(packIndex: Int): List<LevelData>? =+        when (packIndex) {+            DAILY_PACK_INDEX -> _dailyPack.value?.levels+            in LevelPack.packs.indices -> LevelPack.packs[packIndex].levels+            else -> null+        }      /**      * Loads the requested level if it differs from the currently-loaded one.@@ -184,20 +200,27 @@ class UnblockJamViewModel(application: Application) : AndroidViewModel(applicati      * A level left part-way - by Back, by switching puzzles, or by the process      * being killed - comes back as it was left, undo history included.      */-    fun loadLevel(packIndex: Int, levelIndex: Int) {+    fun loadLevel(+        packIndex: Int,+        levelIndex: Int,+    ) {         if (isPlaying(packIndex, levelIndex)) return         val levelData = levelsFor(packIndex)?.getOrNull(levelIndex) ?: return         val saved = inProgress.load(levelData)-        _uiState.value = UnblockJamUiState(-            packIndex = packIndex,-            levelIndex = levelIndex,-            currentLevelData = saved?.current ?: levelData,-            history = saved?.history.orEmpty(),-        )+        _uiState.value =+            UnblockJamUiState(+                packIndex = packIndex,+                levelIndex = levelIndex,+                currentLevelData = saved?.current ?: levelData,+                history = saved?.history.orEmpty(),+            )     }      /** Whether ([packIndex], [levelIndex]) is already on screen and still being played. */-    private fun isPlaying(packIndex: Int, levelIndex: Int): Boolean {+    private fun isPlaying(+        packIndex: Int,+        levelIndex: Int,+    ): Boolean {         val current = _uiState.value         val sameLevel = current.packIndex == packIndex && current.levelIndex == levelIndex         return sameLevel && current.currentLevelData != null && !current.isLevelWon@@ -251,7 +274,8 @@ class UnblockJamViewModel(application: Application) : AndroidViewModel(applicati             viewModelScope.launch(Dispatchers.IO) {                 repository.incrementTotalMoves()                 achievementsManager.onProgressUpdated(-                    "moves_1000", repository.getTotalMoves(),+                    "moves_1000",+                    repository.getTotalMoves(),                 )             }         } else {@@ -267,7 +291,10 @@ class UnblockJamViewModel(application: Application) : AndroidViewModel(applicati      * taken by a block moved in the meantime — the dragged block stays where it is. A report      * that does not name a moved block of this board is installed as reported.      */-    private fun reconcile(reported: LevelData, current: LevelData): LevelData? {+    private fun reconcile(+        reported: LevelData,+        current: LevelData,+    ): LevelData? {         val index = reported.lastMovedBlockIndex ?: return reported         if (reported.blocks.size != current.blocks.size) return reported         val reportedBlock = reported.blocks.getOrNull(index) ?: return reported@@ -312,13 +339,17 @@ class UnblockJamViewModel(application: Application) : AndroidViewModel(applicati     }      /** Daily wins record into the separate store, and extend the streak once the day is cleared. */-    private fun onDailyLevelWon(level: LevelData, moves: Int) {+    private fun onDailyLevelWon(+        level: LevelData,+        moves: Int,+    ) {         val day = _dailyDay.value         viewModelScope.launch {-            val refreshed = withContext(Dispatchers.IO) {-                dailyRepository.updateBestScore(level.id, moves)-                dailyRepository.getLevelStats()-            }+            val refreshed =+                withContext(Dispatchers.IO) {+                    dailyRepository.updateBestScore(level.id, moves)+                    dailyRepository.getLevelStats()+                }             _dailyStats.value = refreshed              achievementsManager.onAchievementUnlocked("first_daily")@@ -326,8 +357,9 @@ class UnblockJamViewModel(application: Application) : AndroidViewModel(applicati                 achievementsManager.onAchievementUnlocked("optimal_win")             } -            val dayComplete = (0 until DailyLevelGenerator.LEVELS_PER_DAY)-                .all { refreshed.containsKey(DailyLevelGenerator.levelId(day, it)) }+            val dayComplete =+                (0 until DailyLevelGenerator.LEVELS_PER_DAY)+                    .all { refreshed.containsKey(DailyLevelGenerator.levelId(day, it)) }             if (dayComplete) {                 val streak = dailyStore.recordDayCompleted(day)                 achievementsManager.onProgressUpdated("daily_streak_7", streak.best.toInt())@@ -350,7 +382,8 @@ class UnblockJamViewModel(application: Application) : AndroidViewModel(applicati         viewModelScope.launch(Dispatchers.IO) {             repository.incrementUndoCount()             achievementsManager.onProgressUpdated(-                "undo_master", repository.getUndoCount(),+                "undo_master",+                repository.getUndoCount(),             )         }     }
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/Theme.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/Theme.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/Theme.ktindex 97f4da784b..19eb74aa00 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/Theme.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/Theme.kt@@ -1,52 +1,54 @@ package com.vayunmathur.games.unblockjam.ui-import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.darkColorScheme import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color import com.vayunmathur.games.unblockjam.data.LevelPack+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.darkColorScheme -private val CustomDarkColorScheme = darkColorScheme(-    primary = DarkBrown,-    secondary = Brown,-    tertiary = Color.Red,-    background = Brown,-    surface = DarkBrown,-    onPrimary = Color.White,-    onSecondary = Color.White,-    onTertiary = Color.White,-    onBackground = Color.White,-    onSurface = Color.White,-    primaryContainer = Orange,-    secondaryContainer = WarmGray,-    error = Color.Red-)+private val CustomDarkColorScheme =+    darkColorScheme(+        primary = DarkBrown,+        secondary = Brown,+        tertiary = Color.Red,+        background = Brown,+        surface = DarkBrown,+        onPrimary = Color.White,+        onSecondary = Color.White,+        onTertiary = Color.White,+        onBackground = Color.White,+        onSurface = Color.White,+        primaryContainer = Orange,+        secondaryContainer = WarmGray,+        error = Color.Red,+    )  @Composable fun UnblockJamTheme(     pack: LevelPack? = null,-    content: @Composable () -> Unit+    content: @Composable () -> Unit, ) {-    val colorScheme = pack?.colorScheme?.let {-        darkColorScheme(-            primary = Color(it.primary),-            secondary = Color(it.secondary),-            tertiary = Color(it.tertiary),-            background = Color(it.background),-            surface = Color(it.surface),-            onPrimary = Color(it.onPrimary),-            onSecondary = Color(it.onSecondary),-            onTertiary = Color(it.onTertiary),-            onBackground = Color(it.onBackground),-            onSurface = Color(it.onSurface),-            primaryContainer = Color(it.primaryContainer),-            secondaryContainer = Color(it.secondaryContainer),-            error = Color(it.error)-        )-    } ?: CustomDarkColorScheme+    val colorScheme =+        pack?.colorScheme?.let {+            darkColorScheme(+                primary = Color(it.primary),+                secondary = Color(it.secondary),+                tertiary = Color(it.tertiary),+                background = Color(it.background),+                surface = Color(it.surface),+                onPrimary = Color(it.onPrimary),+                onSecondary = Color(it.onSecondary),+                onTertiary = Color(it.onTertiary),+                onBackground = Color(it.onBackground),+                onSurface = Color(it.onSurface),+                primaryContainer = Color(it.primaryContainer),+                secondaryContainer = Color(it.secondaryContainer),+                error = Color(it.error),+            )+        } ?: CustomDarkColorScheme      MaterialTheme(         colorScheme = colorScheme,         typography = Typography,-        content = content+        content = content,     ) }
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/Type.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/Type.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/Type.ktindex f54bba980a..a73b4b9106 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/Type.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/Type.kt@@ -1,16 +1,18 @@ package com.vayunmathur.games.unblockjam.ui-import com.vayunmathur.library.ui.Typography import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.sp+import com.vayunmathur.library.ui.Typography -val Typography = Typography(-    bodyLarge = TextStyle(-        fontFamily = FontFamily.Default,-        fontWeight = FontWeight.Normal,-        fontSize = 16.sp,-        lineHeight = 24.sp,-        letterSpacing = 0.5.sp+val Typography =+    Typography(+        bodyLarge =+            TextStyle(+                fontFamily = FontFamily.Default,+                fontWeight = FontWeight.Normal,+                fontSize = 16.sp,+                lineHeight = 24.sp,+                letterSpacing = 0.5.sp,+            ),     )-)
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/BlockAccessibility.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/BlockAccessibility.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/BlockAccessibility.ktindex 273f189fb0..51ff31a5c6 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/BlockAccessibility.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/BlockAccessibility.kt@@ -36,31 +36,31 @@ internal fun Modifier.blockAccessibility(     movable: Boolean,     interactionSource: MutableInteractionSource,     onStep: (dx: Int, dy: Int) -> Boolean,-): Modifier = this-    .semantics {-        contentDescription = labels.description-        if (movable) {-            customActions = if (horizontal) {-                listOf(-                    CustomAccessibilityAction(labels.left) { onStep(-1, 0) },-                    CustomAccessibilityAction(labels.right) { onStep(1, 0) },-                )-            } else {-                listOf(-                    CustomAccessibilityAction(labels.up) { onStep(0, -1) },-                    CustomAccessibilityAction(labels.down) { onStep(0, 1) },-                )+): Modifier =+    this+        .semantics {+            contentDescription = labels.description+            if (movable) {+                customActions =+                    if (horizontal) {+                        listOf(+                            CustomAccessibilityAction(labels.left) { onStep(-1, 0) },+                            CustomAccessibilityAction(labels.right) { onStep(1, 0) },+                        )+                    } else {+                        listOf(+                            CustomAccessibilityAction(labels.up) { onStep(0, -1) },+                            CustomAccessibilityAction(labels.down) { onStep(0, 1) },+                        )+                    }             }-        }-    }-    .onKeyEvent { event ->-        if (!movable || event.type != KeyEventType.KeyDown) return@onKeyEvent false-        when (event.key) {-            Key.DirectionLeft -> onStep(-1, 0)-            Key.DirectionRight -> onStep(1, 0)-            Key.DirectionUp -> onStep(0, -1)-            Key.DirectionDown -> onStep(0, 1)-            else -> false-        }-    }-    .focusable(enabled = movable, interactionSource = interactionSource)+        }.onKeyEvent { event ->+            if (!movable || event.type != KeyEventType.KeyDown) return@onKeyEvent false+            when (event.key) {+                Key.DirectionLeft -> onStep(-1, 0)+                Key.DirectionRight -> onStep(1, 0)+                Key.DirectionUp -> onStep(0, -1)+                Key.DirectionDown -> onStep(0, 1)+                else -> false+            }+        }.focusable(enabled = movable, interactionSource = interactionSource)
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/GameBlock.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/GameBlock.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/GameBlock.ktindex 6da5489b24..10f97cfde2 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/GameBlock.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/GameBlock.kt@@ -29,9 +29,9 @@ import com.vayunmathur.games.unblockjam.data.Block import com.vayunmathur.games.unblockjam.data.LevelData import com.vayunmathur.games.unblockjam.platform.BlockPosition import com.vayunmathur.games.unblockjam.platform.StepResult+import com.vayunmathur.games.unblockjam.platform.blockDragGestures import com.vayunmathur.games.unblockjam.platform.isHorizontal import com.vayunmathur.games.unblockjam.platform.stepBlock-import com.vayunmathur.games.unblockjam.platform.blockDragGestures import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Motion import com.vayunmathur.library.ui.travelledOffset@@ -51,11 +51,12 @@ internal fun GameBlock(     onLevelWon: () -> Unit, ) {     val isMainBlock = index == 0-    val color = when {-        isMainBlock -> MaterialTheme.colorScheme.tertiary-        block.fixed -> MaterialTheme.colorScheme.secondaryContainer-        else -> MaterialTheme.colorScheme.primaryContainer-    }+    val color =+        when {+            isMainBlock -> MaterialTheme.colorScheme.tertiary+            block.fixed -> MaterialTheme.colorScheme.secondaryContainer+            else -> MaterialTheme.colorScheme.primaryContainer+        }     val markColor = MaterialTheme.colorScheme.onTertiary     val focusColor = MaterialTheme.colorScheme.onBackground     val interactionSource = remember { MutableInteractionSource() }@@ -76,77 +77,87 @@ internal fun GameBlock(     val won = isMainBlock && isLevelWon     // Two cells past the board: through the one-cell exit lane and under the fade beyond it.     val rest = if (won) Offset(levelData.dimension.width + 2f, committed.y) else committed-    val settled = travelledOffset(-        key = levelData.id to trip.id,-        from = trip.from,-        to = rest,-        spec = if (won) Motion.over(WIN_ANIM_MILLIS) else Motion.reorder(),-    )+    val settled =+        travelledOffset(+            key = levelData.id to trip.id,+            from = trip.from,+            to = rest,+            spec = if (won) Motion.over(WIN_ANIM_MILLIS) else Motion.reorder(),+        )     // The drag detector keeps the object it started with, so it reads the settle through this     // rather than capturing the State of whichever trip was current back then.     val latestSettled = rememberUpdatedState(settled)-    val position = remember(levelData.id) {-        object : BlockPosition {-            override val x get() = (drag ?: latestSettled.value.value).x-            override val y get() = (drag ?: latestSettled.value.value).y-            override fun dragTo(x: Float, y: Float) { drag = Offset(x, y) }-            override fun release() {-                val from = drag ?: return-                drag = null-                trip = SettleTrip(trip.id + 1, from)-            }-        }-    }+    val position =+        remember(levelData.id) {+            object : BlockPosition {+                override val x get() = (drag ?: latestSettled.value.value).x+                override val y get() = (drag ?: latestSettled.value.value).y -    var modifier = Modifier-        .size(blockWidth, blockHeight)-        // Read here, in layout, so a drag or a settle never recomposes the block.-        .offset {-            val at = drag ?: latestSettled.value.value-            IntOffset((at.x * cellWidth.toPx()).roundToInt(), (at.y * cellHeight.toPx()).roundToInt())-        }-        // Tagged before the inset, so tests read the block's cell rather than its painted inset.-        .testTag("block_$index")-        .blockAccessibility(-            labels = blockLabels(block, isMainBlock),-            horizontal = block.isHorizontal(),-            movable = !block.fixed && !isLevelWon,-            interactionSource = interactionSource,-        ) { dx, dy ->-            val step = stepBlock(levelData, index, dx, dy)-            when (step) {-                is StepResult.Moved -> onLevelChanged(step.level)-                StepResult.Won -> onLevelWon()-                StepResult.Blocked -> Unit+                override fun dragTo(+                    x: Float,+                    y: Float,+                ) {+                    drag = Offset(x, y)+                }++                override fun release() {+                    val from = drag ?: return+                    drag = null+                    trip = SettleTrip(trip.id + 1, from)+                }             }-            step != StepResult.Blocked         }-        .padding(scaling * BLOCK_INSET_SCALE)-        .background(color, shape = RoundedCornerShape(percent = BLOCK_CORNER_PERCENT))-        // Keyboard focus needs to be visible: an outline on the focused block, over its fill.-        .then(-            if (focused) {-                Modifier.border(FOCUS_OUTLINE, focusColor, RoundedCornerShape(percent = BLOCK_CORNER_PERCENT))-            } else {-                Modifier++    var modifier =+        Modifier+            .size(blockWidth, blockHeight)+            // Read here, in layout, so a drag or a settle never recomposes the block.+            .offset {+                val at = drag ?: latestSettled.value.value+                IntOffset((at.x * cellWidth.toPx()).roundToInt(), (at.y * cellHeight.toPx()).roundToInt())             }-        )-        // The target block carries the exit's chevrons, so it stands out by shape as well as-        // colour: on several pack palettes it was only red against orange, which colour-blind-        // players cannot tell apart.-        .then(if (isMainBlock) Modifier.drawBehind { drawExitChevrons(markColor) } else Modifier)+            // Tagged before the inset, so tests read the block's cell rather than its painted inset.+            .testTag("block_$index")+            .blockAccessibility(+                labels = blockLabels(block, isMainBlock),+                horizontal = block.isHorizontal(),+                movable = !block.fixed && !isLevelWon,+                interactionSource = interactionSource,+            ) { dx, dy ->+                val step = stepBlock(levelData, index, dx, dy)+                when (step) {+                    is StepResult.Moved -> onLevelChanged(step.level)+                    StepResult.Won -> onLevelWon()+                    StepResult.Blocked -> Unit+                }+                step != StepResult.Blocked+            }.padding(scaling * BLOCK_INSET_SCALE)+            .background(color, shape = RoundedCornerShape(percent = BLOCK_CORNER_PERCENT))+            // Keyboard focus needs to be visible: an outline on the focused block, over its fill.+            .then(+                if (focused) {+                    Modifier.border(FOCUS_OUTLINE, focusColor, RoundedCornerShape(percent = BLOCK_CORNER_PERCENT))+                } else {+                    Modifier+                },+            )+            // The target block carries the exit's chevrons, so it stands out by shape as well as+            // colour: on several pack palettes it was only red against orange, which colour-blind+            // players cannot tell apart.+            .then(if (isMainBlock) Modifier.drawBehind { drawExitChevrons(markColor) } else Modifier)      if (!block.fixed) {-        modifier = modifier.blockDragGestures(-            block = block,-            levelData = levelData,-            index = index,-            isLevelWon = isLevelWon,-            cellSize = DpSize(cellWidth, cellHeight),-            position = position,-            onLevelWon = onLevelWon,-            onLevelChanged = onLevelChanged,-        )+        modifier =+            modifier.blockDragGestures(+                block = block,+                levelData = levelData,+                index = index,+                isLevelWon = isLevelWon,+                cellSize = DpSize(cellWidth, cellHeight),+                position = position,+                onLevelWon = onLevelWon,+                onLevelChanged = onLevelChanged,+            )     }      Box(modifier = modifier)@@ -154,23 +165,28 @@ internal fun GameBlock(  /** What TalkBack calls [block] and its moves: kind, size and top-left cell (1-based). */ @Composable-private fun blockLabels(block: Block, isMainBlock: Boolean): BlockLabels {-    val kind = stringResource(-        when {-            isMainBlock -> R.string.cd_target_block-            block.fixed -> R.string.cd_wall-            else -> R.string.cd_block-        }-    )+private fun blockLabels(+    block: Block,+    isMainBlock: Boolean,+): BlockLabels {+    val kind =+        stringResource(+            when {+                isMainBlock -> R.string.cd_target_block+                block.fixed -> R.string.cd_wall+                else -> R.string.cd_block+            },+        )     return BlockLabels(-        description = stringResource(-            R.string.cd_block_at,-            kind,-            block.dimension.width,-            block.dimension.height,-            block.position.y + 1,-            block.position.x + 1,-        ),+        description =+            stringResource(+                R.string.cd_block_at,+                kind,+                block.dimension.width,+                block.dimension.height,+                block.position.y + 1,+                block.position.x + 1,+            ),         left = stringResource(R.string.action_move_left),         right = stringResource(R.string.action_move_right),         up = stringResource(R.string.action_move_up),@@ -179,7 +195,10 @@ private fun blockLabels(block: Block, isMainBlock: Boolean): BlockLabels { }  /** One release: a settle from [from], told apart from the last by [id]. */-private data class SettleTrip(val id: Int, val from: Offset)+private data class SettleTrip(+    val id: Int,+    val from: Offset,+)  private const val WIN_ANIM_MILLIS = 600 private const val BLOCK_INSET_SCALE = 4
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/GameBoard.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/GameBoard.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/GameBoard.ktindex e468a9d3be..79d06d457e 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/GameBoard.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/ui/components/GameBoard.kt@@ -5,8 +5,8 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.absoluteOffset import androidx.compose.foundation.layout.size-import androidx.compose.foundation.systemGestureExclusion import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.foundation.systemGestureExclusion import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Alignment@@ -40,7 +40,7 @@ fun GameBoard(     onLevelChanged: (LevelData) -> Unit,     onLevelWon: () -> Unit,     isLevelWon: Boolean,-    modifier: Modifier = Modifier+    modifier: Modifier = Modifier, ) {     // The board is a picture of physical space, not text: the exit is on the right and a drag to     // the right moves a block right, whatever the locale. Under RTL the rtl-aware offsets used for@@ -76,7 +76,10 @@ fun GameBoard(                         // taken by the system back gesture and cancel the move. Android honours                         // up to 200 dp of exclusion per edge, which covers most of a phone board.                         .systemGestureExclusion()-                        .background(MaterialTheme.colorScheme.primary, RoundedCornerShape(scaling * BOARD_CORNER_SCALE))+                        .background(+                            MaterialTheme.colorScheme.primary,+                            RoundedCornerShape(scaling * BOARD_CORNER_SCALE),+                        ),                 ) {                     levelData.blocks.forEachIndexed { index, block ->                         GameBlock(@@ -103,7 +106,12 @@ fun GameBoard(  * target block slides under.  */ @Composable-private fun ExitLane(boardSize: Dp, cellSize: DpSize, exitRow: Int, fadeCells: Int) {+private fun ExitLane(+    boardSize: Dp,+    cellSize: DpSize,+    exitRow: Int,+    fadeCells: Int,+) {     val chevronColor = MaterialTheme.colorScheme.tertiary     val exitLabel = stringResource(R.string.exit)     Box(@@ -111,9 +119,11 @@ private fun ExitLane(boardSize: Dp, cellSize: DpSize, exitRow: Int, fadeCells: I             .absoluteOffset(boardSize - 1.dp, cellSize.height * exitRow)             .size(cellSize.width + 1.dp, cellSize.height)             .testTag(EXIT_LANE_TEST_TAG)-            .background(MaterialTheme.colorScheme.primary, RoundedCornerShape(topEndPercent = 35, bottomEndPercent = 35))-            .drawBehind { drawExitChevrons(chevronColor) }-            .semantics { contentDescription = exitLabel }+            .background(+                MaterialTheme.colorScheme.primary,+                RoundedCornerShape(topEndPercent = 35, bottomEndPercent = 35),+            ).drawBehind { drawExitChevrons(chevronColor) }+            .semantics { contentDescription = exitLabel },     )     Box(         Modifier@@ -121,13 +131,15 @@ private fun ExitLane(boardSize: Dp, cellSize: DpSize, exitRow: Int, fadeCells: I             .size(cellSize.width * fadeCells, cellSize.height)             .zIndex(1f)             .background(-                brush = Brush.horizontalGradient(-                    colorStops = arrayOf(-                        0f to Color.Transparent,-                        1f / fadeCells to MaterialTheme.colorScheme.background-                    )-                )-            )+                brush =+                    Brush.horizontalGradient(+                        colorStops =+                            arrayOf(+                                0f to Color.Transparent,+                                1f / fadeCells to MaterialTheme.colorScheme.background,+                            ),+                    ),+            ),     ) } 
games/unblockjam/src/screenshotTest/kotlin/com/vayunmathur/games/unblockjam/MetadataPreviews.kt
diff --git a/games/unblockjam/src/screenshotTest/kotlin/com/vayunmathur/games/unblockjam/MetadataPreviews.kt b/games/unblockjam/src/screenshotTest/kotlin/com/vayunmathur/games/unblockjam/MetadataPreviews.ktindex e48363d0eb..907da1c337 100644--- a/games/unblockjam/src/screenshotTest/kotlin/com/vayunmathur/games/unblockjam/MetadataPreviews.kt+++ b/games/unblockjam/src/screenshotTest/kotlin/com/vayunmathur/games/unblockjam/MetadataPreviews.kt@@ -9,69 +9,74 @@ import com.vayunmathur.games.unblockjam.data.Dimension import com.vayunmathur.games.unblockjam.data.LevelData import com.vayunmathur.games.unblockjam.data.LevelPack import com.vayunmathur.games.unblockjam.data.PackColorScheme-import com.vayunmathur.games.unblockjam.ui.UnblockJamTheme import com.vayunmathur.games.unblockjam.platform.GameActions import com.vayunmathur.games.unblockjam.platform.GameUiState+import com.vayunmathur.games.unblockjam.ui.UnblockJamTheme import com.vayunmathur.library.util.LevelStats  /** Phone-shaped, roughly 1080x2340 at xxhdpi — comfortably above the F-Droid minimum. */ private const val PHONE = "spec:width=411dp,height=891dp,dpi=420"  /** The palette shipped in `original_pack.json`, which is what every puzzle renders with. */-private val PACK_COLORS = PackColorScheme(-    primary = 0xFF3D3021,-    secondary = 0xFF4A3B2A,-    tertiary = 0xFFFF0000,-    background = 0xFF4A3B2A,-    surface = 0xFF3D3021,-    primaryContainer = 0xFFFFA500,-    secondaryContainer = 0xFF6F5E55,-)+private val PACK_COLORS =+    PackColorScheme(+        primary = 0xFF3D3021,+        secondary = 0xFF4A3B2A,+        tertiary = 0xFFFF0000,+        background = 0xFF4A3B2A,+        surface = 0xFF3D3021,+        primaryContainer = 0xFFFFA500,+        secondaryContainer = 0xFF6F5E55,+    )  /**  * A 6x6 board a few moves into the puzzle. Positions are in board cells with y running down,  * the way [LevelData] stores them after parsing; block 0 is the red one that has to reach the  * exit, so its row must match [LevelData.exit]'s.  */-private val BOARD = LevelData(-    id = "60",-    dimension = Dimension(6, 6),-    exit = Coord(6, 2),-    blocks = listOf(-        Block(Coord(0, 2), Dimension(2, 1), false),-        Block(Coord(2, 0), Dimension(1, 3), false),-        Block(Coord(4, 1), Dimension(1, 2), false),-        Block(Coord(2, 3), Dimension(3, 1), false),-        Block(Coord(3, 0), Dimension(2, 1), false),-        Block(Coord(5, 2), Dimension(1, 2), false),-        Block(Coord(3, 1), Dimension(1, 2), false),-        Block(Coord(2, 4), Dimension(3, 1), false),-        Block(Coord(0, 5), Dimension(3, 1), false),-    ),-    optimalMoves = 10,-)+private val BOARD =+    LevelData(+        id = "60",+        dimension = Dimension(6, 6),+        exit = Coord(6, 2),+        blocks =+            listOf(+                Block(Coord(0, 2), Dimension(2, 1), false),+                Block(Coord(2, 0), Dimension(1, 3), false),+                Block(Coord(4, 1), Dimension(1, 2), false),+                Block(Coord(2, 3), Dimension(3, 1), false),+                Block(Coord(3, 0), Dimension(2, 1), false),+                Block(Coord(5, 2), Dimension(1, 2), false),+                Block(Coord(3, 1), Dimension(1, 2), false),+                Block(Coord(2, 4), Dimension(3, 1), false),+                Block(Coord(0, 5), Dimension(3, 1), false),+            ),+        optimalMoves = 10,+    )  /** The puzzle grid only reads each level's id and optimal move count, so reuse one layout. */-private val PACK = LevelPack(-    name = "Original Pack",-    levels = List(24) { index -> BOARD.copy(id = index.toString(), optimalMoves = 4 + index % 9) },-    colorScheme = PACK_COLORS,-)+private val PACK =+    LevelPack(+        name = "Original Pack",+        levels = List(24) { index -> BOARD.copy(id = index.toString(), optimalMoves = 4 + index % 9) },+        colorScheme = PACK_COLORS,+    )  /** Solved puzzles: a star when the player matched the optimum, a tick when they beat it out. */-private val LEVEL_STATS = mapOf(-    "0" to LevelStats(4),-    "1" to LevelStats(6),-    "2" to LevelStats(6),-    "3" to LevelStats(9),-    "4" to LevelStats(8),-    "5" to LevelStats(9),-    "6" to LevelStats(13),-    "7" to LevelStats(11),-    "8" to LevelStats(15),-    "9" to LevelStats(4),-    "10" to LevelStats(7),-)+private val LEVEL_STATS =+    mapOf(+        "0" to LevelStats(4),+        "1" to LevelStats(6),+        "2" to LevelStats(6),+        "3" to LevelStats(9),+        "4" to LevelStats(8),+        "5" to LevelStats(9),+        "6" to LevelStats(13),+        "7" to LevelStats(11),+        "8" to LevelStats(15),+        "9" to LevelStats(4),+        "10" to LevelStats(7),+    )  /**  * Store listing images for `:games:unblockjam`. See `common-conventions-preview-metadata`.@@ -91,22 +96,22 @@ private val LEVEL_STATS = mapOf(  * palette comes from the pack, not from Material You.  */ class MetadataPreviews {-     @PreviewTest     @Preview(name = "1-board", device = PHONE, group = "phone", showSystemUi = true)     @Composable     fun Preview1Board() {         UnblockJamTheme(pack = PACK) {             GameScreen(-                state = GameUiState(-                    levelData = BOARD,-                    levelIndex = 11,-                    maxLevelIndex = PACK.levels.lastIndex,-                    moves = 7,-                    bestScore = 12,-                    isCompleted = true,-                    canUndo = true,-                ),+                state =+                    GameUiState(+                        levelData = BOARD,+                        levelIndex = 11,+                        maxLevelIndex = PACK.levels.lastIndex,+                        moves = 7,+                        bestScore = 12,+                        isCompleted = true,+                        canUndo = true,+                    ),                 actions = GameActions.Noop,                 onBack = {},             )
games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/BoardDragOverlapTest.kt
diff --git a/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/BoardDragOverlapTest.kt b/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/BoardDragOverlapTest.ktindex 20a5fb99cb..241d399c53 100644--- a/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/BoardDragOverlapTest.kt+++ b/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/BoardDragOverlapTest.kt@@ -44,10 +44,12 @@ class BoardDragOverlapTest {     @BeforeTest     fun setUp() {         Dispatchers.setMain(Dispatchers.Unconfined)-        if (LevelPack.PACKS.isEmpty()) LevelPack.init(app)+        if (LevelPack.packs.isEmpty()) LevelPack.init(app)     } -    @AfterTest fun tearDown() { Dispatchers.resetMain() }+    @AfterTest fun tearDown() {+        Dispatchers.resetMain()+    }      @Test     fun twoFingerDragKeepsBothMoves() {@@ -79,7 +81,9 @@ class BoardDragOverlapTest {             up(1)         }         rule.waitForIdle()-        val blocks = vm.uiState.value.currentLevelData!!.blocks+        val blocks =+            vm.uiState.value.currentLevelData!!+                .blocks         assertEquals(Coord(3, 4), blocks[4].position, "block 4 dragged right one cell")         assertEquals(Coord(3, 0), blocks[2].position, "block 2 dragged up one cell")         assertEquals(2, vm.getCurrentMoves())
games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/BoardDragTest.kt
diff --git a/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/BoardDragTest.kt b/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/BoardDragTest.ktindex 4532caa141..349ca20897 100644--- a/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/BoardDragTest.kt+++ b/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/BoardDragTest.kt@@ -30,24 +30,40 @@ import kotlin.test.assertTrue class BoardDragTest {     @get:Rule val rule = createComposeRule() -    private fun level(blocks: List<Block>) = LevelData(-        id = "drag", dimension = Dimension(6, 6), exit = Coord(6, 2),-        blocks = blocks, optimalMoves = 1,-    )+    private fun level(blocks: List<Block>) =+        LevelData(+            id = "drag",+            dimension = Dimension(6, 6),+            exit = Coord(6, 2),+            blocks = blocks,+            optimalMoves = 1,+        ) -    private fun openLevel() = level(-        listOf(-            Block(Coord(0, 2), Dimension(2, 1), false), // main-            Block(Coord(2, 1), Dimension(1, 3), false), // vertical blocker-            Block(Coord(4, 4), Dimension(2, 1), true), // fixed wall-            Block(Coord(0, 5), Dimension(2, 1), false), // spare horizontal+    private fun openLevel() =+        level(+            listOf(+                Block(Coord(0, 2), Dimension(2, 1), false), // main+                Block(Coord(2, 1), Dimension(1, 3), false), // vertical blocker+                Block(Coord(4, 4), Dimension(2, 1), true), // fixed wall+                Block(Coord(0, 5), Dimension(2, 1), false), // spare horizontal+            ),         )-    ) -    private fun setBoard(level: LevelData, won: Boolean, onChanged: (LevelData) -> Unit, onWon: () -> Unit) {+    private fun setBoard(+        level: LevelData,+        won: Boolean,+        onChanged: (LevelData) -> Unit,+        onWon: () -> Unit,+    ) {         rule.setContent {             Box(Modifier.size(360.dp)) {-                GameBoard(levelData = level, onLevelChanged = onChanged, onLevelWon = onWon, isLevelWon = won, modifier = Modifier.testTag("board"))+                GameBoard(+                    levelData = level,+                    onLevelChanged = onChanged,+                    onLevelWon = onWon,+                    isLevelWon = won,+                    modifier = Modifier.testTag("board"),+                )             }         }     }@@ -71,12 +87,13 @@ class BoardDragTest {     fun draggingMainBlockToExitWins() {         var changed: LevelData? = null         var won = 0-        val free = level(-            listOf(-                Block(Coord(0, 2), Dimension(2, 1), false),-                Block(Coord(0, 5), Dimension(2, 1), false),+        val free =+            level(+                listOf(+                    Block(Coord(0, 2), Dimension(2, 1), false),+                    Block(Coord(0, 5), Dimension(2, 1), false),+                ),             )-        )         setBoard(free, false, { changed = it }, { won++ })         // main centre (1/6, 2.5/6); drag far right toward the exit         rule.onNodeWithTag("board").performTouchInput {@@ -126,12 +143,13 @@ class BoardDragTest {     @Test     fun draggingHorizontalBlockLeftReportsMove() {         var changed: LevelData? = null-        val lvl = level(-            listOf(-                Block(Coord(0, 2), Dimension(2, 1), false),-                Block(Coord(3, 5), Dimension(2, 1), false),+        val lvl =+            level(+                listOf(+                    Block(Coord(0, 2), Dimension(2, 1), false),+                    Block(Coord(3, 5), Dimension(2, 1), false),+                ),             )-        )         setBoard(lvl, false, { changed = it }, {})         // spare block centre (4/6, 5.5/6); drag left two cells         rule.onNodeWithTag("board").performTouchInput {@@ -144,12 +162,13 @@ class BoardDragTest {      @Test     fun blockFollowsTheFingerMidDrag() {-        val lvl = level(-            listOf(-                Block(Coord(0, 2), Dimension(2, 1), false),-                Block(Coord(3, 5), Dimension(2, 1), false),+        val lvl =+            level(+                listOf(+                    Block(Coord(0, 2), Dimension(2, 1), false),+                    Block(Coord(3, 5), Dimension(2, 1), false),+                ),             )-        )         setBoard(lvl, false, {}, {})         val before = rule.onNodeWithTag("block_1").getBoundsInRoot().left         // Finger still down: the position is applied in layout, not by recomposition, and must@@ -171,12 +190,13 @@ class BoardDragTest {     @Test     fun cancelledDragSnapsBackToTheCommittedCell() {         var changed: LevelData? = null-        val lvl = level(-            listOf(-                Block(Coord(0, 2), Dimension(2, 1), false),-                Block(Coord(3, 5), Dimension(2, 1), false),+        val lvl =+            level(+                listOf(+                    Block(Coord(0, 2), Dimension(2, 1), false),+                    Block(Coord(3, 5), Dimension(2, 1), false),+                ),             )-        )         setBoard(lvl, false, { changed = it }, {})         val before = rule.onNodeWithTag("block_1").getBoundsInRoot()         // The system (a back gesture, say) takes the pointer mid-drag.
games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/MainActivityTest.kt
diff --git a/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/MainActivityTest.kt b/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/MainActivityTest.ktindex 66478e72ea..a5b4499cd4 100644--- a/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/MainActivityTest.kt+++ b/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/MainActivityTest.kt@@ -19,8 +19,8 @@ class MainActivityTest {         val activity = controller.get()         Shadows.shadowOf(android.os.Looper.getMainLooper()).idle()         assertFalse(activity.isFinishing)-        assertEquals(7, LevelPack.PACKS.size)-        assertTrue(LevelPack.PACKS.all { it.levels.isNotEmpty() })+        assertEquals(7, LevelPack.packs.size)+        assertTrue(LevelPack.packs.all { it.levels.isNotEmpty() })         val ctx = ApplicationProvider.getApplicationContext<android.content.Context>()         assertEquals("Unblock Jam", ctx.getString(R.string.app_name))         controller.pause().stop().destroy()
games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/NavigationScreensTest.kt
diff --git a/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/NavigationScreensTest.kt b/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/NavigationScreensTest.ktindex c27de0a94e..25031cc314 100644--- a/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/NavigationScreensTest.kt+++ b/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/NavigationScreensTest.kt@@ -51,27 +51,32 @@ class NavigationScreensTest {     @get:Rule val rule = createComposeRule()     private val app get() = ApplicationProvider.getApplicationContext<Application>()     private val ctx get() = app as android.content.Context+     private fun str(id: Int) = ctx.getString(id)      @BeforeTest     fun setUp() {         Dispatchers.setMain(Dispatchers.Unconfined)-        if (LevelPack.PACKS.isEmpty()) LevelPack.init(app)+        if (LevelPack.packs.isEmpty()) LevelPack.init(app)     } -    @AfterTest fun tearDown() { Dispatchers.resetMain() }+    @AfterTest fun tearDown() {+        Dispatchers.resetMain()+    } -    private fun sampleLevel(id: String = "s1") = LevelData(-        id = id,-        dimension = Dimension(6, 6),-        exit = Coord(6, 2),-        blocks = listOf(-            Block(Coord(0, 2), Dimension(2, 1), false),-            Block(Coord(2, 1), Dimension(1, 3), false),-            Block(Coord(4, 4), Dimension(2, 1), true),-        ),-        optimalMoves = 2,-    )+    private fun sampleLevel(id: String = "s1") =+        LevelData(+            id = id,+            dimension = Dimension(6, 6),+            exit = Coord(6, 2),+            blocks =+                listOf(+                    Block(Coord(0, 2), Dimension(2, 1), false),+                    Block(Coord(2, 1), Dimension(1, 3), false),+                    Block(Coord(4, 4), Dimension(2, 1), true),+                ),+            optimalMoves = 2,+        )      private class RecordingActions : GameActions {         var moved: LevelData? = null@@ -79,19 +84,40 @@ class NavigationScreensTest {         var undo = 0         var restart = 0         var levelChange: Int? = null-        override fun onBlockMoved(newLevelData: LevelData) { moved = newLevelData }-        override fun onLevelWon() { won++ }-        override fun onUndo() { undo++ }-        override fun onRestart() { restart++ }++        override fun onBlockMoved(newLevelData: LevelData) {+            moved = newLevelData+        }++        override fun onLevelWon() {+            won+++        }++        override fun onUndo() {+            undo+++        }++        override fun onRestart() {+            restart+++        }+         var backToPacks = 0-        override fun onBackToPacks() { backToPacks++ }-        override fun onLevelChange(newIndex: Int) { levelChange = newIndex }++        override fun onBackToPacks() {+            backToPacks+++        }++        override fun onLevelChange(newIndex: Int) {+            levelChange = newIndex+        }     }      @Test     fun packScreenListsPacksAndDailyAndRoutesClicks() {         var openedPack: Int? = null-        var daily = 0; var center = 0; var settings = 0+        var daily = 0+        var center = 0+        var settings = 0         rule.setContent {             UnblockJamTheme {                 PackScreen(@@ -129,10 +155,11 @@ class NavigationScreensTest {         rule.setContent {             LevelScreen(                 pack = LevelPack("TestPack", levels),-                levelStats = mapOf(-                    "a" to LevelStats(2), // <= optimal: star-                    "b" to LevelStats(9), // > optimal: check-                ),+                levelStats =+                    mapOf(+                        "a" to LevelStats(2), // <= optimal: star+              

Diff truncated.