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

Class Map

Represents the .map file with its entities stored in a list.

Attributes

Attribute Type Description Note
name str The filename of the map Automatically assigned when the map is loaded, not use when create a map from scratch
path str The path to the loaded map file Currently unused
entities list[Entity] List of entities in the map
entity_counter int Counter for assigning unique IDs to entities

Methods

__init__(self, filename=None)

Constructor method for the Map class.

Parameters:

  • filename (str, optional): The filename of the map.
# Create a map from scratch
m = Map()

add_brush(self, *args: Union[Brush, List[Brush]])

Add brushes to the worldspawn entity.

Parameters:

  • *args (Union[Brush, List[Brush]]): Variable number of brushes or list of brushes to be added.
# Add brushes individually
m.add_brush(brush1)
m.add_brush(brush2)
# Add all brushes at once
m.add_brush(brush1, brush2)
# Add a list of brushes
list_brushes = [brush1, brush2]
m.add_brush(list_brushes)

add_entity(self, *args: Union[Entity, List[Entity]])

Add entities to the map.

Parameters:

  • *args (Union[Entity, List[Entity]]): Variable number of entities or list of entities to be added.
# Add entities individually
m.add_entity(ent1)
m.add_entity(ent2)
# Add all entities at once
m.add_brush(ent1, ent2)
# Add a list of entities
list_entities = [ent1, ent2]
m.add_brush(*list_entities)

copy(self)

Return a deepcopy of the current map instance, useful for backup.

m_copy = m.copy()

get_entity_by_brush(self, target_brush: Brush)

Return the parent entity of the specified brush.

Parameters:

  • target_brush (Brush): The target brush.

Returns:

  • Union[Entity, None]: The parent entity if found, else `None.
entity = m.get_entity_by_brush(brush1)

get_entity_by_class(self, name: str)

Return a list of entities with a specified classname.

Parameters:

  • name (str): The classname value

Returns:

  • List[Entity]
m.get_entity_by_class('func_door')

__str__(self)

Return a string representation of the map.

Returns:

  • str: A string representation of the map.

__iter__(self)

Return an iterator over the Map entities.

Returns:

  • iter: An iterator over the Map entities.
# Instead of `for entity in m.entities:`
for entity in m:
   # ...

__contains__(self)

Check if an Entity or Brush instance is in Map

Returns:

  • bool: True if entity or brush is in map, False otherwise.
ent1 = Entity()
ent2 = Entity()
b = Brush()
m.add_entity(ent1)
m.add_brush(b)

if ent1 in m: # True
  # ...
if ent2 in m: # False
  # ...
if b in m: # True
  # ...

Properties

brushes

Get a list of all brushes in the map.

list_brushes = m.brushes

brush_entities

Get a list of all brush entities in the map.

list_brush_entities = m.brush_entities

faces

Get a list of all brush faces in the map.

list_faces = m.faces

point_entities

Get a list of all point entities in the map.

list_point_entities = m.point_entities

worldspawn

Get the worldspawn entity.

Returns:

  • Union[Entity, None]: The worldspawn entity if found, else `None.
world = m.worldspawn

Next: Class Entity

Clone this wiki locally