Define Components in esper
masterIn esper, a Component is any valid Python class. There is no specific base class required.
Common patterns for defining components include:
- Standard Classes: Best for components that require complex initialization or internal state management.
- Dataclasses: Using the
@dataclassdecorator from thedataclassesmodule is recommended for compact, data-focused definitions. - Namedtuples: Useful for immutable components where data does not need to be modified after creation.
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')