SmellAction.py 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from intelligine.cst import POINT_SMELL, POINTS_SMELL, MOLECULES_INFOS, MOLECULES_DIRECTION, SMELL_FOOD, SMELL_EGG
  2. from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
  3. from intelligine.simulation.molecule.Molecule import Molecule
  4. from intelligine.synergy.event.smell.SmellEvent import SmellEvent
  5. from synergine.synergy.event.Action import Action
  6. class SmellAction(Action):
  7. _listen = SmellEvent
  8. @classmethod
  9. def cycle_pre_run(cls, context, synergy_manager):
  10. smell_positions = context.metas.list.get(POINTS_SMELL, POINTS_SMELL, allow_empty=True)
  11. for smell_position in smell_positions:
  12. # TODO: Remonter ca dans MoleculeManager ?
  13. flavour_raw_data = context.metas.value.get(MOLECULES_INFOS, smell_position)
  14. # TODO: Calculer ou definir qqpart la liste des smells
  15. for smell_type in (SMELL_FOOD, SMELL_EGG):
  16. if smell_type in flavour_raw_data:
  17. del(flavour_raw_data[smell_type])
  18. context.metas.value.set(MOLECULES_INFOS, smell_position, flavour_raw_data)
  19. context.metas.list.unset(POINTS_SMELL, POINTS_SMELL, allow_empty=True)
  20. def run(self, obj, context, synergy_manager):
  21. # TODO: Utiliser molecule
  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. DirectionMolecule.appose(context, smell_point, molecule)
  28. #
  29. # current_point_smell = points_distances[smell_point]
  30. # where_to_put_smells = context.metas.value.get(POINT_SMELL, smell_point, allow_empty=True, empty_value={})
  31. #
  32. #
  33. # if smell_type not in where_to_put_smells:
  34. # where_to_put_smells[smell_type] = current_point_smell
  35. # else:
  36. # where_to_put_smell = where_to_put_smells[smell_type]
  37. # if current_point_smell < where_to_put_smell:
  38. # where_to_put_smells[smell_type] = where_to_put_smell
  39. #
  40. # context.metas.value.set(POINT_SMELL, smell_point, where_to_put_smells)
  41. # context.metas.list.add(POINTS_SMELL, POINTS_SMELL, smell_point, assert_not_in=False)