(self, index, notify=True, force_respawn=False)
| 803 | self.set_sensor(self.index, notify=False, force_respawn=True) |
| 804 | |
| 805 | def set_sensor(self, index, notify=True, force_respawn=False): |
| 806 | index = index % len(self.sensors) |
| 807 | needs_respawn = True if self.index is None else \ |
| 808 | (force_respawn or (self.sensors[index][0] != self.sensors[self.index][0])) |
| 809 | if needs_respawn: |
| 810 | if self.sensor is not None: |
| 811 | self.sensor.destroy() |
| 812 | self.surface = None |
| 813 | self.sensor = self._parent.get_world().spawn_actor( |
| 814 | self.sensors[index][-1], |
| 815 | self._camera_transforms[self.transform_index][0], |
| 816 | attach_to=self._parent, |
| 817 | attachment_type=self._camera_transforms[self.transform_index][1]) |
| 818 | # We need to pass the lambda a weak reference to self to avoid |
| 819 | # circular reference. |
| 820 | weak_self = weakref.ref(self) |
| 821 | self.sensor.listen(lambda image: CameraManager._parse_image(weak_self, image)) |
| 822 | if notify: |
| 823 | self.hud.notification(self.sensors[index][2]) |
| 824 | self.index = index |
| 825 | |
| 826 | def next_sensor(self): |
| 827 | self.set_sensor(self.index + 1) |
no test coverage detected