forked from StrafesNET/strafe-project
rename stupidly named file enums
This commit is contained in:
parent
c5f2395b3a
commit
e1d51ff2da
@ -22,7 +22,7 @@ impl std::fmt::Display for ReadError{
|
|||||||
}
|
}
|
||||||
impl std::error::Error for ReadError{}
|
impl std::error::Error for ReadError{}
|
||||||
|
|
||||||
enum Format{
|
pub enum ReadFormat{
|
||||||
#[cfg(feature="roblox")]
|
#[cfg(feature="roblox")]
|
||||||
Roblox(strafesnet_rbx_loader::Model),
|
Roblox(strafesnet_rbx_loader::Model),
|
||||||
#[cfg(feature="source")]
|
#[cfg(feature="source")]
|
||||||
@ -33,21 +33,21 @@ enum Format{
|
|||||||
SNFB(strafesnet_snf::bot::Segment),
|
SNFB(strafesnet_snf::bot::Segment),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read<R:Read+std::io::Seek>(input:R)->Result<Format,ReadError>{
|
pub fn read<R:Read+std::io::Seek>(input:R)->Result<ReadFormat,ReadError>{
|
||||||
let mut buf=std::io::BufReader::new(input);
|
let mut buf=std::io::BufReader::new(input);
|
||||||
let peek=std::io::BufRead::fill_buf(&mut buf).map_err(ReadError::Io)?;
|
let peek=std::io::BufRead::fill_buf(&mut buf).map_err(ReadError::Io)?;
|
||||||
match &peek[0..4]{
|
match &peek[0..4]{
|
||||||
#[cfg(feature="roblox")]
|
#[cfg(feature="roblox")]
|
||||||
b"<rob"=>Ok(Format::Roblox(strafesnet_rbx_loader::read(buf).map_err(ReadError::Roblox)?)),
|
b"<rob"=>Ok(ReadFormat::Roblox(strafesnet_rbx_loader::read(buf).map_err(ReadError::Roblox)?)),
|
||||||
#[cfg(feature="source")]
|
#[cfg(feature="source")]
|
||||||
b"VBSP"=>Ok(Format::Source(strafesnet_bsp_loader::read(buf).map_err(ReadError::Source)?)),
|
b"VBSP"=>Ok(ReadFormat::Source(strafesnet_bsp_loader::read(buf).map_err(ReadError::Source)?)),
|
||||||
#[cfg(feature="snf")]
|
#[cfg(feature="snf")]
|
||||||
b"SNFM"=>Ok(Format::SNFM(
|
b"SNFM"=>Ok(ReadFormat::SNFM(
|
||||||
strafesnet_snf::read_map(buf).map_err(ReadError::StrafesNET)?
|
strafesnet_snf::read_map(buf).map_err(ReadError::StrafesNET)?
|
||||||
.into_complete_map().map_err(ReadError::StrafesNETMap)?
|
.into_complete_map().map_err(ReadError::StrafesNETMap)?
|
||||||
)),
|
)),
|
||||||
#[cfg(feature="snf")]
|
#[cfg(feature="snf")]
|
||||||
b"SNFB"=>Ok(Format::SNFB(
|
b"SNFB"=>Ok(ReadFormat::SNFB(
|
||||||
strafesnet_snf::read_bot(buf).map_err(ReadError::StrafesNET)?
|
strafesnet_snf::read_bot(buf).map_err(ReadError::StrafesNET)?
|
||||||
.read_all().map_err(ReadError::StrafesNETBot)?
|
.read_all().map_err(ReadError::StrafesNETBot)?
|
||||||
)),
|
)),
|
||||||
@ -68,23 +68,23 @@ impl std::fmt::Display for LoadError{
|
|||||||
}
|
}
|
||||||
impl std::error::Error for LoadError{}
|
impl std::error::Error for LoadError{}
|
||||||
|
|
||||||
pub enum Format2{
|
pub enum LoadFormat{
|
||||||
#[cfg(feature="snf")]
|
#[cfg(feature="snf")]
|
||||||
Map(strafesnet_common::map::CompleteMap),
|
Map(strafesnet_common::map::CompleteMap),
|
||||||
#[cfg(feature="snf")]
|
#[cfg(feature="snf")]
|
||||||
Bot(strafesnet_snf::bot::Segment),
|
Bot(strafesnet_snf::bot::Segment),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<Format2,LoadError>{
|
pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<LoadFormat,LoadError>{
|
||||||
//blocking because it's simpler...
|
//blocking because it's simpler...
|
||||||
let file=std::fs::File::open(path).map_err(LoadError::File)?;
|
let file=std::fs::File::open(path).map_err(LoadError::File)?;
|
||||||
match read(file).map_err(LoadError::ReadError)?{
|
match read(file).map_err(LoadError::ReadError)?{
|
||||||
#[cfg(feature="snf")]
|
#[cfg(feature="snf")]
|
||||||
Format::SNFB(bot)=>Ok(Format2::Bot(bot)),
|
ReadFormat::SNFB(bot)=>Ok(LoadFormat::Bot(bot)),
|
||||||
#[cfg(feature="snf")]
|
#[cfg(feature="snf")]
|
||||||
Format::SNFM(map)=>Ok(Format2::Map(map)),
|
ReadFormat::SNFM(map)=>Ok(LoadFormat::Map(map)),
|
||||||
#[cfg(feature="roblox")]
|
#[cfg(feature="roblox")]
|
||||||
Format::Roblox(model)=>{
|
ReadFormat::Roblox(model)=>{
|
||||||
let mut place=model.into_place();
|
let mut place=model.into_place();
|
||||||
place.run_scripts();
|
place.run_scripts();
|
||||||
|
|
||||||
@ -117,10 +117,10 @@ pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<Format2,LoadError>{
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(Format2::Map(map))
|
Ok(LoadFormat::Map(map))
|
||||||
},
|
},
|
||||||
#[cfg(feature="source")]
|
#[cfg(feature="source")]
|
||||||
Format::Source(bsp)=>{
|
ReadFormat::Source(bsp)=>{
|
||||||
let mut loader=strafesnet_deferred_loader::source_legacy();
|
let mut loader=strafesnet_deferred_loader::source_legacy();
|
||||||
|
|
||||||
let (texture_loader,mesh_loader)=loader.get_inner_mut();
|
let (texture_loader,mesh_loader)=loader.get_inner_mut();
|
||||||
@ -156,7 +156,7 @@ pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<Format2,LoadError>{
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(Format2::Map(map))
|
Ok(LoadFormat::Map(map))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use strafesnet_common::instruction::TimedInstruction;
|
use strafesnet_common::instruction::TimedInstruction;
|
||||||
use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner};
|
use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner};
|
||||||
use strafesnet_common::physics::{MiscInstruction,SetControlInstruction};
|
use strafesnet_common::physics::{MiscInstruction,SetControlInstruction};
|
||||||
use crate::file::Format2;
|
use crate::file::LoadFormat;
|
||||||
use crate::physics_worker::Instruction as PhysicsWorkerInstruction;
|
use crate::physics_worker::Instruction as PhysicsWorkerInstruction;
|
||||||
use crate::session::{SessionInputInstruction,SessionControlInstruction,SessionPlaybackInstruction};
|
use crate::session::{SessionInputInstruction,SessionControlInstruction,SessionPlaybackInstruction};
|
||||||
|
|
||||||
@ -30,8 +30,8 @@ impl WindowContext<'_>{
|
|||||||
match event{
|
match event{
|
||||||
winit::event::WindowEvent::DroppedFile(path)=>{
|
winit::event::WindowEvent::DroppedFile(path)=>{
|
||||||
match crate::file::load(path.as_path()){
|
match crate::file::load(path.as_path()){
|
||||||
Ok(Format2::Map(map))=>self.physics_thread.send(TimedInstruction{time,instruction:PhysicsWorkerInstruction::ChangeMap(map)}).unwrap(),
|
Ok(LoadFormat::Map(map))=>self.physics_thread.send(TimedInstruction{time,instruction:PhysicsWorkerInstruction::ChangeMap(map)}).unwrap(),
|
||||||
Ok(Format2::Bot(bot))=>self.physics_thread.send(TimedInstruction{time,instruction:PhysicsWorkerInstruction::LoadReplay(bot)}).unwrap(),
|
Ok(LoadFormat::Bot(bot))=>self.physics_thread.send(TimedInstruction{time,instruction:PhysicsWorkerInstruction::LoadReplay(bot)}).unwrap(),
|
||||||
Err(e)=>println!("Failed to load file: {e}"),
|
Err(e)=>println!("Failed to load file: {e}"),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user