SmellAction.py 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from intelligine.core.exceptions import BestMoleculeHere
  2. from intelligine.cst import POINT_SMELL, POINTS_SMELL, MOLECULES_INFOS, MOLECULES_DIRECTION, SMELL_FOOD, SMELL_EGG
  3. from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
  4. from intelligine.simulation.molecule.Molecule import Molecule
  5. from intelligine.synergy.event.smell.SmellEvent import SmellEvent
  6. from synergine.synergy.event.Action import Action
  7. class SmellAction(Action):
  8. _listen = SmellEvent
  9. @classmethod
  10. def cycle_pre_run(cls, context, synergy_manager):
  11. smell_positions = context.metas.list.get(POINTS_SMELL, POINTS_SMELL, allow_empty=True)
  12. for smell_position in smell_positions:
  13. # TODO: Remonter ca dans MoleculeManager ?
  14. flavour_raw_data = context.metas.value.get(MOLECULES_INFOS, smell_position)
  15. # TODO: Calculer ou definir qqpart la liste des smells
  16. for smell_type in (SMELL_FOOD, SMELL_EGG):
  17. if smell_type in flavour_raw_data:
  18. del(flavour_raw_data[smell_type])
  19. context.metas.value.set(MOLECULES_INFOS, smell_position, flavour_raw_data)
  20. context.metas.list.unset(POINTS_SMELL, POINTS_SMELL, allow_empty=True)
  21. def run(self, obj, context, synergy_manager):
  22. points_distances = self._parameters['points_distances']
  23. smell_type = obj.get_smell()
  24. for smell_point in points_distances:
  25. distance = points_distances[smell_point]
  26. molecule = Molecule(MOLECULES_DIRECTION, smell_type, distance)
  27. try:
  28. DirectionMolecule.appose(context, smell_point, molecule)
  29. except BestMoleculeHere:
  30. pass # TODO: Pas l'inverse ? A voir apres avoir fix la disparition.
  31. #
  32. # current_point_smell = points_distances[smell_point]
  33. # where_to_put_smells = context.metas.value.get(POINT_SMELL, smell_point, allow_empty=True, empty_value={})
  34. #
  35. #
  36. # if smell_type not in where_to_put_smells:
  37. # where_to_put_smells[smell_type] = current_point_smell
  38. # else:
  39. # where_to_put_smell = where_to_put_smells[smell_type]
  40. # if current_point_smell < where_to_put_smell:
  41. # where_to_put_smells[smell_type] = where_to_put_smell
  42. #
  43. # context.metas.value.set(POINT_SMELL, smell_point, where_to_put_smells)
  44. # context.metas.list.add(POINTS_SMELL, POINTS_SMELL, smell_point, assert_not_in=False)