Skip to content

Commit

Permalink
docs: add Component examples, and include attribute docstrings.
Browse files Browse the repository at this point in the history
  • Loading branch information
benmoran56 committed May 28, 2024
1 parent f7ffe9e commit 599174b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
25 changes: 22 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,34 @@ Components
----------
**esper** does not define any specific Component base class
to inherit from. Instead, a normal Python class can be used.
Also, while it's not required, the the `@dataclass` decorator
from the `dataclasses` module can be useful to help write
compact Component classes.
Also, while it's not required, the the ``@dataclass`` decorator
from the ``dataclasses`` module can be useful to help write
compact Component classes. You can even use ``namedtuple``s
for limited cases where a Component does not need to be modified.
Some examples of valid Components::
class Velocity:
def __init__(self, x=0.0, y=0.0, accel=0.1, decel=0.75, maximum=3):
self.vector = Vec2(x, y)
self.accel = accel
self.decel = decel
self.maximum = maximum
@dataclass
class Camera:
current_x_offset: float = 0
current_y_offset: float = 0
Interaction = namedtuple('Interaction', 'interaction_type target_name')
The World context
-----------------
.. autofunction:: esper.switch_world
.. autoattribute:: esper.current_world
.. autofunction:: esper.delete_world
.. autofunction:: esper.list_worlds
.. autofunction:: esper.create_entity
Expand Down
9 changes: 8 additions & 1 deletion esper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,15 @@ def process(self, *args: _Any, **kwargs: _Any) -> None:
_get_component_cache: _Dict[_Type[_Any], _List[_Any]] = {}
_get_components_cache: _Dict[_Tuple[_Type[_Any], ...], _List[_Any]] = {}
_processors: _List[Processor] = []
process_times: _Dict[str, int] = {}
event_registry: _Dict[str, _Any] = {}
process_times: _Dict[str, int] = {}
"""A dictionary containing Processor timings.
After each call to :py:func:`esper.timed_process`, the class name
and elapsed call time (in millisections) for each Processor will
be recorded in this dictionary. The times are replaced with each
call.
"""
current_world: str = "default"
"""The name of the currently active World context.
Expand Down

0 comments on commit 599174b

Please sign in to comment.