# 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`(component_name, **kwargs)

  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

  `__init__`(component_name, **kwargs)

    Initializes the descriptor

    Parameters

      - component_name (str) – The name of the component

      - **kwargs (any) – Key=Values overriding default values of the component

class `evennia.contrib.base_systems.components.holder.``ComponentHandler`(host)

  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.

  `__init__`(host)

    Initialize self. See help(type(self)) for accurate signature.

  `add`(component)

    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)

    Method to add a Component initialized to default values on a host. It will retrieve the proper component and instanciate 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)

    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)

    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.

  `get`(name)

    Method to retrieve a cached Component instance by its name.

    Parameters

      name (str) – The name of the component to retrieve.

  `has`(name)

    Method to check if a component is registered and ready.

    Parameters

      name (str) – The name of the component.

  `initialize`()

    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 names

    Returns

      component_names (iterable) – The name of each component that is registered

class `evennia.contrib.base_systems.components.holder.``ComponentHolderMixin`

  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.

  `at_init`()

    Method that initializes the ComponentHandler.

  `at_post_puppet`(*args, **kwargs)
  `at_post_unpuppet`(*args, **kwargs)
  `basetype_setup`()

    Method that initializes the ComponentHandler, creates and registers all components that were set on the typeclass using ComponentProperty.

  `basetype_posthook_setup`()

    Method that add component related tags that were set 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`

exception `evennia.contrib.base_systems.components.holder.``ComponentDoesNotExist`

  Bases: `Exception`

exception `evennia.contrib.base_systems.components.holder.``ComponentIsNotRegistered`

  Bases: `Exception`