NearEvent.py 897B

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