2024-01-19 00:59:00 +00:00
|
|
|
use binrw::BinReaderExt;
|
2024-01-16 03:09:34 +00:00
|
|
|
|
2024-07-23 18:05:01 +00:00
|
|
|
mod newtypes;
|
|
|
|
|
2024-07-25 17:48:04 +00:00
|
|
|
mod file;
|
2024-01-16 03:30:26 +00:00
|
|
|
pub mod map;
|
|
|
|
pub mod bot;
|
|
|
|
pub mod demo;
|
2024-01-16 03:09:34 +00:00
|
|
|
|
2024-07-26 00:47:00 +00:00
|
|
|
#[derive(Debug)]
|
2024-01-16 03:30:26 +00:00
|
|
|
pub enum Error{
|
2024-01-19 00:39:58 +00:00
|
|
|
UnexpectedFourCC,
|
2024-01-16 03:30:26 +00:00
|
|
|
Header(file::Error),
|
|
|
|
Map(map::Error),
|
|
|
|
Bot(bot::Error),
|
|
|
|
Demo(demo::Error),
|
|
|
|
}
|
2024-07-26 00:47:00 +00:00
|
|
|
impl std::fmt::Display for Error{
|
|
|
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
|
|
|
write!(f,"{self:?}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl std::error::Error for Error{}
|
2024-01-16 03:30:26 +00:00
|
|
|
|
2024-01-19 03:28:01 +00:00
|
|
|
pub enum SNF<R:BinReaderExt>{
|
|
|
|
Map(map::StreamableMap<R>),
|
|
|
|
Bot(bot::StreamableBot<R>),
|
|
|
|
Demo(demo::StreamableDemo<R>),
|
2024-01-16 03:30:26 +00:00
|
|
|
}
|
|
|
|
|
2024-01-19 03:28:01 +00:00
|
|
|
pub fn read_snf<R:BinReaderExt>(input:R)->Result<SNF<R>,Error>{
|
2024-02-07 09:01:23 +00:00
|
|
|
let file=file::File::new(input).map_err(Error::Header)?;
|
2024-01-19 00:39:58 +00:00
|
|
|
Ok(match file.fourcc(){
|
2024-02-07 09:01:23 +00:00
|
|
|
file::FourCC::Map=>SNF::Map(map::StreamableMap::new(file).map_err(Error::Map)?),
|
|
|
|
file::FourCC::Bot=>SNF::Bot(bot::StreamableBot::new(file).map_err(Error::Bot)?),
|
|
|
|
file::FourCC::Demo=>SNF::Demo(demo::StreamableDemo::new(file).map_err(Error::Demo)?),
|
2024-01-19 00:39:58 +00:00
|
|
|
})
|
|
|
|
}
|
2024-01-19 03:28:01 +00:00
|
|
|
pub fn read_map<R:BinReaderExt>(input:R)->Result<map::StreamableMap<R>,Error>{
|
2024-02-07 09:01:23 +00:00
|
|
|
let file=file::File::new(input).map_err(Error::Header)?;
|
2024-01-19 00:39:58 +00:00
|
|
|
match file.fourcc(){
|
2024-02-07 09:01:23 +00:00
|
|
|
file::FourCC::Map=>Ok(map::StreamableMap::new(file).map_err(Error::Map)?),
|
2024-01-19 00:39:58 +00:00
|
|
|
_=>Err(Error::UnexpectedFourCC)
|
|
|
|
}
|
|
|
|
}
|
2024-01-19 03:28:01 +00:00
|
|
|
pub fn read_bot<R:BinReaderExt>(input:R)->Result<bot::StreamableBot<R>,Error>{
|
2024-02-07 09:01:23 +00:00
|
|
|
let file=file::File::new(input).map_err(Error::Header)?;
|
2024-01-19 00:39:58 +00:00
|
|
|
match file.fourcc(){
|
2024-02-07 09:01:23 +00:00
|
|
|
file::FourCC::Bot=>Ok(bot::StreamableBot::new(file).map_err(Error::Bot)?),
|
2024-01-19 00:39:58 +00:00
|
|
|
_=>Err(Error::UnexpectedFourCC)
|
|
|
|
}
|
|
|
|
}
|
2024-01-19 03:28:01 +00:00
|
|
|
pub fn read_demo<R:BinReaderExt>(input:R)->Result<demo::StreamableDemo<R>,Error>{
|
2024-02-07 09:01:23 +00:00
|
|
|
let file=file::File::new(input).map_err(Error::Header)?;
|
2024-01-19 00:39:58 +00:00
|
|
|
match file.fourcc(){
|
2024-02-07 09:01:23 +00:00
|
|
|
file::FourCC::Demo=>Ok(demo::StreamableDemo::new(file).map_err(Error::Demo)?),
|
2024-01-19 00:39:58 +00:00
|
|
|
_=>Err(Error::UnexpectedFourCC)
|
|
|
|
}
|
2024-01-16 03:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
//use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test() {
|
|
|
|
}
|
|
|
|
}
|