strafe-project/src/lib.rs

60 lines
1.7 KiB
Rust
Raw Normal View History

2024-01-19 00:59:00 +00:00
use binrw::BinReaderExt;
2024-01-16 03:09:34 +00:00
2024-01-16 03:30:26 +00:00
pub mod file;
pub mod map;
pub mod bot;
pub mod demo;
2024-01-16 03:09:34 +00:00
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-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-01-19 00:59:00 +00:00
let file=file::File::new(input).map_err(|e|Error::Header(e))?;
2024-01-19 00:39:58 +00:00
Ok(match file.fourcc(){
file::FourCC::Map=>SNF::Map(map::StreamableMap::new(file).map_err(|e|Error::Map(e))?),
file::FourCC::Bot=>SNF::Bot(bot::StreamableBot::new(file).map_err(|e|Error::Bot(e))?),
file::FourCC::Demo=>SNF::Demo(demo::StreamableDemo::new(file).map_err(|e|Error::Demo(e))?),
})
}
2024-01-19 03:28:01 +00:00
pub fn read_map<R:BinReaderExt>(input:R)->Result<map::StreamableMap<R>,Error>{
2024-01-19 00:59:00 +00:00
let file=file::File::new(input).map_err(|e|Error::Header(e))?;
2024-01-19 00:39:58 +00:00
match file.fourcc(){
file::FourCC::Map=>Ok(map::StreamableMap::new(file).map_err(|e|Error::Map(e))?),
_=>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-01-19 00:59:00 +00:00
let file=file::File::new(input).map_err(|e|Error::Header(e))?;
2024-01-19 00:39:58 +00:00
match file.fourcc(){
file::FourCC::Bot=>Ok(bot::StreamableBot::new(file).map_err(|e|Error::Bot(e))?),
_=>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-01-19 00:59:00 +00:00
let file=file::File::new(input).map_err(|e|Error::Header(e))?;
2024-01-19 00:39:58 +00:00
match file.fourcc(){
file::FourCC::Demo=>Ok(demo::StreamableDemo::new(file).map_err(|e|Error::Demo(e))?),
_=>Err(Error::UnexpectedFourCC)
}
2024-01-16 03:09:34 +00:00
}
#[cfg(test)]
mod tests {
//use super::*;
#[test]
fn test() {
}
}