evennia.contrib.base_systems.components.holder¶
Components - ChrisLR 2022
This file contains the classes that allow a typeclass to use components.
-
class
evennia.contrib.base_systems.components.holder.
ComponentProperty
(name, **kwargs)[source]¶ Bases:
object
This allows you to register a component on a typeclass. Components registered with this property are automatically added to any instance of this typeclass.
Defaults can be overridden for this typeclass by passing kwargs
-
class
evennia.contrib.base_systems.components.holder.
ComponentHandler
(host)[source]¶ Bases:
object
This is the handler that will be added to any typeclass that inherits from ComponentHolder. It lets you add or remove components and will load components as needed. It stores the list of registered components on the host .db with component_names as key.
-
add
(component: evennia.contrib.base_systems.components.component.Component)[source]¶ Method to add a Component to a host. It caches the loaded component and appends its name to the host’s component name list. It will also call the component’s ‘at_added’ method, passing its host.
- Parameters
component (object) – The ‘loaded’ component instance to add.
-
add_default
(name)[source]¶ Method to add a Component initialized to default values on a host. It will retrieve the proper component and instantiate it with ‘default_create’. It will cache this new component and add it to its list. It will also call the component’s ‘at_added’ method, passing its host.
- Parameters
name (str) – The name of the component class to add.
-
remove
(component: evennia.contrib.base_systems.components.component.Component)[source]¶ Method to remove a component instance from a host. It removes the component from the cache and listing. It will call the component’s ‘at_removed’ method.
- Parameters
component (object) – The component instance to remove.
-
remove_by_name
(name)[source]¶ Method to remove a component instance from a host. It removes the component from the cache and listing. It will call the component’s ‘at_removed’ method.
- Parameters
name (str) – The name of the component to remove or its slot.
-
has
(name: str) → bool[source]¶ Method to check if a component is registered and ready.
- Parameters
name (str) – The name of the component or the slot.
-
initialize
()[source]¶ Method that loads and caches each component currently registered on the host. It retrieves the names from the registered listing and calls ‘load’ on each prototype class that can be found from this listing.
-
property
db_names
¶ Property shortcut to retrieve the registered component keys
- Returns
component_names (iterable) – The name of each component that is registered
-
-
class
evennia.contrib.base_systems.components.holder.
ComponentHolderMixin
[source]¶ Bases:
object
Mixin to add component support to a typeclass
Components are set on objects using the component.name as an object attribute. All registered components are initialized on the typeclass. They will be of None value if not present in the class components or runtime components.
-
basetype_setup
()[source]¶ Method that initializes the ComponentHandler, creates and registers all components that were set on the typeclass using ComponentProperty.
-
property
components
¶ Property getter to retrieve the component_handler. :returns: ComponentHandler – This Host’s ComponentHandler
-
property
cmp
¶ Shortcut Property getter to retrieve the component_handler. :returns: ComponentHandler – This Host’s ComponentHandler
-
property
signals
¶
-