pyecs.containers#

class pyecs.containers.Archetype[source]#
__init__()[source]#
add_entity(entity, components)[source]#

Add an entity and its components to this archetype.

This method stores the entity and its components in parallel arrays, maintaining alignment between entity indices and component indices.

Returns SUCCESS if the entity was added, or FAILURE if the entity already exists in this archetype.

Return type:

TypeAliasType

Parameters:
  • entity (Entity)

  • components (list[Component])

get_component(entity, component_type)[source]#

Retrieve a specific component for an entity.

This method uses the parallel array structure to efficiently locate the requested component by finding the entity’s index.

Returns the component instance if found, or FAILURE if the entity doesn’t exist or doesn’t have the specified component type.

Return type:

Union[TypeAliasType, Literal[<StatusCodes.FAILURE: -1>]]

Parameters:
  • entity (Entity)

  • component_type (type[Component])

iter_components(component_type)[source]#

Iterate over all components of a specific type.

This method yields all component instances of the requested type stored in this archetype, in the same order as their entities.

Yields component instances if the archetype contains the specified component type, otherwise yields nothing.

Return type:

Iterator[TypeAliasType]

Parameters:

component_type (type)

iter_entities()[source]#

Iterate over all entities in this archetype.

This method provides direct iteration over the entities list, useful for systems that need to process all entities with a specific component combination.

Returns an iterator over all entity UUIDs in this archetype.

Return type:

Iterator[TypeAliasType]

remove_entity(entity)[source]#

Remove an entity and all its component data from this archetype.

This method maintains the parallel array structure by removing the entity and its components from the same index across all arrays.

Returns SUCCESS if the entity was removed, or FAILURE if the entity does not exist in this archetype.

Return type:

TypeAliasType

Parameters:

entity (Entity)

class pyecs.containers.ComponentStorage[source]#
__init__()[source]#
add_component(entity, component)[source]#

Add or update a component for an entity.

If the component type doesn’t exist on the entity, adds it and transitions the entity to a new archetype. If the component type already exists, updates the existing component in place.

Returns COMPONENT_ADDED for new components, COMPONENT_UPDATED for existing components, or FAILURE if the entity doesn’t exist.

Return type:

Literal[<StatusCodes.COMPONENT_ADDED: 200>, <StatusCodes.COMPONENT_UPDATED: 202>, <StatusCodes.FAILURE: -1>]

Parameters:
  • entity (Entity)

  • component (Component)

get_component(entity, component_type)[source]#

Retrieve a specific component from an entity.

Returns the component instance if found, or FAILURE if the entity doesn’t exist or doesn’t have the specified component type.

Return type:

Union[TypeAliasType, Literal[<StatusCodes.FAILURE: -1>]]

Parameters:
  • entity (Entity)

  • component_type (type[T])

get_entity_components(entity)[source]#

Retrieve all components for an entity.

Returns a list containing all component instances attached to the entity, in the order they appear in the archetype mask.

Return type:

list[TypeAliasType]

Parameters:

entity (Entity)

has_component(entity, component_type)[source]#

Check if an entity has a specific component type.

Returns True if the entity exists and has the component type, False otherwise.

Return type:

bool

Parameters:
  • entity (Entity)

  • component_type (type[T])

move_entity_to_archetype(entity, new_mask, components=None)[source]#

Move an entity to a different archetype.

Handles the transition of an entity between archetypes when components are added or removed. Creates the target archetype if it doesn’t exist.

Returns SUCCESS after moving the entity to the new archetype.

Return type:

TypeAliasType

Parameters:
remove_component(entity, component_type)[source]#

Remove a component type from an entity.

Transitions the entity to a new archetype without the specified component. If this was the last component, removes the entity entirely.

Returns COMPONENT_REMOVED on success, or FAILURE if the entity doesn’t exist or doesn’t have the specified component type.

Return type:

Literal[<StatusCodes.COMPONENT_REMOVED: 201>, <StatusCodes.FAILURE: -1>]

Parameters:
  • entity (Entity)

  • component_type (type[T])

remove_entity(entity)[source]#

Remove an entity and all its components from storage.

Removes the entity from its current archetype and clears all component data associated with it.

Returns SUCCESS on removal, or FAILURE if the entity doesn’t exist.

Return type:

TypeAliasType

Parameters:

entity (Entity)

Modules