expose all nav areas

This commit is contained in:
Robin Appelman 2020-05-01 23:50:15 +02:00
commit 95fd2d4da3
3 changed files with 29 additions and 1 deletions

View file

@ -113,6 +113,26 @@ impl NavTree {
}
})
}
/// Get all navigation areas from the nav file
///
/// ## Examples
///
/// ```no_run
/// use sourcenav::get_area_tree;
///
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let file = std::fs::read("path/to/navfile.nav")?;
/// let tree = get_area_tree(file)?;
/// for area in tree.areas() {
/// println!("area: {}", area.id)
/// }
/// # Ok(())
/// # }
/// ```
pub fn areas(&self) -> impl Iterator<Item = &NavArea> {
self.0.iter().map(|(_, (area, _))| area)
}
}
#[test]

View file

@ -1,6 +1,8 @@
use aabb_quadtree::Spatial;
use bitbuffer::{BitRead, BitReadStream, Endianness, ReadError};
use euclid::{TypedPoint2D, TypedRect, TypedSize2D};
use std::fmt;
use std::fmt::Debug;
use std::ops::Index;
/// A 3 dimensional coordinate
@ -11,6 +13,12 @@ pub struct Vector3(pub f32, pub f32, pub f32);
#[derive(Debug, BitRead, Clone, Copy, Eq, PartialEq)]
pub struct NavAreaId(u32);
impl fmt::Display for NavAreaId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
}
}
/// A navigation area from the nav file
#[derive(Debug)]
pub struct NavArea {