Add docstrings
This commit is contained in:
parent
37e70cc7fa
commit
6ad6522fa4
3 changed files with 59 additions and 7 deletions
|
|
@ -9,8 +9,17 @@ from evennia.contrib.base_systems.components import COMPONENT_LISTING, exception
|
||||||
|
|
||||||
|
|
||||||
class BaseComponent(type):
|
class BaseComponent(type):
|
||||||
|
"""
|
||||||
|
This is the metaclass for components,
|
||||||
|
responsible for registering components to the listing.
|
||||||
|
"""
|
||||||
@classmethod
|
@classmethod
|
||||||
def __new__(cls, *args):
|
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)
|
new_type = super().__new__(*args)
|
||||||
if new_type.__base__ == object:
|
if new_type.__base__ == object:
|
||||||
return new_type
|
return new_type
|
||||||
|
|
|
||||||
|
|
@ -26,17 +26,31 @@ class DBField(AttributeProperty):
|
||||||
Called when descriptor is first assigned to the class.
|
Called when descriptor is first assigned to the class.
|
||||||
|
|
||||||
Args:
|
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.
|
name (str): The name that was used to set the DBField.
|
||||||
"""
|
"""
|
||||||
self._key = f"{owner.slot or owner.name}::{name}"
|
self._key = f"{owner.slot or owner.name}::{name}"
|
||||||
owner.add_field(name, self)
|
owner.add_field(name, self)
|
||||||
|
|
||||||
def at_added(self, component):
|
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:
|
if self._autocreate:
|
||||||
self.__get__(component, type(component))
|
self.__get__(component, type(component))
|
||||||
|
|
||||||
def at_removed(self, 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)
|
self.__delete__(component)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -52,18 +66,30 @@ class NDBField(NAttributeProperty):
|
||||||
Called when descriptor is first assigned to the class.
|
Called when descriptor is first assigned to the class.
|
||||||
|
|
||||||
Args:
|
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.
|
name (str): The name that was used to set the DBField.
|
||||||
"""
|
"""
|
||||||
self._key = f"{owner.slot or owner.name}::{name}"
|
self._key = f"{owner.slot or owner.name}::{name}"
|
||||||
owner.add_field(name, self)
|
owner.add_field(name, self)
|
||||||
|
|
||||||
def at_added(self, instance):
|
def at_added(self, component):
|
||||||
if self._autocreate:
|
"""
|
||||||
self.__set__(instance, self._default)
|
Called when the parent component is added to a host.
|
||||||
|
|
||||||
def at_removed(self, instance):
|
Args:
|
||||||
self.__delete__(instance)
|
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:
|
class TagField:
|
||||||
|
|
@ -124,8 +150,20 @@ class TagField:
|
||||||
instance.host.tags.clear(category=self._category_key)
|
instance.host.tags.clear(category=self._category_key)
|
||||||
|
|
||||||
def at_added(self, component):
|
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:
|
if self._default:
|
||||||
self.__set__(component, self._default)
|
self.__set__(component, self._default)
|
||||||
|
|
||||||
def at_removed(self, 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)
|
self.__delete__(component)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,11 @@ COMPONENT_LISTING = {}
|
||||||
|
|
||||||
|
|
||||||
def get_component_class(name):
|
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)
|
component_class = COMPONENT_LISTING.get(name)
|
||||||
if component_class is None:
|
if component_class is None:
|
||||||
message = (
|
message = (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue