Browse Source

lint src/ship/map/*

jake 4 years ago
committed by andy
parent
commit
9ebbf16670
  1. 6
      src/ship/map/area.rs
  2. 2
      src/ship/map/enemy.rs
  3. 9
      src/ship/map/maps.rs
  4. 2
      src/ship/map/object.rs
  5. 12
      src/ship/map/variant.rs
  6. 2
      src/ship/quests.rs

6
src/ship/map/area.rs

@ -291,13 +291,15 @@ pub struct MapAreaLookupBuilder {
map_areas: HashMap<u16, MapArea>,
}
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

2
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,

9
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<Option<MapObject>> {
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| {

2
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,
})
}

12
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),

2
src/ship/quests.rs

@ -107,7 +107,7 @@ fn quest_episode(bin: &[u8]) -> Option<Episode> {
}
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 {

Loading…
Cancel
Save