simulation.py 935B

123456789101112131415161718192021222324252627282930313233
  1. # coding: utf-8
  2. from sandbox.engulf.subject import Cell, Grass
  3. from synergine2.xyz import XYZSubjects, XYZSubjectMixin
  4. __author__ = 'bux'
  5. class EngulfSubjects(XYZSubjects):
  6. def __init__(self, *args, **kwargs):
  7. super().__init__(*args, **kwargs)
  8. # TODO: accept multiple subjects as same position
  9. # TODO: init xyz with given list
  10. self.cell_xyz = {}
  11. self.grass_xyz = {}
  12. def remove(self, value: XYZSubjectMixin):
  13. super().remove(value)
  14. if isinstance(value, Cell):
  15. del self.cell_xyz[value.position]
  16. if isinstance(value, Grass):
  17. del self.grass_xyz[value.position]
  18. def append(self, p_object: XYZSubjectMixin):
  19. super().append(p_object)
  20. if isinstance(p_object, Cell):
  21. self.cell_xyz[p_object.position] = p_object
  22. if isinstance(p_object, Grass):
  23. self.grass_xyz[p_object.position] = p_object