From 6f374aac7f4d553c484eecc77c9599be79f2d834 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Tue, 20 Aug 2024 18:17:33 -0700 Subject: send the initial state to clients --- kennel/engine/entities/entity.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'kennel/engine/entities/entity.py') diff --git a/kennel/engine/entities/entity.py b/kennel/engine/entities/entity.py index 0ca8666..b72e996 100644 --- a/kennel/engine/entities/entity.py +++ b/kennel/engine/entities/entity.py @@ -23,6 +23,13 @@ class Entity: def add_component(self, component: Component) -> None: self.components[component.component_type] = component + def to_dict(self) -> dict: + return { + "entity_type": self.entity_type, + "id": self.id, + "components": {k: v.dict() for k, v in self.components.items()}, + } + class EntityManager: def __init__(self): @@ -58,3 +65,6 @@ class EntityManager: def get_entity(self, entity_id: str) -> Optional[Entity]: return self.entities.get(entity_id) + + def to_dict(self) -> dict: + return {k: v.to_dict() for k, v in self.entities.items()} -- cgit v1.3