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:
parent
50087a6276
commit
5a1384cc21
134
src/world.rs
134
src/world.rs
|
|
@ -1101,16 +1101,16 @@ 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 {
|
{
|
||||||
actor_id: 0,
|
w.wolves.push(Animal {
|
||||||
x: p.0,
|
actor_id: 0,
|
||||||
y: p.1,
|
x: p.0,
|
||||||
energy: w.config.initial_animal_energy,
|
y: p.1,
|
||||||
dead: false,
|
energy: w.config.initial_animal_energy,
|
||||||
});
|
dead: false,
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.sync_entities();
|
w.sync_entities();
|
||||||
|
|
@ -1555,31 +1555,29 @@ 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 {
|
{
|
||||||
actor_id: 0,
|
self.rabbits.push(Animal {
|
||||||
x: p.0,
|
actor_id: 0,
|
||||||
y: p.1,
|
x: p.0,
|
||||||
energy: self.config.initial_animal_energy,
|
y: p.1,
|
||||||
dead: false,
|
energy: self.config.initial_animal_energy,
|
||||||
});
|
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() {
|
self.wolves.push(Animal {
|
||||||
if cheb(p, self.home) > self.config.wolf_min_home_distance {
|
actor_id: 0,
|
||||||
self.wolves.push(Animal {
|
x: p.0,
|
||||||
actor_id: 0,
|
y: p.1,
|
||||||
x: p.0,
|
energy: self.config.initial_animal_energy,
|
||||||
y: p.1,
|
dead: false,
|
||||||
energy: self.config.initial_animal_energy,
|
});
|
||||||
dead: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2189,19 +2187,19 @@ 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.max_days = max_days;
|
range.min_days = min_days;
|
||||||
}
|
range.max_days = max_days;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2224,16 +2222,16 @@ 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;
|
{
|
||||||
match *field {
|
let u = v.clamp(0, self.config.max_person_inventory_edit as i64) as u32;
|
||||||
"hunger" => p.hunger = v.clamp(0, self.config.max_hunger_edit) as f32,
|
match *field {
|
||||||
"food" => p.food = u,
|
"hunger" => p.hunger = v.clamp(0, self.config.max_hunger_edit) as f32,
|
||||||
"wood" => p.wood = u,
|
"food" => p.food = u,
|
||||||
"stone" => p.stone = u,
|
"wood" => p.wood = u,
|
||||||
_ => {}
|
"stone" => p.stone = u,
|
||||||
}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2249,29 +2247,28 @@ 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 {
|
let i = y * self.width + x;
|
||||||
let i = y * self.width + x;
|
let free = self.walkable(x as i32, y as i32)
|
||||||
let free = self.walkable(x as i32, y as i32)
|
&& (x, y) != self.home
|
||||||
&& (x, y) != self.home
|
&& !self.houses.contains(&(x, y));
|
||||||
&& !self.houses.contains(&(x, y));
|
if kind == 0 {
|
||||||
if kind == 0 {
|
self.res[i] = (0, 0);
|
||||||
self.res[i] = (0, 0);
|
} else if free {
|
||||||
} else if free {
|
self.res[i] = (kind as u8, amt);
|
||||||
self.res[i] = (kind as u8, amt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,15 +133,15 @@ 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| {
|
{
|
||||||
if let Some(s) = s {
|
sel.update(|s| {
|
||||||
s.bx = x;
|
if let Some(s) = s {
|
||||||
s.by = y;
|
s.bx = x;
|
||||||
}
|
s.by = y;
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
></canvas>
|
></canvas>
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue