evennia.contrib.base_systems.components.dbfield

Components - ChrisLR 2022

This file contains the Descriptors used to set Fields in Components

class evennia.contrib.base_systems.components.dbfield.DBField(default=None, autocreate=False, **kwargs)[source]

Bases: evennia.typeclasses.attributes.AttributeProperty

Component Attribute Descriptor. Allows you to set attributes related to a component on the class. It uses AttributeProperty under the hood but prefixes the key with the component name.

__init__(default=None, autocreate=False, **kwargs)[source]

Allows for specifying Attributes as Django-like ‘fields’ on the class level. Note that while one can set a lock on the Attribute, there is no way to check said lock when accessing via the property - use the full AttributeHandler if you need to do access checks. Note however that if you use the full AttributeHandler to access this Attribute, the at_get/at_set methods on this class will _not_ fire (because you are bypassing the AttributeProperty entirely in that case).

Initialize an Attribute as a property descriptor.

Keyword Arguments
  • default (any) – A default value if the attr is not set. If a callable, this will be run without any arguments and is expected to return the default value.

  • category (str) – The attribute’s category. If unset, use class default.

  • strattr (bool) – If set, this Attribute must be a simple string, and will be stored more efficiently.

  • lockstring (str) – This is not itself useful with the property, but only if using the full AttributeHandler.get(accessing_obj=…) to access the Attribute.

  • autocreate (bool) – True by default; this means Evennia makes sure to create a new copy of the Attribute (with the default value) whenever a new object with this property is created. If False, no Attribute will be created until the property is explicitly assigned a value. This makes it more efficient while it retains its default (there’s no db access), but without an actual Attribute generated, one cannot access it via .db, the AttributeHandler or see it with examine.

Example:

class Character(DefaultCharacter):
    foo = AttributeProperty(default="Bar")
at_added(component)[source]

Called when the parent component is added to a host.

Parameters

component (Component) – The component instance being added.

at_removed(component)[source]

Called when the parent component is removed from a host.

Parameters

component (Component) – The component instance being removed.

class evennia.contrib.base_systems.components.dbfield.NDBField(default=None, category=None, strattr=False, lockstring='', autocreate=True)[source]

Bases: evennia.typeclasses.attributes.NAttributeProperty

Component In-Memory Attribute Descriptor. Allows you to set in-memory attributes related to a component on the class. It uses NAttributeProperty under the hood but prefixes the key with the component name.

at_added(component)[source]

Called when the parent component is added to a host.

Parameters

component (Component) – The component instance being added.

at_removed(component)[source]

Called when the parent component is removed from a host.

Parameters

component (Component) – The component instance being removed.

class evennia.contrib.base_systems.components.dbfield.TagField(default=None, enforce_single=False)[source]

Bases: object

Component Tags Descriptor. Allows you to set Tags related to a component on the class. The tags are set with a prefixed category, so it can support multiple tags or enforce a single one.

Default value of a tag is added when the component is registered. Tags are removed if the component itself is removed.

__init__(default=None, enforce_single=False)[source]

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

at_added(component)[source]

Called when the parent component is added to a host.

Parameters

component (Component) – The component instance being added.

at_removed(component)[source]

Called when the parent component is removed from a host.

Parameters

component (Component) – The component instance being removed.