Allow passing seed to new_world

This commit is contained in:
Tobias Berger 2022-11-13 13:35:20 +01:00
parent a58e7a2c2d
commit 030f590d79
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
3 changed files with 4 additions and 4 deletions

View file

@ -160,8 +160,8 @@ impl WorldManager {
self.get_world().unwrap() self.get_world().unwrap()
} }
pub fn new_world(&mut self) -> Result<&World, WorldGenError> { pub fn new_world(&mut self, seed: Option<u32>) -> Result<&World, WorldGenError> {
let seed = random(); let seed = seed.unwrap_or_else(random);
let mut new_world = World::new(400, 200, seed); let mut new_world = World::new(400, 200, seed);
new_world.generate()?; new_world.generate()?;
self.world = Some(new_world); self.world = Some(new_world);

View file

@ -34,7 +34,7 @@ impl ToolbarButton {
world.resource_scope(|world, mut world_manager: Mut<'_, WorldManager>| { world.resource_scope(|world, mut world_manager: Mut<'_, WorldManager>| {
match self { match self {
ToolbarButton::GenerateWorld => { 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); eprintln!("Failed to generate world: {}", err);
} else { } else {
world.resource_mut::<ShouldRedraw>().0 = true; world.resource_mut::<ShouldRedraw>().0 = true;

View file

@ -252,7 +252,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut manager = WorldManager::new(); let mut manager = WorldManager::new();
#[cfg(feature = "render")] #[cfg(feature = "render")]
{ {
let world = manager.new_world()?; let world = manager.new_world(None)?;
_ = app _ = app
.insert_resource(WinitSettings::game()) .insert_resource(WinitSettings::game())
// Use nearest-neighbor rendering for cripsier pixels // Use nearest-neighbor rendering for cripsier pixels