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.
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
impl Entity
Sourcepub fn new(classname: impl Into<String>, id: u64) -> Self
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);
Sourcepub fn set(&mut self, key: String, value: String)
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.
Sourcepub fn remove_key(&mut self, key: &str) -> Option<String>
pub fn remove_key(&mut self, key: &str) -> Option<String>
Sourcepub fn swap_remove_key(&mut self, key: &str) -> Option<String>
pub fn swap_remove_key(&mut self, key: &str) -> Option<String>
Sourcepub fn targetname(&self) -> Option<&str>
pub fn targetname(&self) -> Option<&str>
Sourcepub 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,
)
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);
Sourcepub fn clear_connections(&mut self)
pub fn clear_connections(&mut self)
Removes all connections from this entity.
Trait Implementations§
Source§impl VmfSerializable for Entity
impl VmfSerializable for Entity
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more