diff --git a/src/world.rs b/src/world.rs index 91d8e23..5bb37de 100644 --- a/src/world.rs +++ b/src/world.rs @@ -1101,16 +1101,16 @@ impl World { } } for _ in 0..w.config.initial_wolves { - if let Some(p) = w.random_land() { - if cheb(p, w.home) > w.config.wolf_min_home_distance { - w.wolves.push(Animal { - actor_id: 0, - x: p.0, - y: p.1, - energy: w.config.initial_animal_energy, - dead: false, - }); - } + if let Some(p) = w.random_land() + && cheb(p, w.home) > w.config.wolf_min_home_distance + { + w.wolves.push(Animal { + actor_id: 0, + x: p.0, + y: p.1, + energy: w.config.initial_animal_energy, + dead: false, + }); } } w.sync_entities(); @@ -1555,31 +1555,29 @@ impl World { .tick .is_multiple_of(self.config.animal_population_interval) { - if self.rabbits.len() < self.config.rabbit_spawn_cap { - if let Some(p) = self.random_land() { - self.rabbits.push(Animal { - actor_id: 0, - x: p.0, - y: p.1, - energy: self.config.initial_animal_energy, - dead: false, - }); - } + if self.rabbits.len() < self.config.rabbit_spawn_cap + && let Some(p) = self.random_land() + { + self.rabbits.push(Animal { + actor_id: 0, + x: p.0, + y: p.1, + energy: self.config.initial_animal_energy, + dead: false, + }); } if self.wolves.len() < self.config.wolf_spawn_cap && self.rabbits.len() > self.config.wolf_spawn_rabbit_threshold + && let Some(p) = self.random_land() + && cheb(p, self.home) > self.config.wolf_min_home_distance { - if let Some(p) = self.random_land() { - if cheb(p, self.home) > self.config.wolf_min_home_distance { - self.wolves.push(Animal { - actor_id: 0, - x: p.0, - y: p.1, - energy: self.config.initial_animal_energy, - dead: false, - }); - } - } + self.wolves.push(Animal { + actor_id: 0, + x: p.0, + y: p.1, + energy: self.config.initial_animal_energy, + dead: false, + }); } } } @@ -2189,19 +2187,19 @@ impl World { Some("stage") => { if let (Some(stage), Some(property)) = (t.get(1), t.get(2)) { if *property == "fertile" { - if let Some(value) = num(3) { - if let Some(range) = self.calendar.duration_mut(stage) { - range.fertile = value != 0; - } + if let Some(value) = num(3) + && let Some(range) = self.calendar.duration_mut(stage) + { + range.fertile = value != 0; } } else if let (Some(min_days), Some(max_days)) = (num(2), num(3)) { let min_days = min_days.clamp(1, 1_000_000) as u32; let max_days = max_days.clamp(1, 1_000_000) as u32; - if min_days <= max_days { - if let Some(range) = self.calendar.duration_mut(stage) { - range.min_days = min_days; - range.max_days = max_days; - } + if min_days <= max_days + && let Some(range) = self.calendar.duration_mut(stage) + { + range.min_days = min_days; + range.max_days = max_days; } } } @@ -2224,16 +2222,16 @@ impl World { } } Some("person") => { - if let (Some(id), Some(field), Some(v)) = (num(1), t.get(2), num(3)) { - if let Some(p) = self.people.iter_mut().find(|p| p.id as i64 == id) { - let u = v.clamp(0, self.config.max_person_inventory_edit as i64) as u32; - match *field { - "hunger" => p.hunger = v.clamp(0, self.config.max_hunger_edit) as f32, - "food" => p.food = u, - "wood" => p.wood = u, - "stone" => p.stone = u, - _ => {} - } + if let (Some(id), Some(field), Some(v)) = (num(1), t.get(2), num(3)) + && let Some(p) = self.people.iter_mut().find(|p| p.id as i64 == id) + { + let u = v.clamp(0, self.config.max_person_inventory_edit as i64) as u32; + match *field { + "hunger" => p.hunger = v.clamp(0, self.config.max_hunger_edit) as f32, + "food" => p.food = u, + "wood" => p.wood = u, + "stone" => p.stone = u, + _ => {} } } } @@ -2249,29 +2247,28 @@ impl World { } } Some("terrain") => { - if let (Some((x0, y0, x1, y1)), Some(kind)) = (self.rect(&t, 1), num(5)) { - if (0..=6).contains(&kind) { - self.paint_terrain(x0, y0, x1, y1, kind as u8); - } + if let (Some((x0, y0, x1, y1)), Some(kind)) = (self.rect(&t, 1), num(5)) + && (0..=6).contains(&kind) + { + self.paint_terrain(x0, y0, x1, y1, kind as u8); } } Some("res") => { if let (Some((x0, y0, x1, y1)), Some(kind), Some(amt)) = (self.rect(&t, 1), num(5), num(6)) + && (0..=3).contains(&kind) { - if (0..=3).contains(&kind) { - let amt = amt.clamp(1, self.config.max_resource_edit as i64) as u16; - for y in y0..=y1 { - for x in x0..=x1 { - let i = y * self.width + x; - let free = self.walkable(x as i32, y as i32) - && (x, y) != self.home - && !self.houses.contains(&(x, y)); - if kind == 0 { - self.res[i] = (0, 0); - } else if free { - self.res[i] = (kind as u8, amt); - } + let amt = amt.clamp(1, self.config.max_resource_edit as i64) as u16; + for y in y0..=y1 { + for x in x0..=x1 { + let i = y * self.width + x; + let free = self.walkable(x as i32, y as i32) + && (x, y) != self.home + && !self.houses.contains(&(x, y)); + if kind == 0 { + self.res[i] = (0, 0); + } else if free { + self.res[i] = (kind as u8, amt); } } } @@ -2538,7 +2535,8 @@ impl World { impl Drop for World { fn drop(&mut self) { - let _ = self.actor_system.shutdown(); + // Shutdown starts eagerly; Drop must not block waiting for completion. + drop(self.actor_system.shutdown()); } } diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 5b029d5..44c902f 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -133,15 +133,15 @@ fn App() -> impl IntoView { } } on:mousemove=move |ev| { - if dragging.get_untracked() { - if let Some((x, y)) = tile(&ev) { - sel.update(|s| { - if let Some(s) = s { - s.bx = x; - s.by = y; - } - }); - } + if dragging.get_untracked() + && let Some((x, y)) = tile(&ev) + { + sel.update(|s| { + if let Some(s) = s { + s.bx = x; + s.by = y; + } + }); } } > @@ -535,7 +535,7 @@ fn ScriptEditor() -> impl IntoView { errors.set("Could not fetch the script.".into()); return; }; - let cb = Closure::::new(move || apply()).into_js_value(); + let cb = Closure::::new(apply).into_js_value(); match editor::editor_mount(&h, &v, &src, vim.get_untracked(), &cb).await { Ok(()) => { mounted.set_value(true);