Skip to main content

VmfSystem

Struct VmfSystem 

Source
pub struct VmfSystem {
    pub files: Vec<VmfFile>,
    pub instances: Vec<Instance>,
    pub search_dirs: Vec<PathBuf>,
    pub warnings: Vec<String>,
}
Expand description

A map and every VMF its func_instances pull in, each file loaded once

A file placed ten times is one entry in files and ten in instances: edits go to the file, world positions come from the instances

use source_vmf::prelude::*;

let map = VmfSystem::open("maps/my_map.vmf")?;
for inst in &map.instances {
    for ent in map.files[inst.file].entities.iter() {
        if ent.classname() == Some("light") {
            let [x, y, z] = inst.transform.point(Transform::from_entity(ent).origin);
            println!("light at {x} {y} {z}");
        }
    }
}

Fields§

§files: Vec<VmfFile>

files[0] is the root map. Never shrinks, so indices survive relink. Every VmfFile::path is canonical, that’s the key files get deduplicated by

§instances: Vec<Instance>

instances[0] is the root map. Parents always come before their children

§search_dirs: Vec<PathBuf>

Searched after the placing VMF’s directory and its maps directory, like gameinfo’s InstancePath

§warnings: Vec<String>

Missing, unreadable and self-including instances found by the last relink

Implementations§

Source§

impl VmfSystem

Source

pub fn open(path: impl AsRef<Path>) -> VmfResult<Self>

Opens a map and every VMF its func_instances pull in

Source

pub fn open_with( path: impl AsRef<Path>, search_dirs: Vec<PathBuf>, ) -> VmfResult<Self>

Like open, also looking for instance files in search_dirs

Rebuilds instances from the visible func_instances of the files, loading the files that are not loaded yet

Call it after removing entities (EntId is a position) or editing a func_instance’s file, origin or angles

Source

pub fn chain(&self, instance: usize) -> impl Iterator<Item = usize>

instance followed by its parents up to the root map

Source

pub fn iter_entities(&self) -> impl Iterator<Item = (usize, EntId, &Entity)>

Every entity of every file, hidden ones included like VmfFile::iter_entities. A file placed ten times is still visited once

Source

pub fn iter_entities_mut( &mut self, ) -> impl Iterator<Item = (usize, EntId, &mut Entity)>

Mutable iter_entities

Source

pub fn flatten(&self) -> Flattened

Merges the root and every placed instance into one map in world space

Brushes and entities go through Transform::apply_solid and Transform::apply_entity. func_instance and func_instance_parms are dropped and hidden objects are left out, like VBSP does. Names, $replace variables, ids and editor data are not fixed up, they stay as they are in their files

Source

pub fn save(&self) -> VmfResult<()>

Writes EVERY FILE back to the path it was loaded from

Trait Implementations§

Source§

impl Debug for VmfSystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.