From 548e88f7c4907a1f429f136400e6c12faf637d1e Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sat, 26 Feb 2022 21:16:59 +0000 Subject: [PATCH 1/2] Fix clippy lints in purple-night build.rs --- examples/the-purple-night/build.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/examples/the-purple-night/build.rs b/examples/the-purple-night/build.rs index c329d950..94914e8e 100644 --- a/examples/the-purple-night/build.rs +++ b/examples/the-purple-night/build.rs @@ -67,7 +67,7 @@ fn main() { write!(&mut writer, "{}", output).unwrap(); } -fn extract_tiles<'a>(layer: &'a tiled::LayerData) -> impl Iterator + 'a { +fn extract_tiles(layer: &'_ tiled::LayerData) -> impl Iterator + '_ { match layer { tiled::LayerData::Finite(tiles) => { tiles.iter().flat_map(|row| row.iter().map(|tile| tile.gid)) @@ -84,17 +84,14 @@ fn get_map_id(tileid: u32) -> u16 { } } -fn get_spawn_locations<'a>( - object_group: &'a tiled::ObjectGroup, +fn get_spawn_locations( + object_group: &tiled::ObjectGroup, enemy_type: &str, -) -> ( - impl Iterator + 'a, - impl Iterator + 'a, -) { +) -> (Vec, Vec) { let mut spawns = object_group .objects .iter() - .filter(|object| &object.obj_type == enemy_type) + .filter(|object| object.obj_type == enemy_type) .map(|object| (object.x as u16, object.y as u16)) .collect::>(); @@ -103,5 +100,5 @@ fn get_spawn_locations<'a>( let xs = spawns.iter().map(|pos| pos.0).collect::>(); let ys = spawns.iter().map(|pos| pos.1).collect::>(); - (xs.into_iter(), ys.into_iter()) + (xs, ys) } From e86bb71abd702346cc0f19a2fe72ee6f97777f5e Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sat, 26 Feb 2022 21:21:54 +0000 Subject: [PATCH 2/2] Fix clippy lints in the-purple-night --- examples/the-purple-night/src/main.rs | 45 ++++++++++++++------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/examples/the-purple-night/src/main.rs b/examples/the-purple-night/src/main.rs index bdb52e2c..ea00124f 100644 --- a/examples/the-purple-night/src/main.rs +++ b/examples/the-purple-night/src/main.rs @@ -6,6 +6,8 @@ extern crate alloc; mod rng; mod sfx; +use core::cmp::Ordering; + use alloc::vec::Vec; use rng::get_random; @@ -324,7 +326,7 @@ impl SwordState { *counter = 0; } match self { - SwordState::LongSword => (0 + *counter / 8) * 4, + SwordState::LongSword => (*counter / 8) * 4, SwordState::ShortSword => (41 + *counter / 8) * 4, SwordState::Dagger => (96 + *counter / 8) * 4, SwordState::Swordless => (154 + *counter / 8) * 4, @@ -943,12 +945,10 @@ impl SlimeData { .set_tile_id((29 + self.sprite_offset / 16) * 4); if (player.entity.position - entity.position).manhattan_distance() < 40.into() { - let direction = if player.entity.position.x > entity.position.x { - Tri::Positive - } else if player.entity.position.x < entity.position.x { - Tri::Negative - } else { - Tri::Zero + let direction = match player.entity.position.x.cmp(&entity.position.x) { + Ordering::Equal => Tri::Zero, + Ordering::Greater => Tri::Positive, + Ordering::Less => Tri::Negative, }; self.slime_state = SlimeState::Chasing(direction); @@ -1200,14 +1200,18 @@ impl EmuData { .signum(); entity.velocity.x = velocity; - if velocity > 0.into() { - entity.sprite.set_hflip(true); - self.state = EmuState::Charging(Tri::Positive); - } else if velocity < 0.into() { - self.state = EmuState::Charging(Tri::Negative); - entity.sprite.set_hflip(false); - } else { - self.state = EmuState::Idle; + match velocity.cmp(&0.into()) { + Ordering::Greater => { + entity.sprite.set_hflip(true); + self.state = EmuState::Charging(Tri::Positive); + } + Ordering::Less => { + self.state = EmuState::Charging(Tri::Negative); + entity.sprite.set_hflip(false); + } + Ordering::Equal => { + self.state = EmuState::Idle; + } } } @@ -1916,13 +1920,12 @@ impl<'a> Game<'a> { } self.input.update(); - match self.player.update(&self.input, &self.level, sfx) { - UpdateInstruction::CreateParticle(data, position) => { - let new_particle = Particle::new(object_controller, data, position); + if let UpdateInstruction::CreateParticle(data, position) = + self.player.update(&self.input, &self.level, sfx) + { + let new_particle = Particle::new(object_controller, data, position); - self.particles.insert(new_particle); - } - _ => {} + self.particles.insert(new_particle); } let mut remove = Vec::with_capacity(10);