Struct Entity

Source
pub struct Entity {
    pub key_values: IndexMap<String, String>,
    pub connections: Option<Vec<(String, String)>>,
    pub solids: Option<Vec<Solid>>,
    pub editor: Editor,
    pub is_hidden: bool,
}
Expand description

Represents an entity in a VMF file.

Fields§

§key_values: IndexMap<String, String>

The key-value pairs associated with this entity.

§connections: Option<Vec<(String, String)>>

The output connections of this entity.

§solids: Option<Vec<Solid>>

The solids associated with this entity, if any.

§editor: Editor

The editor data for this entity.

§is_hidden: bool

Indicates if the entity is hidden within the editor. This field is primarily used when parsing a hidden block within a VMF file, and is not serialized back when writing the VMF.

Implementations§

Source§

impl Entity

Source

pub fn new(classname: impl Into<String>, id: u64) -> Self

Creates a new Entity with the specified classname and ID.

§Arguments
  • classname - The classname of the entity (e.g., “func_detail”, “info_player_start”).
  • id - The unique ID of the entity.
§Example
use vmf_forge::prelude::*;

let entity = Entity::new("info_player_start", 1);
assert_eq!(entity.classname(), Some("info_player_start"));
assert_eq!(entity.id(), 1);
Source

pub fn set(&mut self, key: String, value: String)

Sets a key-value pair for the entity. If the key already exists, its value is updated.

§Arguments
  • key - The key to set.
  • value - The value to set for the key.
Source

pub fn remove_key(&mut self, key: &str) -> Option<String>

Removes a key-value pair from the entity, preserving the order of other keys.

§Arguments
  • key - The key to remove.
§Returns

An Option containing the removed value, if the key was present.

Source

pub fn swap_remove_key(&mut self, key: &str) -> Option<String>

Removes a key-value pair from the entity, potentially changing the order of other keys. This is faster than remove_key but does not preserve insertion order.

§Arguments
  • key - The key to remove.
§Returns

An Option containing the removed value, if the key was present.

Source

pub fn get(&self, key: &str) -> Option<&String>

Gets the value associated with the given key.

§Arguments
  • key - The key to get the value for.
§Returns

An Option containing a reference to the value, if the key is present.

Source

pub fn get_mut(&mut self, key: &str) -> Option<&mut String>

Gets a mutable reference to the value associated with the given key.

§Arguments
  • key - The key to get the value for.
§Returns

An Option containing a mutable reference to the value, if the key is present.

Source

pub fn classname(&self) -> Option<&str>

Returns the classname of the entity.

§Returns

An Option containing the classname, if it exists.

Source

pub fn targetname(&self) -> Option<&str>

Returns the targetname of the entity.

§Returns

An Option containing the targetname, if it exists.

Source

pub fn id(&self) -> u64

Returns the ID of the entity.

Source

pub fn model(&self) -> Option<&str>

Returns the model of the entity.

§Returns

An Option containing the model path, if it exists.

Source

pub fn add_connection( &mut self, output: impl Into<String>, target_entity: impl AsRef<str>, input: impl AsRef<str>, parms: impl AsRef<str>, delay: f32, fire_limit: i32, )

Adds an output connection to the entity.

§Arguments
  • output - The name of the output on this entity.
  • target_entity - The targetname of the entity to connect to.
  • input - The name of the input on the target entity.
  • parms - The parameters to pass to the input.
  • delay - The delay before the input is triggered, in seconds.
  • fire_limit - The number of times the output can be fired (-1 for unlimited).
§Example
use vmf_forge::prelude::*;

let mut entity = Entity::new("logic_relay", 1);
entity.add_connection("OnTrigger", "my_door", "Open", "", 0.0, -1);
Source

pub fn clear_connections(&mut self)

Removes all connections from this entity.

Source

pub fn has_connection(&self, output: &str, input: &str) -> bool

Checks if a specific connection exists.

§Arguments
  • output The output to check
  • input The input to check
§Returns
  • true if the connection exists, false otherwise.

Trait Implementations§

Source§

impl Clone for Entity

Source§

fn clone(&self) -> Entity

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Entity

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Entity

Source§

fn default() -> Entity

Returns the “default value” for a type. Read more
Source§

impl From<Entity> for VmfBlock

Source§

fn from(val: Entity) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Entity

Source§

fn eq(&self, other: &Entity) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<VmfBlock> for Entity

Source§

type Error = VmfError

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

fn try_from(block: VmfBlock) -> VmfResult<Self>

Performs the conversion.
Source§

impl VmfSerializable for Entity

Source§

fn to_vmf_string(&self, indent_level: usize) -> String

Serializes the object into a VMF string. Read more
Source§

impl StructuralPartialEq for Entity

Auto Trait Implementations§

§

impl Freeze for Entity

§

impl RefUnwindSafe for Entity

§

impl Send for Entity

§

impl Sync for Entity

§

impl Unpin for Entity

§

impl UnwindSafe for Entity

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.