simulation.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # coding: utf-8
  2. import time
  3. import typing
  4. from synergine2.config import Config
  5. from synergine2.simulation import SimulationBehaviour
  6. from synergine2.simulation import Simulation
  7. from synergine2.simulation import Event
  8. from synergine2_xyz.move.intention import MoveToIntention
  9. from synergine2_xyz.simulation import XYZSimulation
  10. class RequestMoveBehaviour(SimulationBehaviour):
  11. move_intention_class = MoveToIntention
  12. @classmethod
  13. def merge_data(cls, new_data, start_data=None):
  14. # TODO: behaviour/Thing dedicated to Gui -> Simulation ?
  15. pass # This behaviour is designed to be launch by terminal
  16. def __init__(
  17. self,
  18. config: Config,
  19. simulation: Simulation,
  20. ):
  21. super().__init__(config, simulation)
  22. self.simulation = typing.cast(XYZSimulation, self.simulation)
  23. def run(self, data):
  24. # TODO: behaviour/Thing dedicated to Gui -> Simulation ?
  25. pass # This behaviour is designed to be launch by terminal
  26. def action(self, data) -> typing.List[Event]:
  27. subject_id = data['subject_id']
  28. move_to = data['move_to']
  29. try:
  30. subject = self.simulation.subjects.index[subject_id]
  31. subject.intentions.set(self.move_intention_class(
  32. move_to,
  33. gui_action=data['gui_action'],
  34. ))
  35. except KeyError:
  36. # TODO: log error here
  37. pass
  38. return []