Add docstrings

This commit is contained in:
ChrisLR 2024-01-14 12:58:26 -05:00
parent 37e70cc7fa
commit 6ad6522fa4
3 changed files with 59 additions and 7 deletions

View file

@ -9,8 +9,17 @@ from evennia.contrib.base_systems.components import COMPONENT_LISTING, exception
class BaseComponent(type):
"""
This is the metaclass for components,
responsible for registering components to the listing.
"""
@classmethod
def __new__(cls, *args):
"""
Every class that uses this metaclass will be registered
as a component in the Component Listing using its name.
All of them require a unique name.
"""
new_type = super().__new__(*args)
if new_type.__base__ == object:
return new_type

View file

@ -26,17 +26,31 @@ class DBField(AttributeProperty):
Called when descriptor is first assigned to the class.
Args:
owner (object): The component classF on which this is set
owner (Component): The component classF on which this is set
name (str): The name that was used to set the DBField.
"""
self._key = f"{owner.slot or owner.name}::{name}"
owner.add_field(name, self)
def at_added(self, component):
"""
Called when the parent component is added to a host.
Args:
component (Component): The component instance being added.
"""
if self._autocreate:
self.__get__(component, type(component))
def at_removed(self, component):
"""
Called when the parent component is removed from a host.
Args:
component (Component): The component instance being removed.
"""
self.__delete__(component)
@ -52,18 +66,30 @@ class NDBField(NAttributeProperty):
Called when descriptor is first assigned to the class.
Args:
owner (object): The component class on which this is set
owner (Component): The component class on which this is set
name (str): The name that was used to set the DBField.
"""
self._key = f"{owner.slot or owner.name}::{name}"
owner.add_field(name, self)
def at_added(self, instance):
if self._autocreate:
self.__set__(instance, self._default)
def at_added(self, component):
"""
Called when the parent component is added to a host.
def at_removed(self, instance):
self.__delete__(instance)
Args:
component (Component): The component instance being added.
"""
if self._autocreate:
self.__set__(component, self._default)
def at_removed(self, component):
"""
Called when the parent component is removed from a host.
Args:
component (Component): The component instance being removed.
"""
self.__delete__(component)
class TagField:
@ -124,8 +150,20 @@ class TagField:
instance.host.tags.clear(category=self._category_key)
def at_added(self, component):
"""
Called when the parent component is added to a host.
Args:
component (Component): The component instance being added.
"""
if self._default:
self.__set__(component, self._default)
def at_removed(self, component):
"""
Called when the parent component is removed from a host.
Args:
component (Component): The component instance being removed.
"""
self.__delete__(component)

View file

@ -4,6 +4,11 @@ COMPONENT_LISTING = {}
def get_component_class(name):
"""
Retrieves a component from the listing using a name
Args:
name (str): The unique name of the component
"""
component_class = COMPONENT_LISTING.get(name)
if component_class is None:
message = (