From 03906a7f0a30f69dcd8e58e10b06f2aa944b4ca0 Mon Sep 17 00:00:00 2001 From: jake Date: Fri, 18 Jun 2021 13:00:04 -0600 Subject: [PATCH] lint src/ship/map/* --- src/ship/map/area.rs | 6 ++++-- src/ship/map/enemy.rs | 2 +- src/ship/map/maps.rs | 9 ++++----- src/ship/map/object.rs | 2 +- src/ship/map/variant.rs | 12 ++++++------ src/ship/quests.rs | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/ship/map/area.rs b/src/ship/map/area.rs index 9621109..a26aa19 100644 --- a/src/ship/map/area.rs +++ b/src/ship/map/area.rs @@ -291,13 +291,15 @@ pub struct MapAreaLookupBuilder { map_areas: HashMap, } -impl MapAreaLookupBuilder { - pub fn new() -> MapAreaLookupBuilder { +impl Default for MapAreaLookupBuilder { + fn default() -> MapAreaLookupBuilder { MapAreaLookupBuilder { map_areas: HashMap::new() } } +} +impl MapAreaLookupBuilder { pub fn add(mut self, value: u16, map_area: MapArea) -> MapAreaLookupBuilder { self.map_areas.insert(value, map_area); self diff --git a/src/ship/map/enemy.rs b/src/ship/map/enemy.rs index 8eab744..a9601d2 100644 --- a/src/ship/map/enemy.rs +++ b/src/ship/map/enemy.rs @@ -253,7 +253,7 @@ impl MapEnemy { Ok(MapEnemy { monster: monster, - map_area: map_area.clone(), + map_area: *map_area, hp: 0, dropped_item: false, gave_exp: false, diff --git a/src/ship/map/maps.rs b/src/ship/map/maps.rs index 3f7f515..15e790c 100644 --- a/src/ship/map/maps.rs +++ b/src/ship/map/maps.rs @@ -17,14 +17,14 @@ pub fn objects_from_stream(cursor: &mut impl Read, episode: &Episode, map_area: let mut object_data = Vec::new(); while let Ok(raw_object) = RawMapObject::from_byte_stream(cursor) { - let object = MapObject::from_raw(raw_object.clone(), *episode, map_area); + let object = MapObject::from_raw(raw_object, *episode, map_area); object_data.push(object.ok()); } object_data } fn objects_from_map_data(path: PathBuf, episode: &Episode, map_area: &MapArea) -> Vec> { - let mut cursor = File::open(path.clone()).unwrap(); + let mut cursor = File::open(path).unwrap(); objects_from_stream(&mut cursor, episode, map_area) } @@ -32,8 +32,7 @@ fn parse_enemy(episode: &Episode, map_area: &MapArea, raw_enemy: RawMapEnemy) -> let enemy = MapEnemy::from_raw(raw_enemy, episode, map_area); enemy .map_or(vec![None], |monster| { - let mut monsters = Vec::new(); - monsters.push(Some(monster)); + let mut monsters = vec![Some(monster)]; match monster.monster { MonsterType::Monest => { @@ -275,7 +274,7 @@ impl Maps { let maps = Maps { enemy_data: map_variants.iter().fold(Vec::new(), |mut enemy_data, map_variant| { - enemy_data.append(&mut enemy_data_from_map_data(&map_variant, &room_mode.episode())); + enemy_data.append(&mut enemy_data_from_map_data(map_variant, &room_mode.episode())); enemy_data }), object_data: map_variants.iter().map(|map_variant| { diff --git a/src/ship/map/object.rs b/src/ship/map/object.rs index dde1e7e..e431c88 100644 --- a/src/ship/map/object.rs +++ b/src/ship/map/object.rs @@ -160,7 +160,7 @@ impl MapObject { Ok(MapObject { object: object, - map: map_area.clone(), + map: *map_area, dropped_item: false, }) } diff --git a/src/ship/map/variant.rs b/src/ship/map/variant.rs index a969960..7e85bee 100644 --- a/src/ship/map/variant.rs +++ b/src/ship/map/variant.rs @@ -198,9 +198,9 @@ impl MapVariant { MapArea::Forest1 => format!("data/maps/map_forest01_0{}_offe.dat", self.minor*2), MapArea::Forest2 => { match self.minor { - 0 => format!("data/maps/map_forest02_00_offe.dat"), - 1 => format!("data/maps/map_forest02_03_offe.dat"), - 2 => format!("data/maps/map_forest02_04_offe.dat"), + 0 => "data/maps/map_forest02_00_offe.dat".into(), + 1 => "data/maps/map_forest02_03_offe.dat".into(), + 2 => "data/maps/map_forest02_04_offe.dat".into(), _ => unreachable!() }}, MapArea::Caves1 => format!("data/maps/map_cave01_0{}_0{}_offe.dat", self.major, self.minor), @@ -302,9 +302,9 @@ impl MapVariant { MapArea::Forest1 => format!("data/maps/map_forest01_0{}o.dat", self.minor*2), MapArea::Forest2 => { match self.minor { - 0 => format!("data/maps/map_forest02_00o.dat"), - 1 => format!("data/maps/map_forest02_03o.dat"), - 2 => format!("data/maps/map_forest02_04o.dat"), + 0 => "data/maps/map_forest02_00o.dat".into(), + 1 => "data/maps/map_forest02_03o.dat".into(), + 2 => "data/maps/map_forest02_04o.dat".into(), _ => unreachable!() }}, MapArea::Caves1 => format!("data/maps/map_cave01_0{}_0{}o.dat", self.major, self.minor), diff --git a/src/ship/quests.rs b/src/ship/quests.rs index 0b6be3d..7b1316f 100644 --- a/src/ship/quests.rs +++ b/src/ship/quests.rs @@ -107,7 +107,7 @@ fn quest_episode(bin: &[u8]) -> Option { } fn map_area_mappings(bin: &[u8]) -> MapAreaLookup { - let mut map_areas = MapAreaLookupBuilder::new(); + let mut map_areas = MapAreaLookupBuilder::default(); for bytes in bin.windows(4) { // BB_Map_Designate if bytes[0] == 0xF9 && bytes[1] == 0x51 {