evennia.contrib.base_systems.components.component¶
Components - ChrisLR 2022
This file contains the base class to inherit for creating new components.
- class evennia.contrib.base_systems.components.component.BaseComponent(name, parents, attrs)[source]¶
Bases:
typeThis is the metaclass for components, responsible for registering components to the listing.
- class evennia.contrib.base_systems.components.component.Component(host=None)[source]¶
Bases:
objectThis is the base class for components. Any component must inherit from this class to be considered for usage.
Each Component must supply the name, it is used as a slot name but also part of the attribute key.
- name = ''¶
- slot = None¶
- host¶
- classmethod default_create(host)[source]¶
- This is called when the host is created
and should return the base initialized state of a component.
- Parameters:
host (object) – The host typeclass instance
- Returns:
Component – The created instance of the component
- classmethod create(host, **kwargs)[source]¶
This is the method to call when supplying kwargs to initialize a component.
- Parameters:
host (object) – The host typeclass instance
**kwargs – Key-Value of default values to replace. To persist the value, the key must correspond to a DBField.
- Returns:
Component – The created instance of the component
- classmethod load(host)[source]¶
- Loads a component instance
This is called whenever a component is loaded (ex: Server Restart)
- Parameters:
host (object) – The host typeclass instance
- Returns:
Component – The loaded instance of the component
- at_added(host)[source]¶
This is the method called when a component is registered on a host.
- Parameters:
host (object) – The host typeclass instance
- at_removed(host)[source]¶
This is the method called when a component is removed from a host.
- Parameters:
host (object) – The host typeclass instance
- property attributes¶
Shortcut property returning the host’s AttributeHandler.
- Returns:
AttributeHandler – The Host’s AttributeHandler
- property pk¶
Shortcut property returning the host’s primary key.
- Returns:
int – The Host’s primary key.
Notes
This is requried to allow AttributeProperties to correctly update _SaverMutable data (like lists) in-place (since the DBField sits on the Component which doesn’t itself have a primary key, this save operation would otherwise fail).
- property nattributes¶
Shortcut property returning the host’s In-Memory AttributeHandler (Non Persisted).
- Returns:
AttributeHandler – The Host’s In-Memory AttributeHandler