aboutsummaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-09-16 18:00:28 +0200
committermetamuffin <metamuffin@disroot.org>2024-09-16 18:00:35 +0200
commit499f4994a6a8507dcca20ed820c851be9a2343c1 (patch)
tree9100c6c924e116e811d94d7188353f87819d02d3 /server/src
parent709fd5ddaaec290165e85b48b237cb82563b9e87 (diff)
downloadhurrycurry-499f4994a6a8507dcca20ed820c851be9a2343c1.tar
hurrycurry-499f4994a6a8507dcca20ed820c851be9a2343c1.tar.bz2
hurrycurry-499f4994a6a8507dcca20ed820c851be9a2343c1.tar.zst
fix all clippy things
Diffstat (limited to 'server/src')
-rw-r--r--server/src/data/index.rs13
-rw-r--r--server/src/data/mod.rs6
-rw-r--r--server/src/entity/bot.rs2
-rw-r--r--server/src/interaction.rs105
-rw-r--r--server/src/server.rs2
-rw-r--r--server/src/state.rs11
6 files changed, 64 insertions, 75 deletions
diff --git a/server/src/data/index.rs b/server/src/data/index.rs
index 1c206d83..e056cfc0 100644
--- a/server/src/data/index.rs
+++ b/server/src/data/index.rs
@@ -11,14 +11,11 @@ impl GamedataIndex {
self.recipe_passive_by_input.clear();
for (ri, r) in data.recipes() {
- match r {
- Recipe::Passive { input, .. } => {
- self.recipe_passive_by_input
- .entry(*input)
- .or_default()
- .push(ri);
- }
- _ => (),
+ if let Recipe::Passive { input, .. } = r {
+ self.recipe_passive_by_input
+ .entry(*input)
+ .or_default()
+ .push(ri);
}
}
}
diff --git a/server/src/data/mod.rs b/server/src/data/mod.rs
index 246f695e..91b32a42 100644
--- a/server/src/data/mod.rs
+++ b/server/src/data/mod.rs
@@ -152,14 +152,12 @@ impl DataIndex {
&self
.read_recipes(
map_in
- .recipes
- .as_ref()
- .map(|a| a.as_str())
+ .recipes.as_deref()
.unwrap_or("default"),
)
.await?,
)?;
- Ok(build_data(&self.maps, map.to_string(), map_in, recipes_in)?)
+ build_data(&self.maps, map.to_string(), map_in, recipes_in)
}
}
diff --git a/server/src/entity/bot.rs b/server/src/entity/bot.rs
index cc67f640..79ca97f1 100644
--- a/server/src/entity/bot.rs
+++ b/server/src/entity/bot.rs
@@ -55,7 +55,7 @@ impl<T: BotAlgo> Entity for BotDriver<T> {
})
}
- let input = self.algo.tick(self.id, &c.game, c.dt);
+ let input = self.algo.tick(self.id, c.game, c.dt);
if input.leave {
info!("leave {:?}", self.id);
c.packet_in.push_back(PacketS::Leave { player: self.id });
diff --git a/server/src/interaction.rs b/server/src/interaction.rs
index 0721fa81..3a950fba 100644
--- a/server/src/interaction.rs
+++ b/server/src/interaction.rs
@@ -22,6 +22,7 @@ use std::collections::VecDeque;
use crate::data::index::GamedataIndex;
+#[allow(clippy::too_many_arguments)]
pub fn interact(
data: &Gamedata,
edge: bool,
@@ -108,32 +109,30 @@ pub fn interact(
}
if this.is_none() {
if let Some(item) = &other {
- if item.kind == *input {
- if item.active.is_none() {
- let mut item = other.take().unwrap();
- info!("start active recipe {ri:?}");
- item.active = Some(Involvement {
- player,
- recipe: ri,
- speed: *speed,
- position: 0.,
- warn: false,
- });
- *this = Some(item);
- score.active_recipes += 1;
- packet_out.push_back(PacketC::MoveItem {
- from: other_loc,
- to: this_loc,
- });
- packet_out.push_back(PacketC::SetProgress {
- player,
- item: this_loc,
- position: 0.,
- speed: *speed,
- warn: false,
- });
- return;
- }
+ if item.kind == *input && item.active.is_none() {
+ let mut item = other.take().unwrap();
+ info!("start active recipe {ri:?}");
+ item.active = Some(Involvement {
+ player,
+ recipe: ri,
+ speed: *speed,
+ position: 0.,
+ warn: false,
+ });
+ *this = Some(item);
+ score.active_recipes += 1;
+ packet_out.push_back(PacketC::MoveItem {
+ from: other_loc,
+ to: this_loc,
+ });
+ packet_out.push_back(PacketC::SetProgress {
+ player,
+ item: this_loc,
+ position: 0.,
+ speed: *speed,
+ warn: false,
+ });
+ return;
}
}
}
@@ -194,7 +193,6 @@ pub fn interact(
from: this_loc,
to: other_loc,
});
- return;
}
}
}
@@ -209,6 +207,7 @@ pub enum TickEffect {
Produce,
}
+#[allow(clippy::too_many_arguments)]
pub fn tick_slot(
dt: f32,
data: &Gamedata,
@@ -273,34 +272,31 @@ pub fn tick_slot(
warn: a.warn,
item: slot_loc,
});
- return;
}
- } else {
- if let Some(recipes) = data_index.recipe_passive_by_input.get(&item.kind) {
- for &ri in recipes {
- let recipe = data.recipe(ri);
- if recipe.supports_tile(tile) {
- if let Recipe::Passive {
- input, warn, speed, ..
- } = recipe
- {
- if *input == item.kind {
- item.active = Some(Involvement {
- player: None,
- recipe: ri,
- position: 0.,
- warn: *warn,
- speed: *speed,
- });
- packet_out.push_back(PacketC::SetProgress {
- player: None,
- position: 0.,
- speed: *speed,
- warn: *warn,
- item: slot_loc,
- });
- return;
- }
+ } else if let Some(recipes) = data_index.recipe_passive_by_input.get(&item.kind) {
+ for &ri in recipes {
+ let recipe = data.recipe(ri);
+ if recipe.supports_tile(tile) {
+ if let Recipe::Passive {
+ input, warn, speed, ..
+ } = recipe
+ {
+ if *input == item.kind {
+ item.active = Some(Involvement {
+ player: None,
+ recipe: ri,
+ position: 0.,
+ warn: *warn,
+ speed: *speed,
+ });
+ packet_out.push_back(PacketC::SetProgress {
+ player: None,
+ position: 0.,
+ speed: *speed,
+ warn: *warn,
+ item: slot_loc,
+ });
+ return;
}
}
}
@@ -309,6 +305,7 @@ pub fn tick_slot(
}
}
+#[allow(clippy::too_many_arguments)]
fn produce(
player: Option<PlayerID>,
this_had_item: bool,
diff --git a/server/src/server.rs b/server/src/server.rs
index fd7db5b5..01460cb9 100644
--- a/server/src/server.rs
+++ b/server/src/server.rs
@@ -399,7 +399,7 @@ impl Server {
let last_position_update = self
.last_movement_update
.entry(player)
- .or_insert_with(|| Instant::now());
+ .or_insert_with(Instant::now);
let dt = last_position_update.elapsed();
*last_position_update += dt;
let diff = pos - pd.movement.position;
diff --git a/server/src/state.rs b/server/src/state.rs
index e368317c..b9a43f6b 100644
--- a/server/src/state.rs
+++ b/server/src/state.rs
@@ -76,15 +76,12 @@ impl Server {
self.packet_in(packet, &mut replies)?;
for p in &replies {
- match p {
- PacketC::Joined { id } => {
- self.connections.entry(conn).or_default().insert(*id);
- }
- _ => (),
+ if let PacketC::Joined { id } = p {
+ self.connections.entry(conn).or_default().insert(*id);
}
}
- if self.count_chefs() <= 0 && !self.game.lobby {
+ if self.count_chefs() == 0 && !self.game.lobby {
self.tx
.send(PacketC::ServerMessage {
text: "Game was aborted due to a lack of players".to_string(),
@@ -97,7 +94,7 @@ impl Server {
pub async fn disconnect(&mut self, conn: ConnectionID) {
if let Some(players) = self.connections.get(&conn) {
- for player in players.to_owned() {
+ for player in players.clone() {
let _ = self.packet_in_outer(conn, PacketS::Leave { player }).await;
}
}