visualisation.py 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from xyworld.display.object.pygame.PygameImage import PygameImage
  2. from xyworld.display.object.pygame.DirectionnedImage import DirectionnedImage
  3. from intelligine.synergy.object.Bug import Bug
  4. from intelligine.synergy.object.ant.Ant import Ant
  5. from intelligine.sandbox.colored.BlueAnt import BlueAnt
  6. from intelligine.sandbox.colored.RedAnt import RedAnt
  7. from intelligine.sandbox.colored.GreenAnt import GreenAnt
  8. from intelligine.synergy.object.Rock import Rock
  9. from intelligine.synergy.object.ant.Egg import Egg
  10. from os import getcwd
  11. from intelligine.cst import PREVIOUS_DIRECTION
  12. # TODO: Analyser les procedes ici pour proposer des outils dans le framework
  13. ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/ant.png')
  14. dead_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_ant.png')
  15. red_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/red_ant.png')
  16. green_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/green_ant.png')
  17. blue_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/blue_ant.png')
  18. dead_red_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_red_ant.png')
  19. dead_green_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_green_ant.png')
  20. dead_blue_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_blue_ant.png')
  21. bug = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/ant.png')
  22. rock = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/rock.png')
  23. egg = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg.png')
  24. directions_ant = DirectionnedImage(ant)
  25. directions_red_ant = DirectionnedImage(red_ant)
  26. directions_blue_ant = DirectionnedImage(blue_ant)
  27. directions_green_ant = DirectionnedImage(green_ant)
  28. # TODO: context donne au callbacks
  29. def bug_direction(bug, context):
  30. if bug.get_life_points() <= 0:
  31. return dead_ant
  32. try:
  33. previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  34. except KeyError:
  35. previous_direction = 14
  36. return directions_ant.get_for_direction(previous_direction)
  37. def red_ant_direction(bug, context):
  38. if bug.get_life_points() <= 0:
  39. return dead_red_ant
  40. try:
  41. previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  42. except KeyError:
  43. previous_direction = 14
  44. return directions_red_ant.get_for_direction(previous_direction)
  45. def blue_ant_direction(bug, context):
  46. if bug.get_life_points() <= 0:
  47. return dead_blue_ant
  48. try:
  49. previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  50. except KeyError:
  51. previous_direction = 14
  52. return directions_blue_ant.get_for_direction(previous_direction)
  53. def green_ant_direction(bug, context):
  54. if bug.get_life_points() <= 0:
  55. return dead_green_ant
  56. try:
  57. previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  58. except KeyError:
  59. previous_direction = 14
  60. return directions_green_ant.get_for_direction(previous_direction)
  61. visualisation = {
  62. 'window': {},
  63. 'objects': {
  64. RedAnt: {
  65. 'default': red_ant,
  66. 'callbacks': [red_ant_direction]
  67. },
  68. BlueAnt: {
  69. 'default': blue_ant,
  70. 'callbacks': [blue_ant_direction]
  71. },
  72. GreenAnt: {
  73. 'default': green_ant,
  74. 'callbacks': [green_ant_direction]
  75. },
  76. Ant: {
  77. 'default': ant,
  78. 'callbacks': [bug_direction]
  79. },
  80. Bug: {
  81. 'default': bug,
  82. 'callbacks': [bug_direction]
  83. },
  84. Egg: {
  85. 'default': egg
  86. },
  87. Rock: {
  88. 'default': rock
  89. }
  90. }
  91. }