From 030f590d79e8c9d5e51910b41380769c9ea2e495 Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Sun, 13 Nov 2022 13:35:20 +0100 Subject: [PATCH] Allow passing seed to new_world --- planet/src/world_manager.rs | 4 ++-- src/gui/widgets/toolbar.rs | 2 +- src/main.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/planet/src/world_manager.rs b/planet/src/world_manager.rs index f9ee94b..4d8440b 100644 --- a/planet/src/world_manager.rs +++ b/planet/src/world_manager.rs @@ -160,8 +160,8 @@ impl WorldManager { self.get_world().unwrap() } - pub fn new_world(&mut self) -> Result<&World, WorldGenError> { - let seed = random(); + pub fn new_world(&mut self, seed: Option) -> Result<&World, WorldGenError> { + let seed = seed.unwrap_or_else(random); let mut new_world = World::new(400, 200, seed); new_world.generate()?; self.world = Some(new_world); diff --git a/src/gui/widgets/toolbar.rs b/src/gui/widgets/toolbar.rs index 3b05e35..7a2c4f4 100644 --- a/src/gui/widgets/toolbar.rs +++ b/src/gui/widgets/toolbar.rs @@ -34,7 +34,7 @@ impl ToolbarButton { world.resource_scope(|world, mut world_manager: Mut<'_, WorldManager>| { match self { ToolbarButton::GenerateWorld => { - if let Err(err) = world_manager.new_world() { + if let Err(err) = world_manager.new_world(None) { eprintln!("Failed to generate world: {}", err); } else { world.resource_mut::().0 = true; diff --git a/src/main.rs b/src/main.rs index 6c3dc4e..aa9db4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -252,7 +252,7 @@ fn main() -> Result<(), Box> { let mut manager = WorldManager::new(); #[cfg(feature = "render")] { - let world = manager.new_world()?; + let world = manager.new_world(None)?; _ = app .insert_resource(WinitSettings::game()) // Use nearest-neighbor rendering for cripsier pixels