diff options
| author | Elizabeth Hunt <elizabeth@simponic.xyz> | 2024-08-20 18:17:33 -0700 |
|---|---|---|
| committer | Elizabeth Hunt <elizabeth@simponic.xyz> | 2024-08-20 18:17:33 -0700 |
| commit | 6f374aac7f4d553c484eecc77c9599be79f2d834 (patch) | |
| tree | 70b1db95de6eab70da2f83f139a80274b01cd1fb /kennel/engine/entities | |
| parent | b4140460014d1fc134df9127600f6da2346376e3 (diff) | |
| download | kennel.hatecomputers.club-6f374aac7f4d553c484eecc77c9599be79f2d834.tar.gz kennel.hatecomputers.club-6f374aac7f4d553c484eecc77c9599be79f2d834.zip | |
send the initial state to clients
Diffstat (limited to 'kennel/engine/entities')
| -rw-r--r-- | kennel/engine/entities/entity.py | 10 |
1 files changed, 10 insertions, 0 deletions
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()} |
