NearEvent.py 972B

123456789101112131415161718192021222324
  1. from intelligine.core.exceptions import NearNothingFound
  2. from intelligine.synergy.event.Event import Event
  3. from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
  4. class NearEvent(Event):
  5. _near_name = None
  6. _near_map = lambda self, near_object_id, context: False
  7. def __init__(self, actions):
  8. super().__init__(actions)
  9. self._mechanism = ArroundMechanism
  10. # TODO: parameters en entre/sortie c pas bon ca
  11. def map(self, context, parameters, stop_at_first=False, filter=lambda near_object_id, context: True):
  12. for near_object_id in parameters['objects_ids_near']:
  13. if self._near_map(near_object_id, context) and filter(near_object_id, context):
  14. if self._near_name not in parameters:
  15. parameters[self._near_name] = []
  16. parameters[self._near_name].append(near_object_id)
  17. if stop_at_first:
  18. return
  19. raise NearNothingFound()