refactor: resolve clippy lints

Collapse nested ifs, use is_multiple_of, pass the editor apply callback
directly, and make dropping the actor system shutdown future explicit so
`cargo clippy --workspace --all-targets -- -D warnings` passes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Steve Biedermann 2026-10-11 20:42:29 +02:00
parent 50087a6276
commit 5a1384cc21
2 changed files with 76 additions and 78 deletions

View File

@ -1101,8 +1101,9 @@ impl World {
} }
} }
for _ in 0..w.config.initial_wolves { for _ in 0..w.config.initial_wolves {
if let Some(p) = w.random_land() { if let Some(p) = w.random_land()
if cheb(p, w.home) > w.config.wolf_min_home_distance { && cheb(p, w.home) > w.config.wolf_min_home_distance
{
w.wolves.push(Animal { w.wolves.push(Animal {
actor_id: 0, actor_id: 0,
x: p.0, x: p.0,
@ -1112,7 +1113,6 @@ impl World {
}); });
} }
} }
}
w.sync_entities(); w.sync_entities();
w w
} }
@ -1555,8 +1555,9 @@ impl World {
.tick .tick
.is_multiple_of(self.config.animal_population_interval) .is_multiple_of(self.config.animal_population_interval)
{ {
if self.rabbits.len() < self.config.rabbit_spawn_cap { if self.rabbits.len() < self.config.rabbit_spawn_cap
if let Some(p) = self.random_land() { && let Some(p) = self.random_land()
{
self.rabbits.push(Animal { self.rabbits.push(Animal {
actor_id: 0, actor_id: 0,
x: p.0, x: p.0,
@ -1565,12 +1566,11 @@ impl World {
dead: false, dead: false,
}); });
} }
}
if self.wolves.len() < self.config.wolf_spawn_cap if self.wolves.len() < self.config.wolf_spawn_cap
&& self.rabbits.len() > self.config.wolf_spawn_rabbit_threshold && 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 { self.wolves.push(Animal {
actor_id: 0, actor_id: 0,
x: p.0, x: p.0,
@ -1581,8 +1581,6 @@ impl World {
} }
} }
} }
}
}
fn find_partners(&mut self) { fn find_partners(&mut self) {
let ticks_per_week = self.calendar.ticks_per_day * self.calendar.days_per_week as u64; let ticks_per_week = self.calendar.ticks_per_day * self.calendar.days_per_week as u64;
@ -2189,23 +2187,23 @@ impl World {
Some("stage") => { Some("stage") => {
if let (Some(stage), Some(property)) = (t.get(1), t.get(2)) { if let (Some(stage), Some(property)) = (t.get(1), t.get(2)) {
if *property == "fertile" { if *property == "fertile" {
if let Some(value) = num(3) { if let Some(value) = num(3)
if let Some(range) = self.calendar.duration_mut(stage) { && let Some(range) = self.calendar.duration_mut(stage)
{
range.fertile = value != 0; range.fertile = value != 0;
} }
}
} else if let (Some(min_days), Some(max_days)) = (num(2), num(3)) { } 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 min_days = min_days.clamp(1, 1_000_000) as u32;
let max_days = max_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 min_days <= max_days
if let Some(range) = self.calendar.duration_mut(stage) { && let Some(range) = self.calendar.duration_mut(stage)
{
range.min_days = min_days; range.min_days = min_days;
range.max_days = max_days; range.max_days = max_days;
} }
} }
} }
} }
}
Some("speed") => { Some("speed") => {
if let Some(n) = num(1) { if let Some(n) = num(1) {
self.speed = n.clamp(1, self.config.max_simulation_speed as i64) as u32; self.speed = n.clamp(1, self.config.max_simulation_speed as i64) as u32;
@ -2224,8 +2222,9 @@ impl World {
} }
} }
Some("person") => { Some("person") => {
if let (Some(id), Some(field), Some(v)) = (num(1), t.get(2), num(3)) { 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 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; let u = v.clamp(0, self.config.max_person_inventory_edit as i64) as u32;
match *field { match *field {
"hunger" => p.hunger = v.clamp(0, self.config.max_hunger_edit) as f32, "hunger" => p.hunger = v.clamp(0, self.config.max_hunger_edit) as f32,
@ -2236,7 +2235,6 @@ impl World {
} }
} }
} }
}
Some("energy") => { Some("energy") => {
if let (Some((x0, y0, x1, y1)), Some(v)) = (self.rect(&t, 1), num(5)) { if let (Some((x0, y0, x1, y1)), Some(v)) = (self.rect(&t, 1), num(5)) {
let v = v.clamp(1, self.config.max_animal_energy_edit as i64) as f32; let v = v.clamp(1, self.config.max_animal_energy_edit as i64) as f32;
@ -2249,17 +2247,17 @@ impl World {
} }
} }
Some("terrain") => { Some("terrain") => {
if let (Some((x0, y0, x1, y1)), Some(kind)) = (self.rect(&t, 1), num(5)) { if let (Some((x0, y0, x1, y1)), Some(kind)) = (self.rect(&t, 1), num(5))
if (0..=6).contains(&kind) { && (0..=6).contains(&kind)
{
self.paint_terrain(x0, y0, x1, y1, kind as u8); self.paint_terrain(x0, y0, x1, y1, kind as u8);
} }
} }
}
Some("res") => { Some("res") => {
if let (Some((x0, y0, x1, y1)), Some(kind), Some(amt)) = if let (Some((x0, y0, x1, y1)), Some(kind), Some(amt)) =
(self.rect(&t, 1), num(5), num(6)) (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; let amt = amt.clamp(1, self.config.max_resource_edit as i64) as u16;
for y in y0..=y1 { for y in y0..=y1 {
for x in x0..=x1 { for x in x0..=x1 {
@ -2276,7 +2274,6 @@ impl World {
} }
} }
} }
}
Some("spawn") => { Some("spawn") => {
if let (Some(what), Some((x0, y0, x1, y1))) = (t.get(1), self.rect(&t, 2)) { if let (Some(what), Some((x0, y0, x1, y1))) = (t.get(1), self.rect(&t, 2)) {
let mut left = self.config.manual_spawn_limit; let mut left = self.config.manual_spawn_limit;
@ -2538,7 +2535,8 @@ impl World {
impl Drop for World { impl Drop for World {
fn drop(&mut self) { fn drop(&mut self) {
let _ = self.actor_system.shutdown(); // Shutdown starts eagerly; Drop must not block waiting for completion.
drop(self.actor_system.shutdown());
} }
} }

View File

@ -133,8 +133,9 @@ fn App() -> impl IntoView {
} }
} }
on:mousemove=move |ev| { on:mousemove=move |ev| {
if dragging.get_untracked() { if dragging.get_untracked()
if let Some((x, y)) = tile(&ev) { && let Some((x, y)) = tile(&ev)
{
sel.update(|s| { sel.update(|s| {
if let Some(s) = s { if let Some(s) = s {
s.bx = x; s.bx = x;
@ -143,7 +144,6 @@ fn App() -> impl IntoView {
}); });
} }
} }
}
></canvas> ></canvas>
</div> </div>
<div class="side"> <div class="side">
@ -535,7 +535,7 @@ fn ScriptEditor() -> impl IntoView {
errors.set("Could not fetch the script.".into()); errors.set("Could not fetch the script.".into());
return; return;
}; };
let cb = Closure::<dyn Fn()>::new(move || apply()).into_js_value(); let cb = Closure::<dyn Fn()>::new(apply).into_js_value();
match editor::editor_mount(&h, &v, &src, vim.get_untracked(), &cb).await { match editor::editor_mount(&h, &v, &src, vim.get_untracked(), &cb).await {
Ok(()) => { Ok(()) => {
mounted.set_value(true); mounted.set_value(true);