pub struct VmfFile {
pub path: Option<String>,
pub versioninfo: VersionInfo,
pub visgroups: VisGroups,
pub viewsettings: ViewSettings,
pub world: World,
pub entities: Entities,
pub hiddens: Entities,
pub cameras: Cameras,
pub cordons: Cordons,
pub extra_blocks: Vec<VmfBlock>,
pub warnings: Vec<String>,
pub suppressed_warnings: usize,
}Expand description
Represents a parsed VMF file.
Fields§
§path: Option<String>The path to the VMF file, if known.
versioninfo: VersionInfoThe version info of the VMF file.
visgroups: VisGroupsThe visgroups in the VMF file.
viewsettings: ViewSettingsThe view settings in the VMF file.
world: WorldThe world data in the VMF file.
entities: EntitiesThe entities in the VMF file.
The hidden entities in the VMF file.
cameras: CamerasThe camera data in the VMF file.
cordons: CordonsThe cordon data in the VMF file.
extra_blocks: Vec<VmfBlock>Top-level blocks this struct does not model, kept so they survive a parse/serialize round-trip.
warnings: Vec<String>Non-fatal warnings encountered during parsing (e.g. fallback defaults, unknown blocks).
suppressed_warnings: usizeNumber of warnings suppressed after exceeding the warning limit.
Implementations§
Source§impl VmfFile
impl VmfFile
Sourcepub fn to_vmf_string(&self) -> String
pub fn to_vmf_string(&self) -> String
Converts the VmfFile to a string in VMF format.
Sourcepub fn parse(content: &str) -> VmfResult<Self>
pub fn parse(content: &str) -> VmfResult<Self>
Parses a VMF file from a string.
§Examples
use source_vmf::VmfFile;
let vmf_content = r#"
versioninfo
{
"editorversion" "400"
"editorbuild" "8000"
"mapversion" "1"
"formatversion" "100"
"prefab" "0"
}
"#;
let vmf_file = VmfFile::parse(vmf_content);
assert!(vmf_file.is_ok());Sourcepub fn open(path: impl AsRef<Path>) -> VmfResult<Self>
pub fn open(path: impl AsRef<Path>) -> VmfResult<Self>
Opens and parses a VMF file from a file path.
§Examples
use source_vmf::VmfFile;
let vmf_file = VmfFile::open("your_map.vmf");
assert!(vmf_file.is_ok());Sourcepub fn save(&self, path: impl AsRef<Path>) -> VmfResult<()>
pub fn save(&self, path: impl AsRef<Path>) -> VmfResult<()>
Saves the VmfFile to a file at the specified path.
Writes to a temporary .part file first and renames it into place.
§Examples
use source_vmf::VmfFile;
let vmf_file = VmfFile::open("your_map.vmf").unwrap();
let result = vmf_file.save("new_map.vmf");
assert!(result.is_ok());Sourcepub fn merge(&mut self, other: Self)
pub fn merge(&mut self, other: Self)
Merges the contents of another VmfFile into this one.
Combines visgroups, world solids (visible and hidden), entities, hiddens,
and cordons. versioninfo, viewsettings, and cameras are retained from self.
§Examples
use source_vmf::prelude::*;
let mut vmf1 = VmfFile::open("map1.vmf").unwrap();
let vmf2 = VmfFile::open("map2.vmf").unwrap();
vmf1.merge(vmf2);Sourcepub fn get_entities_in_visgroup(
&self,
group_id: i32,
include_children: bool,
) -> Option<impl Iterator<Item = &Entity> + '_>
pub fn get_entities_in_visgroup( &self, group_id: i32, include_children: bool, ) -> Option<impl Iterator<Item = &Entity> + '_>
Returns an iterator over entities (including hidden ones) belonging to the specified VisGroup ID.
Sourcepub fn get_entities_in_visgroup_mut(
&mut self,
group_id: i32,
include_children: bool,
) -> Option<impl Iterator<Item = &mut Entity> + '_>
pub fn get_entities_in_visgroup_mut( &mut self, group_id: i32, include_children: bool, ) -> Option<impl Iterator<Item = &mut Entity> + '_>
Returns a mutable iterator over entities (including hidden ones) belonging to the specified VisGroup ID.
Source§impl VmfFile
impl VmfFile
Sourcepub fn entity(&self, id: EntId) -> Option<&Entity>
pub fn entity(&self, id: EntId) -> Option<&Entity>
Returns a reference to the entity at id, or None if the index is out of bounds.
Sourcepub fn entity_mut(&mut self, id: EntId) -> Option<&mut Entity>
pub fn entity_mut(&mut self, id: EntId) -> Option<&mut Entity>
Returns a mutable reference to the entity at id, or None if the index is out of bounds.
Sourcepub fn iter_entities(&self) -> impl Iterator<Item = (EntId, &Entity)>
pub fn iter_entities(&self) -> impl Iterator<Item = (EntId, &Entity)>
Iterates over all entities in the file, including hidden ones.
Sourcepub fn iter_entities_mut(
&mut self,
) -> impl Iterator<Item = (EntId, &mut Entity)>
pub fn iter_entities_mut( &mut self, ) -> impl Iterator<Item = (EntId, &mut Entity)>
Mutably iterates over all entities in the file, including hidden ones.