fire.py 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # coding: utf-8
  2. import typing
  3. from opencc.simulation.fire import RequestFireBehaviour
  4. from synergine2_cocos2d.interaction import BaseActorInteraction
  5. from opencc.user_action import UserAction
  6. from synergine2.simulation import SimulationBehaviour
  7. from synergine2_cocos2d.actor import Actor
  8. from synergine2_cocos2d.gl import draw_line
  9. class BaseFireActorInteraction(BaseActorInteraction):
  10. gui_action = None
  11. color = None
  12. not_visible_color = (0, 0, 0)
  13. request_move_behaviour_class = RequestFireBehaviour
  14. def draw_pending(self) -> None:
  15. for actor in self.layer_manager.edit_layer.selection:
  16. actor_grid_position = self.layer_manager.grid_manager.get_grid_position(actor.position)
  17. actor_pixel_position = self.layer_manager.grid_manager.get_world_position_of_grid_position(
  18. actor_grid_position,
  19. )
  20. mouse_grid_position = self.layer_manager.grid_manager.get_grid_position(
  21. self.layer_manager.scrolling_manager.screen_to_world(
  22. *self.layer_manager.edit_layer.screen_mouse,
  23. )
  24. )
  25. draw_to_pixel = self.layer_manager.edit_layer.screen_mouse
  26. obstacle_grid_position = self.layer_manager.gui.physics.get_visibility_obstacle(
  27. subject=actor.subject,
  28. to_position=mouse_grid_position,
  29. matrix_name='visibility',
  30. opacity_property_name='opacity',
  31. )
  32. # DEBUG
  33. if self.layer_manager.debug:
  34. grid_paths = self.layer_manager.gui.physics.matrixes.get_path_positions(
  35. from_=actor_grid_position,
  36. to=mouse_grid_position,
  37. )
  38. previous_grid_path = None
  39. for grid_path in grid_paths:
  40. if previous_grid_path:
  41. previous_grid_path_pixel = self.layer_manager.grid_manager.get_world_position_of_grid_position(
  42. previous_grid_path,
  43. )
  44. current_grid_pixel = self.layer_manager.grid_manager.get_world_position_of_grid_position(
  45. grid_path,
  46. )
  47. draw_line(
  48. self.layer_manager.scrolling_manager.world_to_screen(*previous_grid_path_pixel),
  49. self.layer_manager.scrolling_manager.world_to_screen(*current_grid_pixel),
  50. (25, 125, 25),
  51. )
  52. previous_grid_path = grid_path
  53. if obstacle_grid_position:
  54. obstacle_pixel = self.layer_manager.grid_manager.get_world_position_of_grid_position(
  55. obstacle_grid_position,
  56. )
  57. draw_to_pixel = self.layer_manager.scrolling_manager.world_to_screen(*obstacle_pixel)
  58. draw_line(
  59. self.layer_manager.scrolling_manager.world_to_screen(*obstacle_pixel),
  60. self.layer_manager.edit_layer.screen_mouse,
  61. self.not_visible_color,
  62. )
  63. draw_line(
  64. self.layer_manager.scrolling_manager.world_to_screen(*actor_pixel_position),
  65. draw_to_pixel,
  66. self.color,
  67. )
  68. def get_behaviour(self, actor: Actor, mouse_grid_position) -> typing.Tuple[typing.Type[SimulationBehaviour], dict]:
  69. raise NotImplementedError()
  70. return self.request_move_behaviour_class, {
  71. 'subject_id': actor.subject.id,
  72. 'move_to': mouse_grid_position,
  73. 'gui_action': self.gui_action,
  74. }
  75. class FireActorInteraction(BaseFireActorInteraction):
  76. gui_action = UserAction.ORDER_FIRE
  77. color = (255, 0, 0)