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),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum SNF{
|
2024-01-18 23:33:22 +00:00
|
|
|
Map(map::StreamableMap),
|
|
|
|
Bot(bot::StreamableBot),
|
|
|
|
Demo(demo::StreamableDemo),
|
2024-01-16 03:30:26 +00:00
|
|
|
}
|
|
|
|
|
2024-01-19 00:59:00 +00:00
|
|
|
pub fn read_snf<R:BinReaderExt>(input:R)->Result<SNF,Error>{
|
|
|
|
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 00:59:00 +00:00
|
|
|
pub fn read_map<R:BinReaderExt>(input:R)->Result<map::StreamableMap,Error>{
|
|
|
|
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 00:59:00 +00:00
|
|
|
pub fn read_bot<R:BinReaderExt>(input:R)->Result<bot::StreamableBot,Error>{
|
|
|
|
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 00:59:00 +00:00
|
|
|
pub fn read_demo<R:BinReaderExt>(input:R)->Result<demo::StreamableDemo,Error>{
|
|
|
|
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() {
|
|
|
|
}
|
|
|
|
}
|