diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:21 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:21 +0100 |
commit | 58ae76634da13423894a958e3a71cf8f001054e4 (patch) | |
tree | f017868a5af70e92d2bffb7547e59bf63473bf13 /stockton-levels | |
parent | 4dacd2a58f778818d7c2f4d73980b0967c7202b4 (diff) |
feat(levels): add get_texture method to HasTextures trait
Diffstat (limited to 'stockton-levels')
-rw-r--r-- | stockton-levels/src/q3/textures.rs | 8 | ||||
-rw-r--r-- | stockton-levels/src/traits/textures.rs | 1 |
2 files changed, 7 insertions, 2 deletions
diff --git a/stockton-levels/src/q3/textures.rs b/stockton-levels/src/q3/textures.rs index 85093b5..5aa1ba2 100644 --- a/stockton-levels/src/q3/textures.rs +++ b/stockton-levels/src/q3/textures.rs @@ -42,7 +42,7 @@ pub fn from_data(lump: &[u8]) -> Result<Box<[Texture]>> { for n in 0..length { let offset = n * TEXTURE_LUMP_SIZE; textures.push(Texture { - name: str::from_utf8(&lump[offset..offset + 64]).map_err(|_| ParseError::Invalid)?.to_owned(), + name: str::from_utf8(&lump[offset..offset + 64]).map_err(|_| ParseError::Invalid)?.trim_matches('\0').to_owned(), surface: SurfaceFlags::from_bits_truncate(slice_to_u32(&lump[offset + 64..offset + 68])), contents: ContentsFlags::from_bits_truncate(slice_to_u32(&lump[offset + 68..offset + 72])), }); @@ -57,6 +57,10 @@ impl<T: CoordSystem> HasTextures for Q3BSPFile<T> { fn textures_iter<'a>(&'a self) -> Self::TexturesIter<'a> { self.textures.iter() } + + fn get_texture<'a>(&'a self, idx: u32) -> &'a Texture { + &self.textures[idx as usize] + } } #[test] @@ -75,7 +79,7 @@ fn textures_single_texture() { assert_eq!(lump.len(), 1); - assert_eq!(lump[0].name, format!("{:64}", "TEST TEXTURE")); + assert_eq!(lump[0].name, "TEST TEXTURE"); assert_eq!( lump[0].surface, SurfaceFlags::NO_DAMAGE | SurfaceFlags::SLICK | SurfaceFlags::FLESH | SurfaceFlags::DUST diff --git a/stockton-levels/src/traits/textures.rs b/stockton-levels/src/traits/textures.rs index ffd2a2f..16213ea 100644 --- a/stockton-levels/src/traits/textures.rs +++ b/stockton-levels/src/traits/textures.rs @@ -146,4 +146,5 @@ pub trait HasTextures { type TexturesIter<'a>: Iterator<Item = &'a Texture>; fn textures_iter<'a>(&'a self) -> Self::TexturesIter<'a>; + fn get_texture<'a>(&'a self, idx: u32) -> &'a Texture; } |