debug info
This commit is contained in:
@@ -214,18 +214,81 @@ pub struct Model{
|
||||
pub attributes:gameplay_attributes::CollisionAttributesId,
|
||||
pub color:Color4,//transparency is in here
|
||||
pub transform:Planar64Affine3,
|
||||
pub brush_info:BrushInfo,
|
||||
pub debug_info:DebugInfo,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone)]
|
||||
pub enum DebugInfo{
|
||||
World,
|
||||
Prop,
|
||||
Brush(BrushInfo),
|
||||
Entity(EntityInfo),
|
||||
}
|
||||
impl std::fmt::Display for DebugInfo{
|
||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||
match self{
|
||||
DebugInfo::World=>write!(f,"World"),
|
||||
DebugInfo::Prop=>write!(f,"Prop"),
|
||||
DebugInfo::Brush(brush_info)=>brush_info.fmt(f),
|
||||
DebugInfo::Entity(entity_info)=>entity_info.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone)]
|
||||
pub struct BrushInfo{
|
||||
pub flags:vbsp::BrushFlags,
|
||||
pub sides:Vec<vbsp::TextureFlags>,
|
||||
}
|
||||
impl BrushInfo{
|
||||
pub const BUH:Self=BrushInfo{
|
||||
flags:vbsp::BrushFlags::empty(),
|
||||
sides:vec![],
|
||||
};
|
||||
impl std::fmt::Display for BrushInfo{
|
||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||
let noice=self.flags.iter_names().filter_map(|(name,flags)|{
|
||||
(flags.bits()!=0).then(||name)
|
||||
}).collect::<Vec<&str>>().join("|");
|
||||
writeln!(f,"brush_info.flags={noice}")?;
|
||||
for (i,side) in self.sides.iter().enumerate(){
|
||||
let noice_string=side.iter_names().filter_map(|(name,flags)|{
|
||||
(flags.bits()!=0).then(||name)
|
||||
}).collect::<Vec<&str>>().join("|");
|
||||
writeln!(f,"brush_info.sides[{i}]={noice_string}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone)]
|
||||
pub struct EntityInfo{
|
||||
pub classname:Box<str>,
|
||||
pub properties:Vec<(Box<str>,Box<str>)>,
|
||||
}
|
||||
pub enum EntityInfoError{
|
||||
MissingClassname,
|
||||
}
|
||||
impl EntityInfo{
|
||||
pub fn new<'a>(iter:impl IntoIterator<Item=(&'a str,&'a str)>)->Result<Self,EntityInfoError>{
|
||||
let mut classname:Option<Box<str>>=None;
|
||||
let mut properties:Vec<(Box<str>,Box<str>)>=Vec::new();
|
||||
for (name,value) in iter{
|
||||
match name{
|
||||
"classname"=>classname=Some(value.into()),
|
||||
"hammerid"=>(),
|
||||
_=>properties.push((name.into(),value.into())),
|
||||
}
|
||||
}
|
||||
properties.sort_by(|(n0,_),(n1,_)|n0.cmp(n1));
|
||||
let Some(classname)=classname else{
|
||||
return Err(EntityInfoError::MissingClassname);
|
||||
};
|
||||
Ok(EntityInfo{classname,properties})
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for EntityInfo{
|
||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||
writeln!(f,"struct {}{{",self.classname)?;
|
||||
for (name,value) in &self.properties{
|
||||
writeln!(f,"\t{name}:{value},")?;
|
||||
}
|
||||
write!(f,"}}")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user