From 1bff001db2914e8ee7bc331a4104592ad6e2e9a3 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 18 Jul 2024 15:52:12 +0200 Subject: clippy --- server/src/entity/conveyor.rs | 6 +----- server/src/entity/customers/demands.rs | 8 ++------ server/src/entity/customers/mod.rs | 4 ++-- server/src/entity/customers/pathfinding.rs | 6 ++---- server/src/entity/mod.rs | 2 +- server/src/game.rs | 16 ++++++++++------ server/src/interaction.rs | 30 +++++++++++------------------- 7 files changed, 29 insertions(+), 43 deletions(-) (limited to 'server/src') diff --git a/server/src/entity/conveyor.rs b/server/src/entity/conveyor.rs index d1594ce7..6067c679 100644 --- a/server/src/entity/conveyor.rs +++ b/server/src/entity/conveyor.rs @@ -44,11 +44,7 @@ impl EntityT for Conveyor { .get(t) .ok_or(anyhow!("conveyor filter missing"))?; filter_tile.item.as_ref().map(|e| e.kind) - } else if let Some(i) = &self.filter_item { - Some(*i) - } else { - None - }; + } else { self.filter_item.as_ref().map(|i| *i) }; if let Some(filter) = filter { if from_item.kind != filter { diff --git a/server/src/entity/customers/demands.rs b/server/src/entity/customers/demands.rs index fa7e0dbf..4f15f86f 100644 --- a/server/src/entity/customers/demands.rs +++ b/server/src/entity/customers/demands.rs @@ -41,7 +41,7 @@ pub fn generate_demands( let prod_count = producable.len(); for r in &recipes { - let output_count = r.outputs().iter().filter(|o| !items.contains(&o)).count(); + let output_count = r.outputs().iter().filter(|o| !items.contains(o)).count(); let Some(ingred_cost) = r .inputs() .iter() @@ -79,16 +79,12 @@ pub fn generate_demands( raw_demands .iter() .filter_map(|(i, o, d)| { - if let Some(cost) = producable.get(i) { - Some(Demand { + producable.get(i).map(|cost| Demand { from: *i, to: *o, duration: *d, points: *cost as i64, }) - } else { - None - } }) .collect() } diff --git a/server/src/entity/customers/mod.rs b/server/src/entity/customers/mod.rs index 7f0b0c22..806a25f9 100644 --- a/server/src/entity/customers/mod.rs +++ b/server/src/entity/customers/mod.rs @@ -150,7 +150,7 @@ impl EntityT for Customers { game.data.customer_spawn.as_ivec2(), ) .expect("no path to exit"); - *self.chairs.get_mut(&chair).unwrap() = true; + *self.chairs.get_mut(chair).unwrap() = true; game.demands_failed += 1; game.points -= 1; game.score_changed = true; @@ -231,7 +231,7 @@ impl EntityT for Customers { game.data.customer_spawn.as_ivec2(), ) .ok_or(anyhow!("no path to exit"))?; - *self.chairs.get_mut(&chair).unwrap() = true; + *self.chairs.get_mut(chair).unwrap() = true; game.demands_completed += 1; game.points += demand.points; game.score_changed = true; diff --git a/server/src/entity/customers/pathfinding.rs b/server/src/entity/customers/pathfinding.rs index 97bd8328..87ccf391 100644 --- a/server/src/entity/customers/pathfinding.rs +++ b/server/src/entity/customers/pathfinding.rs @@ -47,7 +47,7 @@ pub fn find_path(walkable: &HashSet, from: IVec2, to: IVec2) -> Option Option { - self.0.partial_cmp(&other.0) + Some(self.0.cmp(&other.0)) } } impl Ord for Open { @@ -61,9 +61,7 @@ pub fn find_path(walkable: &HashSet, from: IVec2, to: IVec2) -> Option { - let demands = generate_demands(tiles_used, items_used, &raw_demands, &recipes); + let demands = generate_demands(tiles_used, items_used, raw_demands, recipes); let chair = reg.register_tile("chair".to_string()); let chairs = initial_map .iter() diff --git a/server/src/game.rs b/server/src/game.rs index 370c2e8f..f5670277 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -83,6 +83,12 @@ pub struct Game { pub demands_completed: usize, } +impl Default for Game { + fn default() -> Self { + Self::new() + } +} + impl Game { pub fn new() -> Self { Self { @@ -239,7 +245,7 @@ impl Game { self.tiles.get(&(tile + IVec2::Y)).map(|e| e.kind), self.tiles.get(&(tile + IVec2::X)).map(|e| e.kind), ], - kind: Some(tdata.kind.clone()), + kind: Some(tdata.kind), }); if let Some(item) = &tdata.item { out.push(PacketC::SetItem { @@ -574,13 +580,11 @@ impl Game { } } - return self.end.map(|t| t < Instant::now()).unwrap_or_default(); + self.end.map(|t| t < Instant::now()).unwrap_or_default() } pub fn count_chefs(&self) -> usize { - self.players - .iter() - .map(|(_, p)| if p.character >= 0 { 1 } else { 0 }) + self.players.values().map(|p| if p.character >= 0 { 1 } else { 0 }) .sum() } } @@ -606,7 +610,7 @@ pub fn interact_effect( let this_had_item = this.is_some(); let other_had_item = other.is_some(); - if let Some(effect) = interact(&data, edge, this_tile_kind, this, other, points, automated) { + if let Some(effect) = interact(data, edge, this_tile_kind, this, other, points, automated) { match effect { InteractEffect::Put => { info!("put {this_loc} <- {other_loc}"); diff --git a/server/src/interaction.rs b/server/src/interaction.rs index b3f6af8c..2f6c940a 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -80,20 +80,14 @@ impl Recipe { match self { Recipe::Passive { input, .. } => vec![*input], Recipe::Active { input, .. } => vec![*input], - Recipe::Instant { inputs, .. } => { - inputs.into_iter().flat_map(|e| e.to_owned()).collect() - } + Recipe::Instant { inputs, .. } => inputs.iter().flat_map(|e| e.to_owned()).collect(), } } pub fn outputs(&self) -> Vec { match self { - Recipe::Passive { output, .. } => output.to_owned().into_iter().collect(), - Recipe::Active { outputs, .. } => { - outputs.into_iter().flat_map(|e| e.to_owned()).collect() - } - Recipe::Instant { outputs, .. } => { - outputs.into_iter().flat_map(|e| e.to_owned()).collect() - } + Recipe::Passive { output, .. } => output.iter().copied().collect(), + Recipe::Active { outputs, .. } => outputs.iter().flat_map(|e| e.to_owned()).collect(), + Recipe::Instant { outputs, .. } => outputs.iter().flat_map(|e| e.to_owned()).collect(), } } pub fn supports_tile(&self, tile: Option) -> bool { @@ -161,15 +155,13 @@ pub fn interact( Recipe::Active { input, .. } => { if other.is_none() { if let Some(item) = this { - if item.kind == *input { - if item.active.is_none() { - info!("start active recipe {ri:?}"); - item.active = Some(Involvement { - recipe: ri, - working: 1, - progress: 0., - }); - } + if item.kind == *input && item.active.is_none() { + info!("start active recipe {ri:?}"); + item.active = Some(Involvement { + recipe: ri, + working: 1, + progress: 0., + }); } } } -- cgit v1.2.3-70-g09d2