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 {
if let Some(p) = w.random_land() {
if cheb(p, w.home) > w.config.wolf_min_home_distance {
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,
@ -1112,7 +1113,6 @@ impl World {
});
}
}
}
w.sync_entities();
w
}
@ -1555,8 +1555,9 @@ 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() {
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,
@ -1565,12 +1566,11 @@ impl World {
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,
@ -1581,8 +1581,6 @@ impl World {
}
}
}
}
}
fn find_partners(&mut self) {
let ticks_per_week = self.calendar.ticks_per_day * self.calendar.days_per_week as u64;
@ -2189,23 +2187,23 @@ 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) {
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) {
if min_days <= max_days
&& let Some(range) = self.calendar.duration_mut(stage)
{
range.min_days = min_days;
range.max_days = max_days;
}
}
}
}
}
Some("speed") => {
if let Some(n) = num(1) {
self.speed = n.clamp(1, self.config.max_simulation_speed as i64) as u32;
@ -2224,8 +2222,9 @@ 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) {
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,
@ -2236,7 +2235,6 @@ impl World {
}
}
}
}
Some("energy") => {
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;
@ -2249,17 +2247,17 @@ impl World {
}
}
Some("terrain") => {
if let (Some((x0, y0, x1, y1)), Some(kind)) = (self.rect(&t, 1), num(5)) {
if (0..=6).contains(&kind) {
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 {
@ -2276,7 +2274,6 @@ impl World {
}
}
}
}
Some("spawn") => {
if let (Some(what), Some((x0, y0, x1, y1))) = (t.get(1), self.rect(&t, 2)) {
let mut left = self.config.manual_spawn_limit;
@ -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());
}
}

View File

@ -133,8 +133,9 @@ fn App() -> impl IntoView {
}
}
on:mousemove=move |ev| {
if dragging.get_untracked() {
if let Some((x, y)) = tile(&ev) {
if dragging.get_untracked()
&& let Some((x, y)) = tile(&ev)
{
sel.update(|s| {
if let Some(s) = s {
s.bx = x;
@ -143,7 +144,6 @@ fn App() -> impl IntoView {
});
}
}
}
></canvas>
</div>
<div class="side">
@ -535,7 +535,7 @@ fn ScriptEditor() -> impl IntoView {
errors.set("Could not fetch the script.".into());
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 {
Ok(()) => {
mounted.set_value(true);