NearEvent.py 880B

12345678910111213141516171819202122
  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. parameters[self._near_name] = []
  11. for near_object_id in parameters['objects_ids_near']:
  12. if self._near_map(near_object_id, context) and filter(near_object_id, context):
  13. parameters[self._near_name].append(near_object_id)
  14. if stop_at_first:
  15. return
  16. if not parameters[self._near_name]:
  17. raise NearNothingFound()