simulation.py 919B

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