1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- from intelligine.core.exceptions import NoMolecule
- from synergine_xyz.display.Pygame import Pygame as XyzPygame
- import pygame
- from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO, PHEROMON_POSITIONS, POINTS_SMELL, \
- POINT_SMELL, SMELL_EGG, SMELL_FOOD
- from intelligine.display.pygame.visualisation import SURFACE_PHEROMONE_EXPLORATION, SURFACE_PHEROMONE_HOME, \
- SURFACE_SMELL_EGG, SURFACE_SMELL_FOOD
-
-
- class Pygame(XyzPygame):
-
- def __init__(self, config, context, synergy_manager):
- super().__init__(config, context, synergy_manager)
- self._is_display_molecules = False
- self._is_display_smells = False
-
- def receive(self, actions_done):
- super().receive(actions_done)
-
- if self._is_display_molecules:
- molecules_positions = self._context.metas.list.get(PHEROMON_POSITIONS,
- PHEROMON_POSITIONS,
- allow_empty=True)
- self._display_molecules(molecules_positions, self._context)
-
- if self._is_display_smells:
- smell_positions = self._context.metas.list.get(POINTS_SMELL,
- POINTS_SMELL,
- allow_empty=True)
- self._display_smells(smell_positions, self._context)
-
- def _display_molecules(self, molecules_positions, context):
- molecule_exploration_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_EXPLORATION)
- molecule_home_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_HOME)
-
- for point in molecules_positions:
- point_flavour = context.molecules().get_flavour(point)
- try:
- point_flavour.get_molecule(category=PHEROMON_DIRECTION, type=PHEROMON_DIR_HOME)
- self.draw_surface(point, molecule_home_surface)
- except NoMolecule:
- pass # No molecule here
-
- try:
- point_flavour.get_molecule(category=PHEROMON_DIRECTION, type=PHEROMON_DIR_EXPLO)
- self.draw_surface(point, molecule_exploration_surface)
- except NoMolecule:
- pass # No molecule here
-
- def _display_smells(self, smell_positions, context):
- smell_egg_surface = self._object_visualizer.get_surface(SURFACE_SMELL_EGG)
- smell_food_surface = self._object_visualizer.get_surface(SURFACE_SMELL_FOOD)
-
- for point in smell_positions:
- point_flavour = context.metas.value.get(POINT_SMELL, point, allow_empty=True, empty_value={})
- if SMELL_EGG in point_flavour:
- self.draw_surface(point, smell_egg_surface)
- if SMELL_FOOD in point_flavour:
- self.draw_surface(point, smell_food_surface)
-
- def _key_pressed(self, key):
-
- if key == pygame.K_p:
- if self._is_display_molecules:
- self._is_display_molecules = False
- else:
- self._is_display_molecules = True
-
- if key == pygame.K_s:
- if self._is_display_smells:
- self._is_display_smells = False
- else:
- self._is_display_smells = True
|