-
Notifications
You must be signed in to change notification settings - Fork 0
Entity
Represents an entity in a .map file with properties and associated brushes.
Attribute | Type | Description |
---|---|---|
properties |
dict |
Dictionary of entity properties |
brushes |
list[Brush] |
List of brushes associated with the entity |
_id |
int |
Unique identifier for the entity |
brush_counter |
int |
Counter for assigning unique IDs to brushes |
__init__
(self, classname: Union[str, None]=None, origin_or_brushes: Union[Point, List[float], Brush, List[Brush], None]=None, properties: Union[dict, None]=None)
Constructor method for the
Entity
class.
Parameters:
classname
(str): The entity classnameorigin_or_brush
(Point, List[float], Brush, List[Brush]): Origin if is a point entity or brush(es) if is a brush entityproperties
(dict): Entity key-values properties
# Create an Entity from scratch without params
e1 = Entity()
# Brush entity with params
e2 = Entity('func_door', brush, {"speed":"50"})
# Point entity with params
e3 = Entity('light_spot', [64, 0, 128], {"_light":"255 255 255 200"})
Add brush(es) to the entity.
Parameters:
*args
(Union[Brush, List[Brush]]): Variable number of brushes or list of brushes to be added.
# Add brushes individually
e.add_brush(brush1)
e.add_brush(brush2)
# Add all brushes at once
e.add_brush(brush1, brush2)
Moves the entity by specified offsets.
Parameters:
x
(float): Offset in the x-axis.y
(float): Offset in the y-axis.z
(float): Offset in the z-axis.
# before: 10 10 10
e.move_by(10,20,30)
# after: 20 30 40
Move the entity to a specific coordinate.
Parameters:
x
(float): Target x-coordinate.y
(float): Target y-coordinate.z
(float): Target z-coordinate.centroid
(bool, optional): Whether to use the centroid of brushes (default: True).bbox
(bool, optional): Whether to use the bounding box of brushes (default: False).
# before: 10 10 10
e.move_to(10,20,30)
# after: 10 20 30
Return a string representation of the entity.
Returns:
str
: String representation of the entity.
Return an iterator over the entity's brushes.
Returns:
iter
: Iterator over the entity's brushes.
for brush in e:
# ...
Set an item in the entity's property dictionary.
Parameters:
key
(str): Property key.value
(str): Property value.
# e.['key'] = 'value'
e.['zhlt_noclip'] = '1'
Get the value of a key property.
Parameters:
key
(str): Property key.
Returns:
str
: Property value.
# e.['key']
clip_value = e.['zhlt_clip']
Check if a key is present in the entity's property dictionary.
Parameters:
key
(str): Property key.
Returns:
bool
: True if the key is present, False otherwise.
if 'zhlt_clip' in e:
# ...
Compare the entity with another Entity object (or string for checking classname).
Parameters:
other
: Entity object or string to compare.
Returns:
bool
: True if equal, False otherwise.
if e == e2:
# ...
if e == "func_detail":
# ...
Get the classname value of the entity.
Returns:
str
: Classname value.
entity_class = e.classname
Get the origin of the entity.
Returns:
Union[Point, None]
: Origin of the entity as a Point object.
entity_origin = e.origin
Check if the entity is a point entity.
Returns:
bool
: True if the entity is a point entity, False otherwise.
if e.is_point_entity:
# ...
Check if the entity is a brush entity.
Returns:
bool
: True if the entity is a brush entity, False otherwise.
if e.is_brush_entity:
# ...
Get a list of faces associated with the entity.
Returns:
List[Face]
: List of faces associated with the entity.
brush_entity_faces = e.faces
Get a list of vertices associated with the entity.
Returns:
List[Point]
: List of vertices associated with the entity.
brush_entity_vertices = e.vertices