pub struct Entity {
pub key_values: IndexMap<String, String>,
pub connections: Option<Vec<Connection>>,
pub solids: Option<Vec<Solid>>,
pub editor: Editor,
pub is_hidden: bool,
pub extra: Extras,
}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<Connection>>The output connections of this entity.
solids: Option<Vec<Solid>>The solids associated with this entity, if any.
editor: EditorThe 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.
extra: ExtrasBlocks this struct does not model. Unknown keys land in key_values.
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 source_vmf::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 Into<String>,
input: impl Into<String>,
parms: impl Into<String>,
delay: f32,
fire_limit: i32,
)
pub fn add_connection( &mut self, output: impl Into<String>, target_entity: impl Into<String>, input: impl Into<String>, parms: impl Into<String>, 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 source_vmf::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 FromBlock for Entity
impl FromBlock for Entity
Source§fn from_block(block: VmfBlock, ctx: &mut ParseCtx) -> Self
fn from_block(block: VmfBlock, ctx: &mut ParseCtx) -> Self
Parses
block, substituting defaults and logging warnings for missing or invalid values.impl StructuralPartialEq for Entity
Source§impl VmfSerializable for Entity
impl VmfSerializable 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 UnsafeUnpin 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