Skip to content

Commit 3182e34

Browse files
committed
Refactor WorldInfo class to include methods for retrieving entities and entity IDs
1 parent da95b86 commit 3182e34

File tree

2 files changed

+74
-36
lines changed

2 files changed

+74
-36
lines changed

adf_core_python/core/agent/info/world_info.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from typing import Any
1+
from typing import Any, Optional
22

3+
from rcrs_core.entities.entity import Entity
34
from rcrs_core.worldmodel.changeSet import ChangeSet
45
from rcrs_core.worldmodel.entityID import EntityID
56
from rcrs_core.worldmodel.worldmodel import WorldModel
@@ -35,3 +36,40 @@ def set_change_set(self, change_set: ChangeSet) -> None:
3536
Change set
3637
"""
3738
self._change_set = change_set
39+
40+
def get_entity(self, entity_id: EntityID) -> Optional[Entity]:
41+
"""
42+
Get the entity
43+
44+
Parameters
45+
----------
46+
entity_id : EntityID
47+
Entity ID
48+
49+
Returns
50+
-------
51+
Optional[Entity]
52+
Entity
53+
"""
54+
return self._world_model.get_entity(entity_id)
55+
56+
def get_entity_ids_of_type(self, entity_type: type[Entity]) -> list[EntityID]:
57+
"""
58+
Get the entity IDs of the specified type
59+
60+
Parameters
61+
----------
62+
entity_type : type[Entity]
63+
Entity type
64+
65+
Returns
66+
-------
67+
list[EntityID]
68+
Entity IDs
69+
"""
70+
entity_ids: list[EntityID] = []
71+
for entity in self._world_model.get_entities():
72+
if isinstance(entity, entity_type):
73+
entity_ids.append(entity.get_id())
74+
75+
return entity_ids

poetry.lock

Lines changed: 35 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)