Modern Apps git

← Modern-Apps.git

wordmaker: give the level-load error a scaffold and Retry (#ux-audit)

Commit
d9d4ddee99e0851de201157efe525b75365be7e7
Author
Vayun Mathur <[email protected]>
When
2026-11-13 01:30 UTC (23 days ago)
Parents
2a07f93
Symptom: when a level could not be parsed or generated, the game
showed a bare red "Failed to parse level data." in the middle of an
empty screen - no top bar, no way to switch mode, open settings or
try again. The only way out was to kill the app.

Root cause: WordMakerGameLoader rendered the ViewModel's error string
as a lone Text in place of the whole game page, and the ViewModel
had no way to re-run the failed load.

Fix:
- New WordMakerLoadError screen: the same AppScaffold top bar as the
  game (mode chooser + game-center/settings actions) around the
  shared library ErrorState, with a Retry button (the shared
  library:ui R.string.retry, already translated).
- WordMakerViewModel.retryLoad() clears the error and re-runs the
  load for the current mode: reloads the casual level, regenerates
  today's daily, or generates a new competitive board.

User-visible effect: a failed level shows an error inside the normal
game chrome with Retry; the player can also switch mode or open
settings from there.

Verification: new WordMakerLoadErrorTest renders the screen, checks
the message and Retry are shown, and that Retry calls back.

Diff

games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.ktindex 006d536c12..ce7ad664b0 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt@@ -342,6 +342,19 @@ class WordMakerViewModel(application: Application) : AndroidViewModel(applicatio         }     } +    /**+     * Retries the load that failed for the current mode (the error screen's Retry button):+     * reloads the casual level, regenerates today's daily, or generates a new competitive board.+     */+    fun retryLoad() {+        _error.value = null+        when (gameMode.value) {+            GameMode.CASUAL -> viewModelScope.launch { loadCasualLevel(currentLevel.value) }+            GameMode.DAILY -> viewModelScope.launch { refreshDaily() }+            GameMode.COMPETITIVE -> loadNextCompetitiveLevel()+        }+    }+     override fun setDifficulty(difficulty: Difficulty) {         // Difficulty is chosen on the lobby between levels, so it only needs to be persisted.         viewModelScope.launch { levelDataStore.setDifficulty(difficulty) }
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordMakerGameLoader.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordMakerGameLoader.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordMakerGameLoader.ktindex 4e997215e9..402dd2c5b6 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordMakerGameLoader.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordMakerGameLoader.kt@@ -3,8 +3,6 @@ package com.vayunmathur.games.wordmaker.ui import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.CircularProgressIndicator-import androidx.compose.material3.MaterialTheme-import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState@@ -50,8 +48,18 @@ fun WordMakerGameLoader(backStack: NavBackStack<Route>, viewModel: WordMakerView                 )             } +            // Inside the normal scaffold (mode chooser, settings) with a Retry button, rather+            // than a bare line of text the player could not get away from.             error != null -> {-                Text(text = error!!, color = MaterialTheme.colorScheme.error)+                WordMakerLoadError(+                    message = error!!,+                    gameMode = gameMode,+                    levelNumber = currentLevel,+                    onSelectMode = viewModel::setGameMode,+                    onRetry = viewModel::retryLoad,+                    onOpenGameCenter = { backStack.add(Route.GameCenter) },+                    onOpenSettings = { backStack.add(Route.Settings) },+                )             }              crosswordData != null -> {
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordMakerLoadError.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordMakerLoadError.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordMakerLoadError.ktnew file mode 100644index 0000000000..b75c0397e7--- /dev/null+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordMakerLoadError.kt@@ -0,0 +1,56 @@+package com.vayunmathur.games.wordmaker.ui++import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import com.vayunmathur.games.wordmaker.data.GameMode+import com.vayunmathur.games.wordmaker.ui.components.WordMakerModeChooser+import com.vayunmathur.library.ui.AppBarAlignment+import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.ErrorState+import com.vayunmathur.library.ui.R as UiR+import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.game.GameTopBarActions++/**+ * A level that could not be loaded or generated. Keeps the game's own top bar, so the player+ * can switch mode or open settings, and offers Retry instead of a dead end.+ */+@Composable+fun WordMakerLoadError(+    message: String,+    gameMode: GameMode,+    levelNumber: Int,+    onSelectMode: (GameMode) -> Unit,+    onRetry: () -> Unit,+    onOpenGameCenter: () -> Unit,+    onOpenSettings: () -> Unit,+) {+    AppScaffold(+        modifier = Modifier.fillMaxSize(),+        title = {+            WordMakerModeChooser(+                selected = gameMode,+                onSelected = onSelectMode,+                levelNumber = levelNumber,+            )+        },+        actions = {+            GameTopBarActions(+                onOpenGameCenter = onOpenGameCenter,+                onOpenSettings = onOpenSettings,+            )+        },+        alignment = AppBarAlignment.Center,+        scrollBehavior = appBarScrollBehavior(),+    ) { innerPadding ->+        ErrorState(+            title = message,+            modifier = Modifier.padding(innerPadding),+            retryLabel = stringResource(UiR.string.retry),+            onRetry = onRetry,+        )+    }+}
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerLoadErrorTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerLoadErrorTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerLoadErrorTest.ktnew file mode 100644index 0000000000..b6c19b9c02--- /dev/null+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerLoadErrorTest.kt@@ -0,0 +1,41 @@+package com.vayunmathur.games.wordmaker.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import com.vayunmathur.games.wordmaker.data.GameMode+import com.vayunmathur.library.ui.DynamicTheme+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config+import kotlin.test.Test+import kotlin.test.assertEquals++@RunWith(RobolectricTestRunner::class)+@Config(qualifiers = "w411dp-h891dp")+class WordMakerLoadErrorTest {+    @get:Rule val rule = createComposeRule()++    @Test fun parseErrorOffersRetryInsideTheGameScaffold() {+        var retries = 0+        rule.setContent {+            DynamicTheme {+                WordMakerLoadError(+                    message = "Failed to parse level data.",+                    gameMode = GameMode.CASUAL,+                    levelNumber = 7,+                    onSelectMode = {},+                    onRetry = { retries++ },+                    onOpenGameCenter = {},+                    onOpenSettings = {},+                )+            }+        }+        rule.onNodeWithText("Failed to parse level data.").assertIsDisplayed()+        rule.onNodeWithText("Retry").assertIsDisplayed()+        rule.onNodeWithText("Retry").performClick()+        assertEquals(1, retries)+    }+}