use crate::wad::{RawLumpSlice, Tag};
use crate::wad::ffi::{doom, halflife, quake};
use alloc::vec::Vec;
#[repr(u8)]
#[derive(Clone, Debug)]
pub(super) enum Inner {
Wad {
is_pwad: bool,
directory: Vec<doom::filelump_t>,
} = Tag::Wad as u8,
Wad2 {
directory: Vec<quake::lumpinfo_t>,
} = Tag::Wad2 as u8,
Wad3 {
directory: Vec<halflife::lumpinfo_t>,
} = Tag::Wad3 as u8,
}
impl Inner {
#[inline]
#[must_use]
pub fn tag(&self) -> Tag {
match *self {
Self::Wad { .. } => Tag::Wad,
Self::Wad2 { .. } => Tag::Wad2,
Self::Wad3 { .. } => Tag::Wad3,
}
}
#[inline]
#[must_use]
pub fn magic(&self) -> [i8; 4] {
let bytes = match *self {
Self::Wad { is_pwad: false, .. } => b"IWAD",
Self::Wad { is_pwad: true, .. } => b"PWAD",
Self::Wad2 { .. } => b"WAD2",
Self::Wad3 { .. } => b"WAD3",
};
bytes.map(u8::cast_signed)
}
#[inline]
#[must_use]
pub fn lump_count(&self) -> usize {
match *self {
Self::Wad { ref directory, .. } => directory.len(),
Self::Wad2 { ref directory, .. } => directory.len(),
Self::Wad3 { ref directory, .. } => directory.len(),
}
}
#[inline]
#[must_use]
pub fn directory(&self) -> RawLumpSlice<'_> {
match *self {
Self::Wad { ref directory, .. } => {
directory.as_slice().into()
}
Self::Wad2 { ref directory, .. } => {
directory.as_slice().into()
}
Self::Wad3 { ref directory, .. } => {
directory.as_slice().into()
}
}
}
}