From 1d78f3dd086b714895618e92dd71c9a0e3b55316 Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 4 Aug 2020 20:43:02 -0600 Subject: [PATCH] rename dumb thing to something slightly less dumb --- src/ship/map/area.rs | 39 +++++++++++++++++++-------------------- src/ship/quests.rs | 12 ++++++------ src/ship/room.rs | 6 +++--- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/ship/map/area.rs b/src/ship/map/area.rs index 69c9cea..2afcbcd 100644 --- a/src/ship/map/area.rs +++ b/src/ship/map/area.rs @@ -210,16 +210,15 @@ impl MapArea { } -// TODO: rename this to something less silly #[derive(Debug, Clone)] -pub struct MapAreaMapper(HashMap); +pub struct MapAreaLookup(HashMap); -impl MapAreaMapper { +impl MapAreaLookup { pub fn get_area_map(&self, map_area: u16) -> Result<&MapArea, MapAreaError> { self.0.get(&map_area).ok_or(MapAreaError::UnknownMapArea(map_area)) } - fn default_ep1_maps() -> MapAreaMapper { + fn default_ep1_maps() -> MapAreaLookup { let mut ep1 = HashMap::new(); ep1.insert(0, MapArea::Pioneer2Ep1); ep1.insert(1, MapArea::Forest1); @@ -236,10 +235,10 @@ impl MapAreaMapper { ep1.insert(12, MapArea::DeRolLe); ep1.insert(13, MapArea::VolOpt); ep1.insert(14, MapArea::DarkFalz); - MapAreaMapper(ep1) + MapAreaLookup(ep1) } - fn default_ep2_maps() -> MapAreaMapper { + fn default_ep2_maps() -> MapAreaLookup { let mut ep2 = HashMap::new(); ep2.insert(0, MapArea::Pioneer2Ep2); ep2.insert(1, MapArea::VrTempleAlpha); @@ -259,10 +258,10 @@ impl MapAreaMapper { ep2.insert(15, MapArea::GolDragon); ep2.insert(16, MapArea::SeasideNight); ep2.insert(17, MapArea::Tower); - MapAreaMapper(ep2) + MapAreaLookup(ep2) } - fn default_ep4_maps() -> MapAreaMapper { + fn default_ep4_maps() -> MapAreaLookup { let mut ep4 = HashMap::new(); ep4.insert(0, MapArea::Pioneer2Ep4); ep4.insert(1, MapArea::CraterEast); @@ -274,36 +273,36 @@ impl MapAreaMapper { ep4.insert(7, MapArea::SubDesert2); ep4.insert(8, MapArea::SubDesert3); ep4.insert(9, MapArea::SaintMillion); - MapAreaMapper(ep4) + MapAreaLookup(ep4) } - pub fn new(episode: &Episode) -> MapAreaMapper { + pub fn new(episode: &Episode) -> MapAreaLookup { match episode { - Episode::One => MapAreaMapper::default_ep1_maps(), - Episode::Two => MapAreaMapper::default_ep2_maps(), - Episode::Four => MapAreaMapper::default_ep4_maps(), + Episode::One => MapAreaLookup::default_ep1_maps(), + Episode::Two => MapAreaLookup::default_ep2_maps(), + Episode::Four => MapAreaLookup::default_ep4_maps(), } } } -pub struct MapAreaMapperBuilder { +pub struct MapAreaLookupBuilder { map_areas: HashMap, } -impl MapAreaMapperBuilder { - pub fn new() -> MapAreaMapperBuilder { - MapAreaMapperBuilder { +impl MapAreaLookupBuilder { + pub fn new() -> MapAreaLookupBuilder { + MapAreaLookupBuilder { map_areas: HashMap::new() } } - pub fn add(mut self, value: u16, map_area: MapArea) -> MapAreaMapperBuilder { + pub fn add(mut self, value: u16, map_area: MapArea) -> MapAreaLookupBuilder { self.map_areas.insert(value, map_area); self } - pub fn build(self) -> MapAreaMapper { - MapAreaMapper(self.map_areas) + pub fn build(self) -> MapAreaLookup { + MapAreaLookup(self.map_areas) } } diff --git a/src/ship/quests.rs b/src/ship/quests.rs index b5ee452..5853cec 100644 --- a/src/ship/quests.rs +++ b/src/ship/quests.rs @@ -11,7 +11,7 @@ use byteorder::{LittleEndian, ReadBytesExt}; use libpso::util::array_to_utf16; use crate::ship::map::{MapArea, MapAreaError, MapObject, MapEnemy, enemy_data_from_stream, objects_from_stream}; use crate::ship::room::Episode; -use crate::ship::map::area::{MapAreaMapper, MapAreaMapperBuilder}; +use crate::ship::map::area::{MapAreaLookup, MapAreaLookupBuilder}; #[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq, PartialOrd, Ord)] @@ -61,7 +61,7 @@ enum DatBlock { } -fn read_dat_section_header(cursor: &mut T, episode: &Episode, map_areas: &MapAreaMapper) -> Result { +fn read_dat_section_header(cursor: &mut T, episode: &Episode, map_areas: &MapAreaLookup) -> Result { let header = cursor.read_u32::()?; let _offset = cursor.read_u32::()?; let area = cursor.read_u16::()?; @@ -106,8 +106,8 @@ fn quest_episode(bin: &[u8]) -> Option { None } -fn map_area_mappings(bin: &[u8]) -> MapAreaMapper { - let mut map_areas = MapAreaMapperBuilder::new(); +fn map_area_mappings(bin: &[u8]) -> MapAreaLookup { + let mut map_areas = MapAreaLookupBuilder::new(); for bytes in bin.windows(4) { // BB_Map_Designate if bytes[0] == 0xF9 && bytes[1] == 0x51 { @@ -121,7 +121,7 @@ fn map_area_mappings(bin: &[u8]) -> MapAreaMapper { map_areas.build() } -fn parse_dat(dat: &[u8], episode: &Episode, map_areas: &MapAreaMapper) -> Result<(Vec>, Vec>), ParseDatError> { +fn parse_dat(dat: &[u8], episode: &Episode, map_areas: &MapAreaLookup) -> Result<(Vec>, Vec>), ParseDatError> { let mut cursor = Cursor::new(dat); let header_iter = std::iter::from_fn(move || { @@ -169,7 +169,7 @@ pub struct Quest { pub dat_blob: Vec, pub enemies: Vec>, pub objects: Vec>, - pub map_areas: MapAreaMapper, + pub map_areas: MapAreaLookup, } impl Quest { diff --git a/src/ship/room.rs b/src/ship/room.rs index bf8c594..7ab224f 100644 --- a/src/ship/room.rs +++ b/src/ship/room.rs @@ -6,7 +6,7 @@ use crate::ship::map::Maps; use crate::ship::drops::DropTable; use crate::entity::character::SectionID; use crate::ship::monster::{load_monster_stats_table, MonsterType, MonsterStats}; -use crate::ship::map::area::MapAreaMapper; +use crate::ship::map::area::MapAreaLookup; #[derive(Debug)] pub enum RoomCreationError { @@ -165,7 +165,7 @@ pub struct RoomState { pub random_seed: u32, pub bursting: bool, pub monster_stats: Box>, - pub map_areas: MapAreaMapper, + pub map_areas: MapAreaLookup, // items on ground // enemy info } @@ -240,7 +240,7 @@ impl RoomState { section_id: section_id, drop_table: Box::new(DropTable::new(room_mode.episode(), room_mode.difficulty(), section_id)), bursting: false, - map_areas: MapAreaMapper::new(&room_mode.episode()), + map_areas: MapAreaLookup::new(&room_mode.episode()), }) } }