Modern Apps git

← Modern-Apps.git

voxels: host the menu world list and creator as routes (#nav)

Commit
44698520344a391f4a7edf7a7b4808477ebdd4bb
Author
Vayun Mathur <[email protected]>
When
2026-11-16 20:01 UTC (19 days ago)
Parents
f8317b0
The menu chose between the world list and the world creator with a
`creating` boolean in MenuActivity, swapping the whole Surface
content with an if/else. That is a major-screen choice, so it now
lives on a typed back stack.

Add Route, a serializable sealed NavKey for the module, with
Route.Worlds (the saved-world list, the root) and Route.CreateWorld
(the creator). MenuActivity hosts both with MainNavigation over a
rememberNavBackStack(Route.Worlds): the list's Create action pushes
CreateWorld, and the creator's Back/Cancel — and system Back — pop
back to the list, replacing the hand-set boolean on every path.
Creating a world pops back to Worlds before play() starts the game,
so the menu the player returns to is the list, as before.

Nothing else moves: playing a world still starts MainActivity (the
game) by Intent with the same extras, the share dialog still overlays
the menu from the Worlds entry, and the join-link, inbox poll and
resume-reload effects are untouched. The module AGENTS entry line now
names Route.kt.

Verified on devvm21958 (no push):
- ./gradlew :games:voxels:compileDevKotlin — green
  (full :games:voxels:testDevUnitTest re-run with the game commit)

Diff

games/voxels/AGENTS.md
diff --git a/games/voxels/AGENTS.md b/games/voxels/AGENTS.mdindex 486d9279f0..42ad1c8849 100644--- a/games/voxels/AGENTS.md+++ b/games/voxels/AGENTS.md@@ -6,7 +6,7 @@ _Install: ./install games/voxels (dev by default)._ <!-- last-reviewed: 2026-10-16 --> - Gradle: :games:voxels / dir: games/voxels/ - Package roots present: ui, data, platform, network-- Entry files: MainActivity.kt + platform/MenuActivity.kt (menu/world select; no Route.kt)+- Entry files: MainActivity.kt + platform/MenuActivity.kt (menu/world select) + Route.kt (menu hosts Route.Worlds / Route.CreateWorld) - Deps: :sdk:games, :library:network, :library:e2ee-p2p - Metadata: metadata_data/games-voxels.md (present) - Rust: yes / screenshotTest: hand-committed
games/voxels/src/main/java/com/vayunmathur/games/voxels/Route.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/Route.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/Route.ktnew file mode 100644index 0000000000..53d98940d8--- /dev/null+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/Route.kt@@ -0,0 +1,24 @@+package com.vayunmathur.games.voxels++import com.vayunmathur.library.util.NavKey+import kotlinx.serialization.Serializable++/**+ * Typed destinations for the menu and the game.+ *+ * The menu ([com.vayunmathur.games.voxels.platform.MenuActivity]) hosts+ * [Worlds] and [CreateWorld] on a back stack; playing a world still+ * starts the game Activity by Intent, so no game destination lives here+ * yet — the in-game overlays join this type with the game commit.+ * Routes carry ids and small arguments, never whole objects.+ */+@Serializable+sealed interface Route : NavKey {+    /** The saved-world list: the menu's root destination. */+    @Serializable+    data object Worlds : Route++    /** The world creator, pushed over [Worlds]; Back returns to the list. */+    @Serializable+    data object CreateWorld : Route+}
games/voxels/src/main/java/com/vayunmathur/games/voxels/platform/MenuActivity.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/platform/MenuActivity.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/platform/MenuActivity.ktindex 62e35a0319..fac657d2e1 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/platform/MenuActivity.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/platform/MenuActivity.kt@@ -24,12 +24,14 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import com.vayunmathur.games.voxels.MainActivity import com.vayunmathur.games.voxels.R+import com.vayunmathur.games.voxels.Route import com.vayunmathur.games.voxels.ui.MenuScreen import com.vayunmathur.games.voxels.ui.ShareOnlineDialog import com.vayunmathur.games.voxels.ui.WorldCreatorScreen import com.vayunmathur.library.ui.DynamicTheme-import com.vayunmathur.library.ui.Surface import com.vayunmathur.library.util.AppMessages+import com.vayunmathur.library.util.MainNavigation+import com.vayunmathur.library.util.rememberNavBackStack import com.vayunmathur.library.util.rememberIsOnline import com.vayunmathur.games.voxels.domain.playerSuffix import com.vayunmathur.games.voxels.network.JoinRequests@@ -103,7 +105,10 @@ class MenuActivity : ComponentActivity() {             DynamicTheme {                 val scope = rememberCoroutineScope()                 val online by rememberIsOnline()-                var creating by remember { mutableStateOf(false) }+                // Which menu screen is showing is a destination, not a flag: the creator is+                // pushed over the world list, so Back (system or the creator's Cancel) pops+                // back to the list. Playing a world still starts MainActivity by Intent.+                val backStack = rememberNavBackStack<Route>(Route.Worlds)                 var worlds by remember { mutableStateOf(localWorlds()) }                 var onlineWorlds by remember { mutableStateOf(onlineWorldList()) }                 var deviceId by remember { mutableStateOf("") }@@ -156,20 +161,21 @@ class MenuActivity : ComponentActivity() {                     toast(getString(if (ok) R.string.join_request_sent else R.string.invite_failed))                 } -                Surface(Modifier.fillMaxSize()) {-                    Box(Modifier.fillMaxSize()) {-                        if (creating) {+                Box(Modifier.fillMaxSize()) {+                    MainNavigation(backStack) {+                        entry<Route.CreateWorld> {                             WorldCreatorScreen(-                                onBack = { creating = false },+                                onBack = { backStack.pop() },                                 onCreate = { name, seedText, mode ->                                     val seed = WorldManager.resolveSeed(seedText)                                     val world = WorldManager.createWorld(this@MenuActivity, name, seed, System.currentTimeMillis(), mode)                                     reload()-                                    creating = false+                                    backStack.pop()                                     play(world)                                 }                             )-                        } else {+                        }+                        entry<Route.Worlds> {                             MenuScreen(                                 worlds = worlds,                                 onlineWorlds = onlineWorlds,@@ -180,7 +186,7 @@ class MenuActivity : ComponentActivity() {                                     WorldManager.deleteWorld(this@MenuActivity, world.id)                                     reload()                                 },-                                onCreate = { creating = true },+                                onCreate = { backStack.add(Route.CreateWorld) },                                 onHostOnline = {                                     scope.launch {                                         val ok = withContext(Dispatchers.IO) { runCatching { VoxelsSync.init(this@MenuActivity) }.getOrDefault(false) }@@ -215,8 +221,9 @@ class MenuActivity : ComponentActivity() {                                 },                             )                         }+                    } -                        shareTarget?.let { world ->+                    shareTarget?.let { world ->                             ShareOnlineDialog(                                 world = world,                                 onDismiss = { shareTarget = null },@@ -248,7 +255,6 @@ class MenuActivity : ComponentActivity() {                                 },                             )                         }-                    }                 }             }         }