Skip to content
Gaspar edited this page Jan 20, 2024 · 16 revisions

Class Entity

Represents an entity in a .map file with properties and associated brushes.

Attributes

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

Methods

__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 classname
  • origin_or_brush (Point, List[float], Brush, List[Brush]): Origin if is a point entity or brush(es) if is a brush entity
  • properties(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(self, *args: Union[Brush, List[Brush]])

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)

move_by(self, x: float, y: float, z: float)

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_to(self, x: float, y: float, z: float, centroid: bool=True, bbox: bool=False)

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

__repr__(self)

Return a string representation of the entity.

Returns:

  • str: String representation of the entity.

__iter__(self)

Return an iterator over the entity's brushes.

Returns:

  • iter: Iterator over the entity's brushes.
for brush in e:
  # ...

__setitem__(self, key: str, value: str)

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'

__getitem__(self, key: str)

Get the value of a key property.

Parameters:

  • key (str): Property key.

Returns:

  • str: Property value.
# e.['key']
clip_value = e.['zhlt_clip']

__contains__(self, key: str)

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:
   # ...

__eq__(self, other)

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":
  # ...

Properties


classname(self)

Get the classname value of the entity.

Returns:

  • str: Classname value.
entity_class = e.classname

origin(self)

Get the origin of the entity.

Returns:

  • Union[Point, None]: Origin of the entity as a Point object.
entity_origin = e.origin

is_point_entity(self)

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:
   # ...

is_brush_entity(self)

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:
   # ...

faces(self)

Get a list of faces associated with the entity.

Returns:

  • List[Face]: List of faces associated with the entity.
brush_entity_faces = e.faces

vertices(self)

Get a list of vertices associated with the entity.

Returns:

  • List[Point]: List of vertices associated with the entity.
brush_entity_vertices = e.vertices

Next: Class Brush