diff options
author | metamuffin <metamuffin@disroot.org> | 2025-09-30 21:33:38 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-09-30 21:33:38 +0200 |
commit | f15c20e887a58ae8d65c6d4f240d74a3b74cd55d (patch) | |
tree | a5ac3043a46eb33150e6323d22d8bffbc9048d00 | |
parent | 080672a5fee18336971fa18ab35bb82fb62a0225 (diff) | |
download | hurrycurry-f15c20e887a58ae8d65c6d4f240d74a3b74cd55d.tar hurrycurry-f15c20e887a58ae8d65c6d4f240d74a3b74cd55d.tar.bz2 hurrycurry-f15c20e887a58ae8d65c6d4f240d74a3b74cd55d.tar.zst |
clippy; make use of is_some_and and is_none_or
-rw-r--r-- | server/bot/src/algos/customer.rs | 2 | ||||
-rw-r--r-- | server/bot/src/algos/simple.rs | 2 | ||||
-rw-r--r-- | server/client-lib/src/lib.rs | 2 | ||||
-rw-r--r-- | server/editor/src/main.rs | 4 | ||||
-rw-r--r-- | server/locale/src/message.rs | 2 | ||||
-rw-r--r-- | server/protocol/src/lib.rs | 2 | ||||
-rw-r--r-- | server/registry/src/lobby.rs | 4 | ||||
-rw-r--r-- | server/src/interaction.rs | 6 | ||||
-rw-r--r-- | server/src/server.rs | 8 | ||||
-rw-r--r-- | server/tools/src/main.rs | 2 | ||||
-rw-r--r-- | server/tools/src/map_linter.rs | 45 |
11 files changed, 39 insertions, 40 deletions
diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs index cb5c5b59..8a53ac20 100644 --- a/server/bot/src/algos/customer.rs +++ b/server/bot/src/algos/customer.rs @@ -143,7 +143,7 @@ impl CustomerState { game.data .tile_placeable_items .get(&t.kind) - .map_or(true, |p| p.contains(&requested_item)) + .is_none_or(|p| p.contains(&requested_item)) }) { facing = off.as_vec2(); } diff --git a/server/bot/src/algos/simple.rs b/server/bot/src/algos/simple.rs index 42cc4223..914e8809 100644 --- a/server/bot/src/algos/simple.rs +++ b/server/bot/src/algos/simple.rs @@ -134,7 +134,7 @@ impl<S> Context<'_, S> { .data .tile_placeable_items .get(&t.kind) - .map_or(true, |placable| placable.contains(item)) + .is_none_or(|placable| placable.contains(item)) }) }) .map(|off| pos + off) diff --git a/server/client-lib/src/lib.rs b/server/client-lib/src/lib.rs index 76ef1e77..c77f95e7 100644 --- a/server/client-lib/src/lib.rs +++ b/server/client-lib/src/lib.rs @@ -83,7 +83,7 @@ impl Game { pub fn apply_packet(&mut self, packet: PacketC) { match packet { PacketC::Data { data } => { - self.data = Arc::new(data); + self.data = Arc::new(*data); } PacketC::AddPlayer { id, diff --git a/server/editor/src/main.rs b/server/editor/src/main.rs index 5fb8f1a4..f6fcd9af 100644 --- a/server/editor/src/main.rs +++ b/server/editor/src/main.rs @@ -142,13 +142,13 @@ async fn handle_conn( supports_bincode: false, }); state.out.push(PacketC::Data { - data: Gamedata { + data: Box::new(Gamedata { tile_walkable: (0..TILES.len()).map(TileIndex).collect(), tile_placeable_items: BTreeMap::new(), tile_names: TILES.iter().map(|(name, _, _)| name.to_string()).collect(), current_map: "editor".to_owned(), ..Default::default() - }, + }), }); state.out.push(PacketC::SetIngame { state: true, diff --git a/server/locale/src/message.rs b/server/locale/src/message.rs index bedf45fd..798986fc 100644 --- a/server/locale/src/message.rs +++ b/server/locale/src/message.rs @@ -41,7 +41,7 @@ fn display_message_inner( } = style; match message { Message::Translation { id, params } => { - let Some(template) = locale.get(&id) else { + let Some(template) = locale.get(id) else { return format!("[translation missing: {error}{id}{default}]"); }; let mut s = template.to_string(); diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs index 66f41a6e..c2a7a758 100644 --- a/server/protocol/src/lib.rs +++ b/server/protocol/src/lib.rs @@ -206,7 +206,7 @@ pub enum PacketC { id: PlayerID, }, Data { - data: Gamedata, + data: Box<Gamedata>, }, AddPlayer { id: PlayerID, diff --git a/server/registry/src/lobby.rs b/server/registry/src/lobby.rs index b951f0db..4be2cabd 100644 --- a/server/registry/src/lobby.rs +++ b/server/registry/src/lobby.rs @@ -74,13 +74,13 @@ async fn handle_conn(sock: TcpStream, addr: SocketAddr, entries: &[Entry]) -> Re supports_bincode: false, }); out.push(PacketC::Data { - data: Gamedata { + data: Box::new(Gamedata { tile_walkable: (0..TILES.len()).map(TileIndex).collect(), tile_placeable_items: BTreeMap::new(), tile_names: TILES.iter().map(|(s, _)| s.to_string()).collect(), current_map: "registry".to_owned(), ..Default::default() - }, + }), }); let walkable = HashSet::from_iter(tiles.iter().filter(|(_, v)| !TILES[v.0].1).map(|(k, _)| *k)); for (&tile, &kind) in &tiles { diff --git a/server/src/interaction.rs b/server/src/interaction.rs index 5a8372ee..fef1ca40 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -168,11 +168,11 @@ pub fn interact( } } - let can_place = tile.map_or(true, |tile| { - other.as_ref().map_or(false, |other| { + let can_place = tile.is_none_or(|tile| { + other.as_ref().is_some_and(|other| { data.tile_placeable_items .get(&tile) - .map_or(true, |pl| pl.contains(&other.kind)) + .is_none_or(|pl| pl.contains(&other.kind)) }) }); diff --git a/server/src/server.rs b/server/src/server.rs index 363afc7b..e16fdb61 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -169,7 +169,7 @@ impl GameServerExt for Game { fn prime_client(&self) -> Vec<PacketC> { let mut out = Vec::new(); out.push(PacketC::Data { - data: self.data.as_ref().to_owned(), + data: Box::new(self.data.as_ref().to_owned()), }); out.push(PacketC::Environment { effects: self.environment_effects.clone(), @@ -549,13 +549,13 @@ impl Server { player.interacting = if edge { Some((pos, hand)) } else { None }; // Dont try interacting with player it tile is interactable - let other_pid = if !self + let other_pid = if self .game .data .tile_placeable_items .get(&tile.kind) - .map_or(false, |p| !p.is_empty()) - // TODO check for hand item + // TODO check for hand item + .is_none_or(|p| p.is_empty()) { self.game .players diff --git a/server/tools/src/main.rs b/server/tools/src/main.rs index 03de90b3..c121d5a1 100644 --- a/server/tools/src/main.rs +++ b/server/tools/src/main.rs @@ -107,7 +107,7 @@ fn main() -> Result<()> { let mut index = DataIndex::default(); index.reload()?; for map in index.maps.keys() { - check_map(&map)?; + check_map(map)?; } } else { check_map(&map)?; diff --git a/server/tools/src/map_linter.rs b/server/tools/src/map_linter.rs index 70a170f3..738a9e10 100644 --- a/server/tools/src/map_linter.rs +++ b/server/tools/src/map_linter.rs @@ -148,7 +148,7 @@ pub fn check_map(map: &str) -> Result<()> { let locale = &*FALLBACK_LOCALE; let mut index = DataIndex::default(); index.reload()?; - let (data, serverdata, _) = index.generate(&map)?; + let (data, serverdata, _) = index.generate(map)?; let mut warnings = Vec::new(); @@ -178,7 +178,7 @@ pub fn check_map(map: &str) -> Result<()> { if data .tile_placeable_items .get(&tile) - .map_or(false, |e| e.is_empty()) + .is_some_and(|e| e.is_empty()) { warnings.push(trm!("s.tool.map_linter.exclusive_no_recipe", t = tile)); } @@ -208,23 +208,23 @@ pub fn check_map(map: &str) -> Result<()> { for (&pos, &(tile, _item)) in &serverdata.initial_map { let tile_name = data.tile_name(tile); - if NEED_EASY_ACCESS.contains(&tile_name) || NEED_ACCESS.contains(&tile_name) { - if !has_neighbour_diag(pos, |t| chef_access.contains(&t)) { - warnings.push(trm!( - "s.tool.map_linter.no_chef_access", - t = tile, - s = pos.to_string() - )); - } + if (NEED_EASY_ACCESS.contains(&tile_name) || NEED_ACCESS.contains(&tile_name)) + && !has_neighbour_diag(pos, |t| chef_access.contains(&t)) + { + warnings.push(trm!( + "s.tool.map_linter.no_chef_access", + t = tile, + s = pos.to_string() + )); } - if NEED_EASY_ACCESS.contains(&tile_name) { - if !has_neighbour(&serverdata, pos, |t| data.tile_walkable.contains(&t)) { - warnings.push(trm!( - "s.tool.map_linter.no_easy_access", - t = tile, - s = pos.to_string() - )); - } + if NEED_EASY_ACCESS.contains(&tile_name) + && !has_neighbour(&serverdata, pos, |t| data.tile_walkable.contains(&t)) + { + warnings.push(trm!( + "s.tool.map_linter.no_easy_access", + t = tile, + s = pos.to_string() + )); } if tile_name == "chair" { if !has_neighbour(&serverdata, pos, |t| { @@ -278,7 +278,7 @@ fn has_neighbour(sd: &Serverdata, pos: IVec2, pred: impl Fn(TileIndex) -> bool) .any(|off| { sd.initial_map .get(&(pos + off)) - .map_or(false, |(tile, _)| pred(*tile)) + .is_some_and(|(tile, _)| pred(*tile)) }) } fn has_neighbour_diag(pos: IVec2, pred: impl Fn(IVec2) -> bool) -> bool { @@ -309,11 +309,10 @@ fn fill_walkable(d: &Gamedata, sd: &Serverdata, start: IVec2) -> HashSet<IVec2> if sd .initial_map .get(&npos) - .map_or(false, |(x, _)| d.tile_walkable.contains(x)) + .is_some_and(|(x, _)| d.tile_walkable.contains(x)) + && !visited.contains(&npos) { - if !visited.contains(&npos) { - open.insert(npos); - } + open.insert(npos); } } } |