forked from StrafesNET/strafe-client
read snf map
This commit is contained in:
parent
33cc2e1a45
commit
c0fe3f71cc
12
src/file.rs
12
src/file.rs
@ -4,6 +4,8 @@ use std::io::Read;
|
||||
pub enum ReadError{
|
||||
Roblox(strafesnet_rbx_loader::ReadError),
|
||||
Source(strafesnet_bsp_loader::ReadError),
|
||||
StrafesNET(strafesnet_snf::Error),
|
||||
StrafesNETMap(strafesnet_snf::map::Error),
|
||||
Io(std::io::Error),
|
||||
UnknownFileFormat,
|
||||
}
|
||||
@ -16,15 +18,20 @@ impl std::error::Error for ReadError{}
|
||||
|
||||
pub enum DataStructure{
|
||||
Roblox(strafesnet_rbx_loader::Dom),
|
||||
Source(strafesnet_bsp_loader::Bsp)
|
||||
Source(strafesnet_bsp_loader::Bsp),
|
||||
StrafesNET(strafesnet_common::map::CompleteMap),
|
||||
}
|
||||
|
||||
pub fn read<R:Read>(input:R)->Result<DataStructure,ReadError>{
|
||||
pub fn read<R:Read+std::io::Seek>(input:R)->Result<DataStructure,ReadError>{
|
||||
let mut buf=std::io::BufReader::new(input);
|
||||
let peek=std::io::BufRead::fill_buf(&mut buf).map_err(ReadError::Io)?;
|
||||
match &peek[0..4]{
|
||||
b"<rob"=>Ok(DataStructure::Roblox(strafesnet_rbx_loader::read(buf).map_err(ReadError::Roblox)?)),
|
||||
b"VBSP"=>Ok(DataStructure::Source(strafesnet_bsp_loader::read(buf).map_err(ReadError::Source)?)),
|
||||
b"SNFM"=>Ok(DataStructure::StrafesNET(
|
||||
strafesnet_snf::read_map(buf).map_err(ReadError::StrafesNET)?
|
||||
.into_complete_map().map_err(ReadError::StrafesNETMap)?
|
||||
)),
|
||||
_=>Err(ReadError::UnknownFileFormat),
|
||||
}
|
||||
}
|
||||
@ -46,6 +53,7 @@ pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<strafesnet_common::map::Co
|
||||
//blocking because it's simpler...
|
||||
let file=std::fs::File::open(path).map_err(LoadError::File)?;
|
||||
match read(file).map_err(LoadError::ReadError)?{
|
||||
DataStructure::StrafesNET(map)=>Ok(map),
|
||||
DataStructure::Roblox(dom)=>{
|
||||
let mut loader=strafesnet_deferred_loader::roblox_legacy();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user