SmellAction.py 1.5KB

123456789101112131415161718192021222324252627282930313233343536
  1. from intelligine.cst import POINT_SMELL, POINTS_SMELL
  2. from intelligine.synergy.event.smell.SmellEvent import SmellEvent
  3. from synergine.synergy.event.Action import Action
  4. class SmellAction(Action):
  5. _listen = SmellEvent
  6. @classmethod
  7. def cycle_pre_run(cls, context, synergy_manager):
  8. smell_positions = context.metas.list.get(POINTS_SMELL, POINTS_SMELL, allow_empty=True)
  9. for smell_position in smell_positions:
  10. context.metas.value.unset(POINT_SMELL, smell_position)
  11. context.metas.list.unset(POINTS_SMELL, POINTS_SMELL, allow_empty=True)
  12. def run(self, obj, context, synergy_manager):
  13. points_distances = self._parameters['points_distances']
  14. smell_type = obj.get_smell()
  15. for smell_point in points_distances:
  16. where_to_put_smells = context.metas.value.get(POINT_SMELL, smell_point, allow_empty=True, empty_value={})
  17. current_point_smell = points_distances[smell_point]
  18. if smell_type not in where_to_put_smells:
  19. where_to_put_smells[smell_type] = current_point_smell
  20. else:
  21. where_to_put_smell = where_to_put_smells[smell_type]
  22. if current_point_smell < where_to_put_smell:
  23. where_to_put_smells[smell_type] = where_to_put_smell
  24. context.metas.value.set(POINT_SMELL, smell_point, where_to_put_smells)
  25. context.metas.list.add(POINTS_SMELL, POINTS_SMELL, smell_point, assert_not_in=False)