Browse Source

rename dumb thing to something slightly less dumb

pbs
jake 4 years ago
parent
commit
1d78f3dd08
  1. 39
      src/ship/map/area.rs
  2. 12
      src/ship/quests.rs
  3. 6
      src/ship/room.rs

39
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<u16, MapArea>);
pub struct MapAreaLookup(HashMap<u16, MapArea>);
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<u16, MapArea>,
}
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)
}
}

12
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<T: Read + Seek>(cursor: &mut T, episode: &Episode, map_areas: &MapAreaMapper) -> Result<DatBlock, ParseDatError> {
fn read_dat_section_header<T: Read + Seek>(cursor: &mut T, episode: &Episode, map_areas: &MapAreaLookup) -> Result<DatBlock, ParseDatError> {
let header = cursor.read_u32::<LittleEndian>()?;
let _offset = cursor.read_u32::<LittleEndian>()?;
let area = cursor.read_u16::<LittleEndian>()?;
@ -106,8 +106,8 @@ fn quest_episode(bin: &[u8]) -> Option<Episode> {
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<Option<MapEnemy>>, Vec<Option<MapObject>>), ParseDatError> {
fn parse_dat(dat: &[u8], episode: &Episode, map_areas: &MapAreaLookup) -> Result<(Vec<Option<MapEnemy>>, Vec<Option<MapObject>>), 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<u8>,
pub enemies: Vec<Option<MapEnemy>>,
pub objects: Vec<Option<MapObject>>,
pub map_areas: MapAreaMapper,
pub map_areas: MapAreaLookup,
}
impl Quest {

6
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<HashMap<MonsterType, MonsterStats>>,
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()),
})
}
}
Loading…
Cancel
Save