voxels: add creative/survival world modes; Fly gets its own button (#ux-audit)
- Commit
274e8c68528a3fa07e0b8546e3195869e451139e- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 01:38 UTC (23 days ago)
- Parents
fbbd8fd
Symptom: double-tapping Jump toggled flight, which also happened by
accident whenever players jumped twice quickly (e.g. climbing), and
every world had the free block catalog and flight - there was no way
to play a world where resources mattered.
Root cause: flight was a hidden double-tap gesture on the Jump
HoldButton (MainActivity) honoured unconditionally by the engine
(engine_part1.rs toggle_fly), and the catalog column was always
rendered (ui/InventoryScreen.kt) with giveBlock always allowed.
Fix (product decision, conservative default):
- WorldMeta gains `mode` ("creative" | "survival", data/WorldMode).
Worlds saved before this have no field and load as creative, i.e.
exactly how they always played; online worlds stay creative.
- The world creator gets a Game mode picker with a one-line
explanation; Creative is preselected so nothing changes for players
who don't touch it. The form now scrolls so it still fits a
landscape phone. MenuActivity passes the mode to the game.
- Engine: new nativeSetCreative (set before the world loads).
Survival ignores fly toggles and grounds a flying player
(apply_fly_toggle), refuses catalog gives (inventory_give), and a
brand-new survival world starts with an empty inventory instead of
the building kit.
- HUD: survival hides the catalog column and has no flight control.
Creative gets a dedicated Fly/Land toggle above Use; Jump no longer
reacts to double-taps.
User-visible effect: no more accidental flight; players can choose a
survival world with no catalog and no flying.
Flag for product: the creator preselects Creative to preserve current
behaviour; switching the default to Survival is a one-line change in
WorldCreatorScreen.
Verification: new Rust test flight_is_creative_only; WorldManagerTest
checks the mode round-trips and legacy world.json loads as creative;
VoxelScreensTest checks the creator reports the picked mode.Diff
games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.ktindex 1a82963e72..1a6e82b06f 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.kt@@ -54,6 +54,7 @@ import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsControllerCompat import com.vayunmathur.games.voxels.data.GameSettingsStore+import com.vayunmathur.games.voxels.data.WorldMode import com.vayunmathur.games.voxels.domain.BackTarget import com.vayunmathur.games.voxels.domain.NetStatus import com.vayunmathur.games.voxels.network.JoinRequests@@ -129,9 +130,12 @@ class MainActivity : ComponentActivity() { val worldKeyB64 = intent.getStringExtra("world_key") ?: "" val ownerDevice = intent.getStringExtra("owner_device") ?: "" val worldName = intent.getStringExtra("world_name") ?: ""+ // Absent for worlds launched by older menus: those are creative, as they always were.+ val creative = intent.getStringExtra("world_mode") != WorldMode.SURVIVAL if (VoxelsNative.isAvailable) { // Put the engine in host/client mode before the engine thread starts ticking. if (online) try { VoxelsNative.nativeSetRole(netRole) } catch (_: Exception) {}+ try { VoxelsNative.nativeSetCreative(creative) } catch (_: Exception) {} // Returns immediately: the world is generated and meshed on the engine thread behind // the loading overlay, never on the main thread. initEngine(worldDir, worldSeed)@@ -430,8 +434,8 @@ class MainActivity : ComponentActivity() { // start. This Box has no pointer input, so touches still reach the look layer. Box(Modifier.align(Alignment.CenterEnd).width(40.dp).height(200.dp).systemGestureExclusion()) - // Right-hand action cluster: Use beside two stacked buttons (walking: Jump / Sneak,- // flying: Up / Down; double-tap the top one to toggle flying). It sits above the+ // Right-hand action cluster: Fly (creative) over Use, beside two stacked buttons+ // (walking: Jump / Sneak, flying: Up / Down). It sits above the // hotbar (8 dp slot padding + 52 dp slots + 12 dp offset) so Sneak no longer // covers the last hotbar slots. Row(@@ -439,13 +443,30 @@ class MainActivity : ComponentActivity() { horizontalArrangement = Arrangement.spacedBy(10.dp), verticalAlignment = Alignment.CenterVertically, ) {- // Use/attack whatever is under the crosshair, repeating while held.- UseButton(label = stringResource(R.string.use)) {- if (VoxelsNative.isAvailable && !paused && worldSize.width > 0) try {- if (VoxelsNative.breakBlockAt(worldSize.width / 2f, worldSize.height / 2f)) {- com.vayunmathur.games.voxels.platform.SoundFx.playBreak()- }- } catch (_: Exception) {}+ Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {+ // Creative only: flight has its own toggle (it used to hide behind a double-tap on Jump,+ // which also fired by accident when jumping repeatedly).+ if (creative) {+ HoldButton(+ label = stringResource(if (flying) R.string.land else R.string.fly),+ onPress = {+ if (VoxelsNative.isAvailable) try { VoxelsNative.toggleFly() } catch (_: Exception) {}+ flying = !flying+ if (flying) {+ sneaking = false+ if (VoxelsNative.isAvailable) try { VoxelsNative.setSneak(false) } catch (_: Exception) {}+ }+ },+ )+ }+ // Use/attack whatever is under the crosshair, repeating while held.+ UseButton(label = stringResource(R.string.use)) {+ if (VoxelsNative.isAvailable && !paused && worldSize.width > 0) try {+ if (VoxelsNative.breakBlockAt(worldSize.width / 2f, worldSize.height / 2f)) {+ com.vayunmathur.games.voxels.platform.SoundFx.playBreak()+ }+ } catch (_: Exception) {}+ } } Column( verticalArrangement = Arrangement.spacedBy(10.dp),@@ -456,14 +477,6 @@ class MainActivity : ComponentActivity() { dimmed = !flying && sneaking, onPress = { if (VoxelsNative.isAvailable) try { VoxelsNative.setJump(true) } catch (_: Exception) {} }, onRelease = { if (VoxelsNative.isAvailable) try { VoxelsNative.setJump(false) } catch (_: Exception) {} },- onDoubleTap = {- if (VoxelsNative.isAvailable) try { VoxelsNative.toggleFly() } catch (_: Exception) {}- flying = !flying- if (flying) {- sneaking = false- if (VoxelsNative.isAvailable) try { VoxelsNative.setSneak(false) } catch (_: Exception) {}- }- } ) if (flying) { HoldButton(@@ -550,7 +563,7 @@ class MainActivity : ComponentActivity() { InventoryOverlay( inventoryJson = inventoryJson, recipesJson = recipesJson, blessingsJson = blessingsJson, blessingCatalogJson = blessingCatalogJson,- onClose = { inventoryOpen = false }, startTab = invStartTab,+ onClose = { inventoryOpen = false }, startTab = invStartTab, creative = creative, worldAchievements = achievements?.world, ) }
games/voxels/src/main/java/com/vayunmathur/games/voxels/data/WorldManager.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/data/WorldManager.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/data/WorldManager.ktindex e890b1b902..171829dac9 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/data/WorldManager.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/data/WorldManager.kt@@ -25,8 +25,19 @@ data class WorldMeta( val ownerDeviceId: String = "", val role: String = "", val keyB64: String = "",+ // Game mode, picked at creation. Worlds saved before modes existed have no field and load as+ // creative, which is exactly how they always played.+ val mode: String = WorldMode.CREATIVE, ) +/** World game modes ([WorldMeta.mode]). */+object WorldMode {+ /** Flight and the free block catalog. */+ const val CREATIVE = "creative"+ /** No flight, no catalog, and a new world starts with an empty inventory. */+ const val SURVIVAL = "survival"+}+ // A world plus its resolved id (directory name) and absolute save path. Not persisted directly. data class WorldInfo( val id: String,@@ -63,7 +74,7 @@ object WorldManager { return t.hashCode() } - fun createWorld(ctx: Context, name: String, seed: Int, now: Long): WorldInfo {+ fun createWorld(ctx: Context, name: String, seed: Int, now: Long, mode: String = WorldMode.CREATIVE): WorldInfo { val root = worldsRoot(ctx) // Unique directory id derived from the creation time (worlds can share display names). var id = "w_$now"@@ -71,7 +82,7 @@ object WorldManager { while (File(root, id).exists()) { id = "w_${now}_$i"; i++ } val dir = File(root, id).apply { mkdirs() } val displayName = name.trim().ifEmpty { "New World" }- val meta = WorldMeta(name = displayName, seed = seed, created = now, lastPlayed = now)+ val meta = WorldMeta(name = displayName, seed = seed, created = now, lastPlayed = now, mode = mode) File(dir, "world.json").writeText(json.encodeToString(WorldMeta.serializer(), meta)) return WorldInfo(id = id, dir = dir.absolutePath, meta = meta) }
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 b0361a1a4d..ebeaaf409f 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@@ -160,9 +160,9 @@ class MenuActivity : ComponentActivity() { if (creating) { WorldCreatorScreen( onBack = { creating = false },- onCreate = { name, seedText ->+ onCreate = { name, seedText, mode -> val seed = WorldManager.resolveSeed(seedText)- val world = WorldManager.createWorld(this@MenuActivity, name, seed, System.currentTimeMillis())+ val world = WorldManager.createWorld(this@MenuActivity, name, seed, System.currentTimeMillis(), mode) reload() creating = false play(world)@@ -267,6 +267,7 @@ class MenuActivity : ComponentActivity() { putExtra("world_dir", world.dir) putExtra("world_seed", world.meta.seed) putExtra("world_name", world.meta.name)+ putExtra("world_mode", world.meta.mode) if (world.meta.online) { putExtra("online", true) putExtra("world_id", world.meta.worldId)
games/voxels/src/main/java/com/vayunmathur/games/voxels/platform/VoxelsNative.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/platform/VoxelsNative.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/platform/VoxelsNative.ktindex 3b307d83dc..dd5f171953 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/platform/VoxelsNative.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/platform/VoxelsNative.kt@@ -32,6 +32,8 @@ object VoxelsNative { external fun nativeSave() // Pause menu: stops single-player simulation (frames keep drawing) and releases held input. external fun nativeSetPaused(paused: Boolean)+ // World mode: creative (flight + catalog) or survival. Call before nativeInit.+ external fun nativeSetCreative(creative: Boolean) external fun onMoveInput(moveX: Float, moveY: Float) external fun onLookInput(lookYawRate: Float, lookPitchRate: Float) // Camera turn-speed multiplier from the settings sheet (0.25..3).
games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.ktindex b5033c03ee..2afabc8639 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.kt@@ -71,6 +71,8 @@ internal fun inventorySlotSize(width: Dp): Dp = ((width - SLOT_GAP * 8) / 9).coe fun InventoryOverlay( inventoryJson: String, recipesJson: String, blessingsJson: String, blessingCatalogJson: String, onClose: () -> Unit, startTab: Int = 0,+ // Survival worlds have no free catalog.+ creative: Boolean = true, // This world's achievement tier. Null until the manager has loaded from assets. worldAchievements: AchievementsManager? = null, ) {@@ -130,6 +132,7 @@ fun InventoryOverlay( } } + if (creative) { // Right catalog (creative): tap a block to add a stack. Eight 96 dp tabs don't fit the // 236 dp column, so the tab strip scrolls sideways. Column(Modifier.width(if (narrow) 160.dp else 236.dp).fillMaxHeight(), horizontalAlignment = Alignment.CenterHorizontally) {@@ -147,6 +150,7 @@ fun InventoryOverlay( val cat = when (catTab) { 0 -> catalogNatural; 1 -> catalogOres; 3 -> catalogOcean; 4 -> catalogItems; 5 -> catalogBlessings; 6 -> catalogGear; 7 -> catalogMusic; else -> catalogBuilding } CatalogGrid(cat, columns = if (narrow) 3 else 4) { id -> try { VoxelsNative.giveBlock(id) } catch (_: Exception) {} } }+ } } }
games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/MenuScreens.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/MenuScreens.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/MenuScreens.ktindex 200c49f6fb..1dcd83ae09 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/MenuScreens.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/MenuScreens.kt@@ -17,7 +17,9 @@ import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items+import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.text.KeyboardOptions+import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf@@ -30,6 +32,7 @@ import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog import com.vayunmathur.games.voxels.data.WorldInfo+import com.vayunmathur.games.voxels.data.WorldMode import com.vayunmathur.games.voxels.network.VoxelsRoles import com.vayunmathur.games.voxels.network.VoxelsSync import com.vayunmathur.library.ui.R as UiR@@ -282,13 +285,16 @@ fun ShareOnlineDialog( @Composable fun WorldCreatorScreen( onBack: () -> Unit,- onCreate: (name: String, seedText: String) -> Unit,+ onCreate: (name: String, seedText: String, mode: String) -> Unit, ) { var name by remember { mutableStateOf("") } var seed by remember { mutableStateOf("") }+ // Creative is preselected: it's how every world played before modes existed.+ var mode by remember { mutableStateOf(WorldMode.CREATIVE) } Box(Modifier.fillMaxSize().padding(24.dp), contentAlignment = Alignment.TopCenter) {+ // Scrolls: with the mode picker the form no longer fits a landscape phone's height. Column(- Modifier.fillMaxWidth().widthIn(max = 480.dp),+ Modifier.fillMaxWidth().widthIn(max = 480.dp).verticalScroll(rememberScrollState()), horizontalAlignment = Alignment.CenterHorizontally ) { Text(stringResource(R.string.create_world), style = MaterialTheme.typography.headlineMedium, color = MaterialTheme.colorScheme.primary)@@ -312,10 +318,22 @@ fun WorldCreatorScreen( keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), modifier = Modifier.fillMaxWidth() )+ Spacer(Modifier.height(12.dp))+ Text(stringResource(R.string.game_mode), style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.onBackground)+ Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(12.dp)) {+ for ((m, label) in listOf(WorldMode.CREATIVE to R.string.mode_creative, WorldMode.SURVIVAL to R.string.mode_survival)) {+ if (mode == m) Button(onClick = {}, modifier = Modifier.weight(1f)) { Text(stringResource(label)) }+ else OutlinedButton(onClick = { mode = m }, modifier = Modifier.weight(1f)) { Text(stringResource(label)) }+ }+ }+ Text(+ stringResource(if (mode == WorldMode.SURVIVAL) R.string.mode_survival_hint else R.string.mode_creative_hint),+ style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.7f),+ ) Spacer(Modifier.height(24.dp)) Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(12.dp)) { OutlinedButton(onClick = onBack, modifier = Modifier.weight(1f)) { Text(stringResource(UiR.string.cancel)) }- Button(onClick = { onCreate(name, seed) }, modifier = Modifier.weight(1f)) { Text(stringResource(R.string.create_play)) }+ Button(onClick = { onCreate(name, seed, mode) }, modifier = Modifier.weight(1f)) { Text(stringResource(R.string.create_play)) } } } }
games/voxels/src/main/res/values/strings.xml
diff --git a/games/voxels/src/main/res/values/strings.xml b/games/voxels/src/main/res/values/strings.xmlindex 85e4dc2cdc..94d9dfb54c 100644--- a/games/voxels/src/main/res/values/strings.xml+++ b/games/voxels/src/main/res/values/strings.xml@@ -22,6 +22,15 @@ <string name="leave_blank_for_random">Leave blank for random</string> <string name="a_number_or_any_text_hashed_to_a_seed">A number, or any text (hashed to a seed).</string> <string name="create_play">Create & Play</string>+ <!-- World creator: game mode picker label and options. -->+ <string name="game_mode">Game mode</string>+ <string name="mode_creative">Creative</string>+ <string name="mode_survival">Survival</string>+ <string name="mode_creative_hint">Fly, and take any block from the catalog.</string>+ <string name="mode_survival_hint">Start with nothing: mine, craft and trade for everything. No flying.</string>+ <!-- HUD toggle (creative only): start / stop flying. Verb, keep short -->+ <string name="fly">Fly</string>+ <string name="land">Land</string> <string name="villager_trades">Villager Trades</string> <string name="tap_a_trade_to_exchange_need_the_cost_it">Tap a trade to exchange (need the cost items).</string> <string name="villager_level">Level %1$d of %2$d</string>
games/voxels/src/main/rust/src/engine.rs
diff --git a/games/voxels/src/main/rust/src/engine.rs b/games/voxels/src/main/rust/src/engine.rsindex 5870e553fb..6ee956ccf2 100644--- a/games/voxels/src/main/rust/src/engine.rs+++ b/games/voxels/src/main/rust/src/engine.rs@@ -203,7 +203,9 @@ pub fn new_state(files_dir: String, seed: u32, render_distance: i32) -> EngineSt }; (ps.x, ps.y, ps.z, ps.yaw, ps.pitch, inv) } else {- (0.0, 80.0, 0.0, 0.0, 0.0, Inventory::default())+ // A new creative world starts with the building kit; a new survival world starts empty.+ let inv = if crate::engine::is_creative() { Inventory::default() } else { Inventory::empty() };+ (0.0, 80.0, 0.0, 0.0, 0.0, inv) }; let mut player = Player::new(px, py, pz);
games/voxels/src/main/rust/src/engine_part1.rs
diff --git a/games/voxels/src/main/rust/src/engine_part1.rs b/games/voxels/src/main/rust/src/engine_part1.rsindex 1b6c898681..e85d517ff2 100644--- a/games/voxels/src/main/rust/src/engine_part1.rs+++ b/games/voxels/src/main/rust/src/engine_part1.rs@@ -1,3 +1,20 @@+// World mode, chosen when the world was created. Creative (the default, and what every world+// created before modes existed gets) allows flight and the free block catalog; survival doesn't.+static CREATIVE: AtomicBool = AtomicBool::new(true);++/// Sets the world mode for this session (JNI `nativeSetCreative`, called before the world loads).+pub fn set_creative(creative: bool) { CREATIVE.store(creative, Ordering::SeqCst); }++/// Whether this session is creative.+pub fn is_creative() -> bool { CREATIVE.load(Ordering::SeqCst) }++/// Flight is a creative-only ability: honour a toggle request in creative, and in survival make sure+/// the player is never left flying (e.g. a creative save opened as survival).+fn apply_fly_toggle(state: &mut EngineState, toggle: bool, creative: bool) {+ if !creative { state.player.flying = false; return; }+ if toggle { state.player.flying = !state.player.flying; }+}+ // Set by the pause menu. While set, single-player worlds stop simulating (no physics, mobs, clock, // smelting or autosave) but keep drawing frames so the world stays visible behind the menu. static PAUSED: AtomicBool = AtomicBool::new(false);@@ -36,7 +53,7 @@ fn simulate(state: &mut EngineState, dt: f32) { // The world clock only moves with simulated time: not while paused, not in the background. state.world_secs = wrap_world_secs(state.world_secs + dt); let input = crate::input::snapshot_and_clear_look();- if input.toggle_fly { state.player.flying = !state.player.flying; }+ apply_fly_toggle(state, input.toggle_fly, is_creative()); // Rate-based look: (curved) stick displacement -> angular velocity (rad/s at full deflection). let look_speed = 3.2 * crate::input::look_sensitivity();
games/voxels/src/main/rust/src/engine_part2.rs
diff --git a/games/voxels/src/main/rust/src/engine_part2.rs b/games/voxels/src/main/rust/src/engine_part2.rsindex e6f2b0cb3d..5aeb732e48 100644--- a/games/voxels/src/main/rust/src/engine_part2.rs+++ b/games/voxels/src/main/rust/src/engine_part2.rs@@ -5,7 +5,8 @@ pub fn inventory_move(from: usize, to: usize) { s.inventory.move_item(from, to) }); }-pub fn inventory_give(id: Id) { with_engine(|s| s.inventory.give(id)); }+/// The creative catalog: a free stack of `id`. Refused in survival worlds.+pub fn inventory_give(id: Id) { if is_creative() { with_engine(|s| s.inventory.give(id)); } } pub fn inventory_craft(recipe: usize) -> bool { with_engine(|s| { if !s.inventory.craft(recipe, &s.crafted_recipes) { return false; }
games/voxels/src/main/rust/src/engine_part6.rs
diff --git a/games/voxels/src/main/rust/src/engine_part6.rs b/games/voxels/src/main/rust/src/engine_part6.rsindex e7a831679c..c7fbd236f5 100644--- a/games/voxels/src/main/rust/src/engine_part6.rs+++ b/games/voxels/src/main/rust/src/engine_part6.rs@@ -104,4 +104,21 @@ mod state_tests { let back = new_state(dir, 1234, 2); assert!((back.world_secs - 777.0).abs() < 1e-3); }) }++ // Survival has no flight (even a flying creative save is grounded) and creative toggles freely.+ #[test]+ fn flight_is_creative_only() { big_stack(|| {+ let mut s = small_state("fly");+ s.player.flying = false;+ apply_fly_toggle(&mut s, true, false);+ assert!(!s.player.flying, "survival toggled flight on");+ s.player.flying = true;+ apply_fly_toggle(&mut s, false, false);+ assert!(!s.player.flying, "survival left a player flying");+ apply_fly_toggle(&mut s, true, true);+ assert!(s.player.flying, "creative toggle didn't fly");+ apply_fly_toggle(&mut s, true, true);+ assert!(!s.player.flying);+ assert!(Inventory::empty().slots.iter().all(|sl| sl.id == 0 && sl.count == 0));+ }) } }
games/voxels/src/main/rust/src/lib_jni_lifecycle.rs
diff --git a/games/voxels/src/main/rust/src/lib_jni_lifecycle.rs b/games/voxels/src/main/rust/src/lib_jni_lifecycle.rsindex 8a9bf8a595..3e10831fe5 100644--- a/games/voxels/src/main/rust/src/lib_jni_lifecycle.rs+++ b/games/voxels/src/main/rust/src/lib_jni_lifecycle.rs@@ -111,3 +111,14 @@ pub extern "system" fn Java_com_vayunmathur_games_voxels_util_VoxelsNative_nativ ) { engine::set_paused(paused); }++/// JNI bridge for `VoxelsNative#nativeSetCreative`: the world's mode (creative allows flight and the+/// free catalog; survival doesn't). Call before `nativeInit`.+#[no_mangle]+pub extern "system" fn Java_com_vayunmathur_games_voxels_util_VoxelsNative_nativeSetCreative<'l>(+ _env: EnvUnowned<'l>,+ _class: JClass<'l>,+ creative: jboolean,+) {+ engine::set_creative(creative);+}
games/voxels/src/test/java/com/vayunmathur/games/voxels/data/WorldManagerTest.kt
diff --git a/games/voxels/src/test/java/com/vayunmathur/games/voxels/data/WorldManagerTest.kt b/games/voxels/src/test/java/com/vayunmathur/games/voxels/data/WorldManagerTest.ktindex e3a450b868..df264761b4 100644--- a/games/voxels/src/test/java/com/vayunmathur/games/voxels/data/WorldManagerTest.kt+++ b/games/voxels/src/test/java/com/vayunmathur/games/voxels/data/WorldManagerTest.kt@@ -76,4 +76,12 @@ class WorldManagerTest { File(ctx.filesDir, "voxels_handled_requests.json").writeText("broken") assertTrue(WorldManager.handledRequests(ctx).isEmpty()) }++ @Test fun `game mode is saved, and worlds from before modes load as creative`() {+ val s = WorldManager.createWorld(ctx, "Hard", 3, now = 50, mode = WorldMode.SURVIVAL)+ assertEquals(WorldMode.SURVIVAL, WorldManager.listWorlds(ctx).first { it.id == s.id }.meta.mode)+ val legacy = File(ctx.filesDir, "worlds/w_legacy").apply { mkdirs() }+ File(legacy, "world.json").writeText("""{"name":"Old","seed":1,"created":1,"lastPlayed":1}""")+ assertEquals(WorldMode.CREATIVE, WorldManager.listWorlds(ctx).first { it.id == "w_legacy" }.meta.mode)+ } }
games/voxels/src/test/java/com/vayunmathur/games/voxels/ui/VoxelScreensTest.kt
diff --git a/games/voxels/src/test/java/com/vayunmathur/games/voxels/ui/VoxelScreensTest.kt b/games/voxels/src/test/java/com/vayunmathur/games/voxels/ui/VoxelScreensTest.ktindex fe57143996..b0f270dc8c 100644--- a/games/voxels/src/test/java/com/vayunmathur/games/voxels/ui/VoxelScreensTest.kt+++ b/games/voxels/src/test/java/com/vayunmathur/games/voxels/ui/VoxelScreensTest.kt@@ -4,6 +4,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.performScrollTo import androidx.test.core.app.ApplicationProvider import com.vayunmathur.games.voxels.data.WorldInfo import com.vayunmathur.games.voxels.data.WorldMeta@@ -119,4 +120,12 @@ class VoxelScreensTest { rule.onNodeWithText("Delete").performClick() assertEquals(listOf("Alpha"), deleted) }++ @Test fun `the world creator offers creative and survival`() {+ var mode = ""+ rule.setContent { WorldCreatorScreen(onBack = {}, onCreate = { _, _, m -> mode = m }) }+ rule.onNodeWithText("Survival").performScrollTo().performClick()+ rule.onNodeWithText("Create & Play").performScrollTo().performClick()+ assertEquals(com.vayunmathur.games.voxels.data.WorldMode.SURVIVAL, mode)+ } }